1
0
personal-data/test/test_deduplicate.py

37 lines
1.0 KiB
Python
Raw Normal View History

2024-05-18 19:52:22 +00:00
from frozendict import frozendict
from personal_data.data import DeduplicateMode
from personal_data.main import deduplicate_dicts
LIST = [
2024-05-21 21:37:59 +00:00
frozendict({'a': 0, 'b': 12, 't': 300}),
frozendict({'a': 0, 'b': 12, 't': 301}),
2024-05-18 19:52:22 +00:00
frozendict({'a': 1, 'b': 2, 't': 300}),
frozendict({'a': 1, 'b': 2, 't': 301}),
frozendict({'a': 1, 'b': 2, 't': 302}),
frozendict({'a': 1, 'b': 2, 't': 303}),
]
2024-05-21 21:37:59 +00:00
def test_no_fields_to_ignore():
for mode in DeduplicateMode:
ls, fields = deduplicate_dicts(LIST, mode, [])
assert fields == ['a', 'b', 't']
assert ls == LIST
2024-05-18 19:52:22 +00:00
2024-05-21 21:37:59 +00:00
def test_only_latest():
ls, fields = deduplicate_dicts(LIST, DeduplicateMode.ONLY_LATEST, ['t'])
2024-05-18 19:52:22 +00:00
assert fields == ['a', 'b', 't']
2024-05-21 21:37:59 +00:00
assert ls == ls[:3]
2024-05-18 19:52:22 +00:00
2024-05-21 21:37:59 +00:00
def test_all_fields():
ls, fields = deduplicate_dicts(LIST, DeduplicateMode.BY_ALL_COLUMNS, ['t'])
2024-05-18 19:52:22 +00:00
assert fields == ['a', 'b', 't']
2024-05-21 21:37:59 +00:00
print(ls)
assert ls == [
frozendict({'a': 0, 'b': 12, 't': 300}),
frozendict({'a': 1, 'b': 2, 't': 300}),
]