diff --git a/src/bootstraparse/modules/error_mngr.py b/src/bootstraparse/modules/error_mngr.py index 5bb9953..14e42d7 100644 --- a/src/bootstraparse/modules/error_mngr.py +++ b/src/bootstraparse/modules/error_mngr.py @@ -101,6 +101,16 @@ def dict_check(dic, *args): return output +def str_dict_check(dic, *args): + """ + Helper function to test existence within a dictionary and return a string of the values. + 'arg[0]' : True or False + + """ + out = dict_check(dic, *args) + return "\n".join([f"{args[i]}: {out[i]}" for i in range(len(out))]) + + class ParsingError(Exception): """ Exception class for parsing errors diff --git a/tests/modules/test_error_mngr.py b/tests/modules/test_error_mngr.py index 75e7403..6d0fcb6 100644 --- a/tests/modules/test_error_mngr.py +++ b/tests/modules/test_error_mngr.py @@ -96,5 +96,11 @@ def test_dict_check_2(): assert(error_mngr.dict_check({"test": "test"}, "test", "test2", "test3") == [True, False, False]) +def test_dict_str(): + assert error_mngr.str_dict_check({"test": "test"}, "test") == "test: True" + assert error_mngr.str_dict_check({"test": "test"}, "test2") == "test2: False" + assert error_mngr.str_dict_check({"test": {"test3": "test5"}}, "test", "test3") == "test: True\ntest3: True" + + if __name__ == '__main__': TestLogging().test_init_logging()