Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/dictgen/utils.py: 10%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

21 statements  

1def max_depth(d): 

2 """ 

3 Helper function that returns the maximum depth of a dictionary. Used 

4 for testing the output of generate. 

5 

6 :param d: Dictionary to analyse 

7 """ 

8 if isinstance(d, dict): 

9 return 1 + (max(map(max_depth, d.values())) if d else 0) 

10 elif isinstance(d, list): 

11 return 1 + (max(map(max_depth, d)) if d else 0) 

12 return 0 

13 

14 

15def max_height(d): 

16 """ 

17 Helper function that returns the maximum height of a dictionary. Used 

18 for testing the output of generate. 

19 

20 :param d: Dictionary to analyse 

21 """ 

22 current_height = 0 

23 found_max = [] 

24 if isinstance(d, dict): 

25 for key in d.keys(): 

26 if isinstance(d[key], dict) or isinstance(d[key], list): 

27 found_max.append(max_height(d[key])) 

28 current_height += 1 

29 elif isinstance(d, list): 

30 for item in d: 

31 if isinstance(item, dict) or isinstance(item, list): 

32 found_max.append(max_height(item)) 

33 current_height += 1 

34 found_max.append(current_height) 

35 return max(found_max)