Skip to content

Commit

Permalink
Make LocalizationContainer iterable
Browse files Browse the repository at this point in the history
  • Loading branch information
kozalosev committed May 2, 2023
1 parent d22ec4d commit 0b45f0c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions klocmod/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ def __eq__(self, other) -> bool:
raise TypeError("Incomparable types!")
return self._primary_dict == other._primary_dict and self._spare_lang_dct == other._spare_lang_dct

def __iter__(self) -> Iterable:
return iter(self._primary_dict.items())


class InvalidLocalizationFileError(Exception):
"""
Expand Down
8 changes: 8 additions & 0 deletions tests/test_klocmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,11 @@ def test_exceptions_with_other_invalid_files(filename, message):
def test_non_existing_file():
with pytest.raises(FileNotFoundError):
load_file("foo.bar")


def test_iter(localization: LocalizationsContainer):
lst = {lang: dct for lang, dct in localization}
assert 'en' in lst
assert 'ru' in lst
assert 'mood' in lst['en']
assert 'color' in lst['ru']

0 comments on commit 0b45f0c

Please sign in to comment.