Coverage for tests/test_changed.py: 75%

16 statements  

« prev     ^ index     » next       coverage.py v7.8.2, created at 2025-10-01 16:40 +0200

1from navdict import navdict 

2from navdict.changed import ChangeTrackingDict 

3 

4 

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 ### 

12 

13 print() 

14 print("-" * 40, " Started Change Tracking Test ", "-" * 40) 

15 

16 # x = navdict({"A": {"B": [1, 2, 3, 4], "C": int}}) 

17 x = ChangeTrackingDict({"A": {"B": [1, 2, 3, 4], "C": int}}) 

18 

19 

20 x.reset_tracking() 

21 

22 print(f"Initial: {x.changed}") 

23 assert not x.changed 

24 

25 # x["A"]["C"] = bool 

26 x.A.C = bool 

27 print(f'After changing x["A"]["C"] = bool -> {x.changed}') 

28 assert x.changed 

29 

30 # x["A"]["B"][1] = 0 

31 x.A.B[1] = 0 

32 print(f'After changing x["A"]["B"][1] = 0 -> {x.changed}') 

33 assert x.changed 

34 

35 print("-" * 40, " Finished Change Tracking Test ", "-" * 40)