-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_config_index.py
More file actions
101 lines (79 loc) · 3.8 KB
/
Copy pathtest_config_index.py
File metadata and controls
101 lines (79 loc) · 3.8 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
#!/usr/bin/env python3
"""
Test suite for configuration index validation system
"""
import unittest
import tempfile
import pathlib
import yaml
import json
from tools.validate_config_index import main as validate_main
import sys
import os
class TestConfigurationIndexValidation(unittest.TestCase):
"""Test configuration index validation functionality"""
def setUp(self):
"""Set up test environment"""
self.original_dir = pathlib.Path.cwd()
def test_existing_configuration_validates(self):
"""Test that the existing configuration passes validation"""
# Change to repo root for test
os.chdir('/home/runner/work/AMPEL360-BWB-Q/AMPEL360-BWB-Q')
# Capture stdout/stderr
import io
from contextlib import redirect_stdout, redirect_stderr
stdout_capture = io.StringIO()
stderr_capture = io.StringIO()
try:
with redirect_stdout(stdout_capture), redirect_stderr(stderr_capture):
result = validate_main()
self.assertEqual(result, 0, f"Validation failed. stderr: {stderr_capture.getvalue()}")
output = stdout_capture.getvalue()
self.assertIn("Schema validation passed", output)
self.assertIn("All validations passed", output)
finally:
os.chdir(self.original_dir)
def test_configuration_has_required_fields(self):
"""Test that configuration contains all required fields"""
config_path = pathlib.Path('/home/runner/work/AMPEL360-BWB-Q/AMPEL360-BWB-Q/OPTIM-FRAMEWORK/O-ORGANIZATIONAL/artifacts/configuration-index.yaml')
with open(config_path, 'r') as f:
data = yaml.safe_load(f)
# Check required top-level fields
required_fields = ['meta', 'configurations', 'configuration_parameters',
'validation_gates', 'key_decisions', 'traceability', 'audit_trail']
for field in required_fields:
self.assertIn(field, data, f"Required field '{field}' missing from configuration")
def test_utcs_mi_header_format(self):
"""Test that UTCS-MI header has correct format"""
config_path = pathlib.Path('/home/runner/work/AMPEL360-BWB-Q/AMPEL360-BWB-Q/OPTIM-FRAMEWORK/O-ORGANIZATIONAL/artifacts/configuration-index.yaml')
with open(config_path, 'r') as f:
data = yaml.safe_load(f)
# Check UTCS-MI header exists and starts correctly
self.assertIn('utcs_mi_header', data)
header = data['utcs_mi_header']
self.assertTrue(header.startswith('EstándarUniversal:'),
"UTCS-MI header should start with 'EstándarUniversal:'")
# Check header has expected number of fields (14 as shown in example)
fields = header.split(':')
self.assertGreaterEqual(len(fields), 13,
f"UTCS-MI header should have at least 13 fields, found {len(fields)}")
self.assertLessEqual(len(fields), 14,
f"UTCS-MI header should have at most 14 fields, found {len(fields)}")
def run_tests():
"""Run all tests"""
print("🧪 Running Configuration Index Validation Tests")
print("=" * 60)
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestConfigurationIndexValidation))
runner = unittest.TextTestRunner(verbosity=2)
result = runner.run(suite)
print("\n" + "=" * 60)
if result.wasSuccessful():
print("✅ All configuration index tests passed!")
return True
else:
print(f"❌ {len(result.failures)} test(s) failed, {len(result.errors)} error(s)")
return False
if __name__ == "__main__":
success = run_tests()
sys.exit(0 if success else 1)