-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_structure.py
More file actions
executable file
·151 lines (127 loc) · 4.27 KB
/
test_structure.py
File metadata and controls
executable file
·151 lines (127 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env python3
"""Script de test pour valider la structure de l'application."""
import sys
import importlib.util
def test_imports():
"""Teste que tous les modules peuvent être importés."""
print("Test des imports...")
try:
from config import Config
print(" ✓ config.py")
from netatmo_client import NetatmoClient
print(" ✓ netatmo_client.py")
from netatmo_cli import cmd_status, cmd_set, cmd_frost_guard, cmd_history, cmd_stats
print(" ✓ netatmo_cli.py (commandes)")
return True
except Exception as e:
print(f" ✗ Erreur: {e}")
return False
def test_config():
"""Teste la classe Config."""
print("\nTest de la configuration...")
try:
from config import Config
config = Config()
# Vérifier que la validation fonctionne
try:
config.validate()
print(" ✓ Validation de la configuration OK")
except ValueError as e:
print(f" ⚠ Configuration incomplète (normal si .env n'est pas configuré): {e}")
return True
except Exception as e:
print(f" ✗ Erreur: {e}")
return False
def test_client_structure():
"""Teste la structure du client."""
print("\nTest de la structure du client...")
try:
from netatmo_client import NetatmoClient
from config import Config
# Vérifier que toutes les méthodes publiques existent
required_methods = [
'get_home_status',
'get_thermostat_status',
'set_temperature',
'set_frost_guard',
'get_thermostat_history',
'get_statistics'
]
for method in required_methods:
if hasattr(NetatmoClient, method):
print(f" ✓ Méthode {method} présente")
else:
print(f" ✗ Méthode {method} manquante")
return False
return True
except Exception as e:
print(f" ✗ Erreur: {e}")
return False
def test_cli_commands():
"""Teste que toutes les commandes CLI sont définies."""
print("\nTest des commandes CLI...")
try:
from netatmo_cli import (
cmd_status, cmd_set, cmd_frost_guard,
cmd_history, cmd_stats, format_output
)
commands = [
('cmd_status', cmd_status),
('cmd_set', cmd_set),
('cmd_frost_guard', cmd_frost_guard),
('cmd_history', cmd_history),
('cmd_stats', cmd_stats),
]
for name, func in commands:
if callable(func):
print(f" ✓ {name} est callable")
else:
print(f" ✗ {name} n'est pas callable")
return False
# Tester format_output
test_data = {'test': 'value', 'number': 42}
text_output = format_output(test_data, False)
json_output = format_output(test_data, True)
if text_output and json_output:
print(f" ✓ format_output fonctionne")
else:
print(f" ✗ format_output ne fonctionne pas")
return False
return True
except Exception as e:
print(f" ✗ Erreur: {e}")
import traceback
traceback.print_exc()
return False
def main():
"""Exécute tous les tests."""
print("=" * 50)
print("Tests de structure de l'application Netatmo CLI")
print("=" * 50)
tests = [
test_imports,
test_config,
test_client_structure,
test_cli_commands,
]
results = []
for test in tests:
try:
result = test()
results.append(result)
except Exception as e:
print(f"\n✗ Erreur lors du test {test.__name__}: {e}")
results.append(False)
print("\n" + "=" * 50)
print("Résumé:")
passed = sum(results)
total = len(results)
print(f"Tests réussis: {passed}/{total}")
if all(results):
print("✓ Tous les tests sont passés!")
return 0
else:
print("✗ Certains tests ont échoué")
return 1
if __name__ == '__main__':
sys.exit(main())