Coverage for tests/objects/test_classification.py: 100%

35 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2025-01-31 11:24 +0000

1from qubalab.objects.classification import Classification 

2 

3 

4def test_name(): 

5 expected_name = "name" 

6 classification = Classification(expected_name) 

7 

8 name = classification.name 

9 

10 assert expected_name == name 

11 

12 

13def test_color(): 

14 expected_color = (2, 20, 56) 

15 classification = Classification(None, expected_color) 

16 

17 color = classification.color 

18 

19 assert expected_color == color 

20 

21 

22def test_cache_when_None_name_provided(): 

23 classification = Classification.get_cached_classification(None) 

24 

25 assert classification == None 

26 

27 

28def test_cache_when_empty(): 

29 name = "name" 

30 color = (2, 20, 56) 

31 

32 classification = Classification.get_cached_classification(name, color) 

33 

34 assert classification == Classification(name, color) 

35 

36 

37def test_cache_when_not_empty_and_same_name(): 

38 cached_name = "name" 

39 cached_color = (2, 20, 56) 

40 other_name = cached_name 

41 other_color = (4, 65, 7) 

42 cached_classification = Classification.get_cached_classification(cached_name, cached_color) 

43 

44 classification = Classification.get_cached_classification(other_name, other_color) 

45 

46 assert classification != Classification(other_name, other_color) and classification == cached_classification 

47 

48 

49def test_cache_when_not_empty_and_different_name(): 

50 cached_name = "name" 

51 cached_color = (2, 20, 56) 

52 other_name = "other name" 

53 other_color = (4, 65, 7) 

54 cached_classification = Classification.get_cached_classification(cached_name, cached_color) 

55 

56 classification = Classification.get_cached_classification(other_name, other_color) 

57 

58 assert classification == Classification(other_name, other_color) and classification != cached_classification