diff --git a/src/Zoomba/APILibrary.py b/src/Zoomba/APILibrary.py index c245a474..2e6e44f2 100644 --- a/src/Zoomba/APILibrary.py +++ b/src/Zoomba/APILibrary.py @@ -361,7 +361,10 @@ def _key_by_key_list(self, key, value, actual_dictionary, unmatched_keys_list=No "\nActual: " + str(actual_dictionary[key])) continue else: - actual_item = actual_dictionary[key][index] + if len(actual_dictionary[key]) == 0: + actual_item = '' + else: + actual_item = actual_dictionary[key][index] temp_actual_dict = {key: actual_item} temp_expected_dict = {key: item} if unmatched_keys_list: diff --git a/test/API/test_validate.py b/test/API/test_validate.py index 1f70970f..d4bbb959 100644 --- a/test/API/test_validate.py +++ b/test/API/test_validate.py @@ -106,6 +106,12 @@ def test_key_by_key_validator_list_int(self): library = APILibrary() library.key_by_key_validator({"a": [1]}, {"a": [1]}) + def test_key_by_key_validator_list_empty_fail(self): + library = APILibrary() + unmatched = [] + library.key_by_key_validator({"a": []}, {"a": [1]}, unmatched_keys_list=unmatched) + assert unmatched == [('------------------\nKey: a[0]', 'Expected: 1', 'Actual: ')] + def test_key_by_key_validator_simple_ignored_key(self): library = APILibrary() library.key_by_key_validator({"a": ["1"]}, {"a": ["1"]}, ["a"])