tests: add test suite for jay_diff; fix two bugs found
Move the inline assertions from jay_diff.py into tests/test_jay_diff.py as proper pytest functions, grouped by function under test. Add corner cases for numeric/bool/None/list values, completely different structures, empty containers, deep nesting, type changes (dict↔scalar), and parametrised round-trip tests (diff→merge produces new). Two bugs fixed during the exercise: - jay_diff_rev: guard against _old being a non-dict (type change from dict to scalar caused TypeError on item assignment) - jay_merge_delete / jay_merge_update: already fixed in previous commit; covered by new tests Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+4
-2
@@ -3,6 +3,8 @@ from copy import deepcopy
|
||||
|
||||
def jay_diff_rev(_old, _new):
|
||||
delta = {}
|
||||
if not isinstance(_old, dict):
|
||||
return delta
|
||||
for k in _new.keys():
|
||||
if k in _old:
|
||||
if isinstance(_new[k], dict):
|
||||
@@ -131,7 +133,7 @@ def jay_merge_full(_old, _diff):
|
||||
|
||||
return res
|
||||
|
||||
def main() -> None:
|
||||
def _legacy_assertions() -> None:
|
||||
result = jay_diff_add({}, {'a': 'hamburger', 'b': 'fries', 'c': {'e': 'coke', 'f': 'coffee'}})
|
||||
assert result == {'a':'hamburger', 'b':'fries', 'c': {'e': 'coke', 'f': 'coffee'}}
|
||||
|
||||
@@ -579,4 +581,4 @@ def main() -> None:
|
||||
assert result == old
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
_legacy_assertions()
|
||||
|
||||
Reference in New Issue
Block a user