Coverage for test\test_configuration.py: 100%

53 statements  

« prev     ^ index     » next       coverage.py v7.6.3, created at 2024-10-14 11:07 +0000

1import pytest 

2from xml.dom.minidom import Document 

3import sys 

4from pathlib import Path 

5 

6 

7sys.path.append(str(Path(__file__).parent.parent)) 

8from Configuration import Config 

9 

10 

11# Test for increment_position 

12def test_increment_position_valid(): 

13 config = Config() 

14 assert config.increment_position("(0,0)") == "(1,1)" 

15 assert config.increment_position("(2,3)") == "(3,4)" 

16 assert config.increment_position("(5,5)") == "(6,6)" 

17 

18 

19def test_increment_position_invalid_format(): 

20 config = Config() 

21 with pytest.raises(AssertionError): 

22 config.increment_position("0,0") 

23 with pytest.raises(AssertionError): 

24 config.increment_position("(0,0") 

25 with pytest.raises(AssertionError): 

26 config.increment_position("0,0)") 

27 

28 

29def test_increment_position_negative_values(): 

30 config = Config() 

31 with pytest.raises(AssertionError): 

32 config.increment_position("(-1,0)") 

33 with pytest.raises(AssertionError): 

34 config.increment_position("(0,-1)") 

35 

36 

37@pytest.fixture 

38def config(): 

39 # Create instance 

40 config = Config() 

41 doc = Document() 

42 

43 # Crate stat set 

44 statset = doc.createElement("ss") 

45 statset.setAttribute("name", "hud_test") 

46 

47 stat = doc.createElement("stat") 

48 stat.setAttribute("_rowcol", "(1,1)") 

49 stat.setAttribute("_stat_name", "vpip") 

50 

51 statset.appendChild(stat) 

52 

53 doc.appendChild(statset) 

54 

55 config.doc = doc 

56 return config 

57 

58 

59def test_edit_hud(config): 

60 # call function edit_hud with test data 

61 config.edit_hud( 

62 hud_name="hud_test", 

63 position="(0,0)", 

64 stat_name="pfr", 

65 click="True", 

66 hudcolor="#F44336", 

67 hudprefix="P", 

68 hudsuffix="S", 

69 popup="default", 

70 stat_hicolor="#000000", 

71 stat_hith="high", 

72 stat_locolor="#FFFFFF", 

73 stat_loth="low", 

74 tip="Some tip", 

75 ) 

76 

77 # Get modified node 

78 statset_node = config.doc.getElementsByTagName("ss")[0] 

79 stat_node = statset_node.getElementsByTagName("stat")[0] 

80 

81 # checks 

82 assert stat_node.getAttribute("_stat_name") == "pfr" 

83 assert stat_node.getAttribute("click") == "True" 

84 assert stat_node.getAttribute("hudcolor") == "#F44336" 

85 assert stat_node.getAttribute("hudprefix") == "P" 

86 assert stat_node.getAttribute("hudsuffix") == "S" 

87 assert stat_node.getAttribute("popup") == "default" 

88 assert stat_node.getAttribute("stat_hicolor") == "#000000" 

89 assert stat_node.getAttribute("stat_hith") == "high" 

90 assert stat_node.getAttribute("stat_locolor") == "#FFFFFF" 

91 assert stat_node.getAttribute("stat_loth") == "low" 

92 assert stat_node.getAttribute("tip") == "Some tip"