Coverage for test\test_configuration.py: 100%
54 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-28 16:41 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-28 16:41 +0000
1import pytest
2from unittest.mock import MagicMock, patch
3from xml.dom.minidom import Document
4import sys
7from pathlib import Path
8sys.path.append(str(Path(__file__).parent.parent))
9from Configuration import *
12# Test pour increment_position
13def test_increment_position_valid():
14 config = Config()
15 assert config.increment_position("(0,0)") == "(1,1)"
16 assert config.increment_position("(2,3)") == "(3,4)"
17 assert config.increment_position("(5,5)") == "(6,6)"
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)")
28def test_increment_position_negative_values():
29 config = Config()
30 with pytest.raises(AssertionError):
31 config.increment_position("(-1,0)")
32 with pytest.raises(AssertionError):
33 config.increment_position("(0,-1)")
36@pytest.fixture
37def config():
38 # Création d'une instance de la classe Config avec un document XML vide
39 config = Config()
40 doc = Document()
42 # Création d'un stat set
43 statset = doc.createElement('ss')
44 statset.setAttribute('name', 'hud_test')
47 stat = doc.createElement('stat')
48 stat.setAttribute('_rowcol', '(1,1)')
49 stat.setAttribute('_stat_name', 'vpip')
52 statset.appendChild(stat)
55 doc.appendChild(statset)
58 config.doc = doc
59 return config
61def test_edit_hud(config):
62 # Appel de la fonction edit_hud avec des valeurs de test
63 config.edit_hud(
64 hud_name='hud_test',
65 position='(0,0)',
66 stat_name='pfr',
67 click='True',
68 hudcolor='#F44336',
69 hudprefix='P',
70 hudsuffix='S',
71 popup='default',
72 stat_hicolor='#000000',
73 stat_hith='high',
74 stat_locolor='#FFFFFF',
75 stat_loth='low',
76 tip='Some tip'
77 )
79 # Récupérer le noeud modifié
80 statset_node = config.doc.getElementsByTagName("ss")[0]
81 stat_node = statset_node.getElementsByTagName("stat")[0]
83 # Vérifier que les attributs ont été correctement modifiés
84 assert stat_node.getAttribute("_stat_name") == "pfr"
85 assert stat_node.getAttribute("click") == "True"
86 assert stat_node.getAttribute("hudcolor") == "#F44336"
87 assert stat_node.getAttribute("hudprefix") == "P"
88 assert stat_node.getAttribute("hudsuffix") == "S"
89 assert stat_node.getAttribute("popup") == "default"
90 assert stat_node.getAttribute("stat_hicolor") == "#000000"
91 assert stat_node.getAttribute("stat_hith") == "high"
92 assert stat_node.getAttribute("stat_locolor") == "#FFFFFF"
93 assert stat_node.getAttribute("stat_loth") == "low"
94 assert stat_node.getAttribute("tip") == "Some tip"