Skip to content

Commit

Permalink
Fix syntax for older Python versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunedan committed Jun 5, 2024
1 parent dbd6509 commit de1fc48
Showing 1 changed file with 52 additions and 68 deletions.
120 changes: 52 additions & 68 deletions tests/strategies/dictionaries/test_trie_dictionary_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,19 @@ def test_no_disk_cache() -> None:
use_disk_cache=False, disk_cache_dir=tmp_dir
)

with (
patch.object(
TrieDictionaryFactory,
"_cache_is_current",
wraps=dictionaries._cache_is_current,
) as cache_is_current_mock,
patch.object(
TrieDictionaryFactory,
"_create_trie_from_pickled_dict",
wraps=dictionaries._create_trie_from_pickled_dict,
) as create_trie_mock,
patch.object(
TrieDictionaryFactory,
"_write_trie_to_disk",
wraps=dictionaries._write_trie_to_disk,
) as write_trie_mock,
):
with patch.object(
TrieDictionaryFactory,
"_cache_is_current",
wraps=dictionaries._cache_is_current,
) as cache_is_current_mock, patch.object(
TrieDictionaryFactory,
"_create_trie_from_pickled_dict",
wraps=dictionaries._create_trie_from_pickled_dict,
) as create_trie_mock, patch.object(
TrieDictionaryFactory,
"_write_trie_to_disk",
wraps=dictionaries._write_trie_to_disk,
) as write_trie_mock:
assert sorted(tmp_dir_path.iterdir()) == []

dictionaries.get_dictionary("en")
Expand All @@ -92,23 +88,19 @@ def test_disk_cache() -> None:
tmp_dir_path = Path(tmp_dir)
dictionaries = TrieDictionaryFactory(disk_cache_dir=tmp_dir)

with (
patch.object(
TrieDictionaryFactory,
"_cache_is_current",
wraps=dictionaries._cache_is_current,
) as cache_is_current_mock,
patch.object(
TrieDictionaryFactory,
"_create_trie_from_pickled_dict",
wraps=dictionaries._create_trie_from_pickled_dict,
) as create_trie_mock,
patch.object(
TrieDictionaryFactory,
"_write_trie_to_disk",
wraps=dictionaries._write_trie_to_disk,
) as write_trie_mock,
):
with patch.object(
TrieDictionaryFactory,
"_cache_is_current",
wraps=dictionaries._cache_is_current,
) as cache_is_current_mock, patch.object(
TrieDictionaryFactory,
"_create_trie_from_pickled_dict",
wraps=dictionaries._create_trie_from_pickled_dict,
) as create_trie_mock, patch.object(
TrieDictionaryFactory,
"_write_trie_to_disk",
wraps=dictionaries._write_trie_to_disk,
) as write_trie_mock:
assert sorted(tmp_dir_path.iterdir()) == []

# Initial cached trie files should be generated.
Expand Down Expand Up @@ -166,23 +158,19 @@ def test_corrupted_disk_cache() -> None:
tmp_dir_path = Path(tmp_dir)
dictionaries = TrieDictionaryFactory(disk_cache_dir=tmp_dir)

with (
patch.object(
TrieDictionaryFactory,
"_cache_is_current",
wraps=dictionaries._cache_is_current,
) as cache_is_current_mock,
patch.object(
TrieDictionaryFactory,
"_create_trie_from_pickled_dict",
wraps=dictionaries._create_trie_from_pickled_dict,
) as create_trie_mock,
patch.object(
TrieDictionaryFactory,
"_write_trie_to_disk",
wraps=dictionaries._write_trie_to_disk,
) as write_trie_mock,
):
with patch.object(
TrieDictionaryFactory,
"_cache_is_current",
wraps=dictionaries._cache_is_current,
) as cache_is_current_mock, patch.object(
TrieDictionaryFactory,
"_create_trie_from_pickled_dict",
wraps=dictionaries._create_trie_from_pickled_dict,
) as create_trie_mock, patch.object(
TrieDictionaryFactory,
"_write_trie_to_disk",
wraps=dictionaries._write_trie_to_disk,
) as write_trie_mock:
assert sorted(tmp_dir_path.iterdir()) == []

# Initial cached trie file should be generated.
Expand Down Expand Up @@ -230,23 +218,19 @@ def test_disk_cache_regeneration() -> None:
tmp_dir_path = Path(tmp_dir)
dictionaries = TrieDictionaryFactory(disk_cache_dir=tmp_dir)

with (
patch.object(
TrieDictionaryFactory,
"_cache_is_current",
wraps=dictionaries._cache_is_current,
) as cache_is_current_mock,
patch.object(
TrieDictionaryFactory,
"_create_trie_from_pickled_dict",
wraps=dictionaries._create_trie_from_pickled_dict,
) as create_trie_mock,
patch.object(
TrieDictionaryFactory,
"_write_trie_to_disk",
wraps=dictionaries._write_trie_to_disk,
) as write_trie_mock,
):
with patch.object(
TrieDictionaryFactory,
"_cache_is_current",
wraps=dictionaries._cache_is_current,
) as cache_is_current_mock, patch.object(
TrieDictionaryFactory,
"_create_trie_from_pickled_dict",
wraps=dictionaries._create_trie_from_pickled_dict,
) as create_trie_mock, patch.object(
TrieDictionaryFactory,
"_write_trie_to_disk",
wraps=dictionaries._write_trie_to_disk,
) as write_trie_mock:
assert sorted(tmp_dir_path.iterdir()) == []

# Initial cached trie file should be generated.
Expand Down

0 comments on commit de1fc48

Please sign in to comment.