from frozendict import frozendict from personal_data.data import DeduplicateMode from personal_data.main import deduplicate_dicts LIST = [ frozendict({'a': 0, 'b': 12, 't': 300}), frozendict({'a': 0, 'b': 12, 't': 301}), 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}), ] def test_no_fields_to_ignore(): for mode in DeduplicateMode: ls, fields = deduplicate_dicts(LIST, mode, []) assert fields == ['a', 'b', 't'] assert ls == LIST def test_only_latest(): ls, fields = deduplicate_dicts(LIST, DeduplicateMode.ONLY_LATEST, ['t']) assert fields == ['a', 'b', 't'] assert ls == ls[:3] def test_all_fields(): ls, fields = deduplicate_dicts(LIST, DeduplicateMode.BY_ALL_COLUMNS, ['t']) assert fields == ['a', 'b', 't'] print(ls) assert ls == [ frozendict({'a': 0, 'b': 12, 't': 300}), frozendict({'a': 1, 'b': 2, 't': 300}), ]