diff --git a/requirements.txt b/requirements.txt index 68dfdbd..e6e5256 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ pytest==6.2.2 pyyaml==5.4.1 -pywinauto==0.6.8 \ No newline at end of file +pywinauto==0.6.8 +dict-deep==4.1.2 \ No newline at end of file diff --git a/src/config.py b/src/config.py index 0214789..7b47664 100644 --- a/src/config.py +++ b/src/config.py @@ -1,4 +1,5 @@ import yaml +from dict_deep import deep_get conf = None @@ -8,3 +9,7 @@ def read_config(filename): global conf conf = yaml.safe_load(f) return conf + + +def get_value(key: str): + return deep_get(conf, key) diff --git a/tests/test_log.py b/tests/test_log.py index d21246e..902879c 100644 --- a/tests/test_log.py +++ b/tests/test_log.py @@ -2,8 +2,9 @@ from src import config def test_write_to_log(): - conf = config.read_config(r'config.yaml') - log_file = conf['General']['log_file'] + config.read_config(r'config.yaml') + log_file = config.get_value('General.log_file') + assert(log_file) text = '2021/03/08 23:24:52 17931875 bb3 [INFO Client 1492] @From Sinusal: Hi, I would like to buy your level 21 23% Vaal Impurity of Lightning ' \ 'listed for 18 chaos in Ritual (stash tab "$"; position: left 22, top 5)' with open(log_file, 'a') as f: