Coverage for tests/test_changed.py: 75%
16 statements
« prev ^ index » next coverage.py v7.8.2, created at 2025-10-17 07:56 +0200
« prev ^ index » next coverage.py v7.8.2, created at 2025-10-17 07:56 +0200
1from navdict import navdict
2from navdict.changed import ChangeTrackingDict
5def test_change_tracking():
6 ###
7 # The first test I ran was to have NavigableDict inherit from ChangeTrackingDict, but that didn't
8 # work and changes were not recorded. Second, I tried to have ChangeTrackingDict(x) and use the
9 # dot-notation to change values, but that gave me an AttributeError. So, I think I will have to
10 # merge the ChangeTrackingDict into the NavigableDict class.
11 ###
13 print()
14 print("-" * 40, " Started Change Tracking Test ", "-" * 40)
16 # x = navdict({"A": {"B": [1, 2, 3, 4], "C": int}})
17 x = ChangeTrackingDict({"A": {"B": [1, 2, 3, 4], "C": int}})
19 x.reset_tracking()
21 print(f"Initial: {x.changed}")
22 assert not x.changed
24 # x["A"]["C"] = bool
25 x.A.C = bool
26 print(f'After changing x["A"]["C"] = bool -> {x.changed}')
27 assert x.changed
29 # x["A"]["B"][1] = 0
30 x.A.B[1] = 0
31 print(f'After changing x["A"]["B"][1] = 0 -> {x.changed}')
32 assert x.changed
34 print("-" * 40, " Finished Change Tracking Test ", "-" * 40)