Skip to content

Commit

Permalink
Merge pull request #17 from Vivswan/main
Browse files Browse the repository at this point in the history
v1.0.4
  • Loading branch information
Vivswan authored Jul 3, 2023
2 parents bdefca3 + 7778fe4 commit 4cc2e6d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.0.4

* Added support for multi hash length

## 1.0.3

* Moved all class variables to object variables
Expand Down
7 changes: 6 additions & 1 deletion deduplicationdict/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ def __setitem__(self, key: KT, value: VT) -> None:
del self[key]

if isinstance(value, dict):
self.key_dict[key] = DeDuplicationDict(value, _value_dict=self.value_dict)
new_dd_dict = DeDuplicationDict(_value_dict=self.value_dict)
new_dd_dict.hash_length = self.hash_length
new_dd_dict.auto_clean_up = self.auto_clean_up
new_dd_dict.skip_update_on_setitem = self.skip_update_on_setitem
new_dd_dict.update(value)
self.key_dict[key] = new_dd_dict
elif isinstance(value, DeDuplicationDict):
self.key_dict[key] = value
self.value_dict.update(value.value_dict)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ where = ["deduplicationdict"]
[project]
# $ pip install deduplicationdict
name = "deduplicationdict"
version = "1.0.3"
version = "1.0.4"
description = "A dictionary that de-duplicates values."
readme = "README.md"
requires-python = ">=3.7"
Expand Down
19 changes: 19 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,25 @@ def test_deepcopy(self):
self.assertNotEqual(id(dd_dict1), id(dd_dict2))
self.assertEqual(len(diff), 0)

def test_multi_hash_length(self):
"""Test the multi_hash_length method of the DeDuplicationDict class."""

data = get_json_test_data()
dd_dict = DeDuplicationDict({'a': 1, 'b': 2, 'c': 3})

for i in dd_dict.value_dict.keys():
self.assertEqual(len(i), 8)

dd_dict.hash_length = 32
dd_dict['data'] = data
self.assertEqual(dd_dict.hash_length, 32)
self.assertEqual(dd_dict['data'].hash_length, 32)
del dd_dict['a']
del dd_dict['b']
del dd_dict['c']
for i in dd_dict.value_dict.keys():
self.assertEqual(len(i), 32)


if __name__ == '__main__':
unittest.main()

0 comments on commit 4cc2e6d

Please sign in to comment.