Skip to content

Commit acda0b1

Browse files
committed
Add pytest test suite for airc validator
1 parent a667559 commit acda0b1

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

tests/test_validator.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
"""Tests for airc validator module."""
2+
import pytest
3+
import yaml
4+
from pathlib import Path
5+
from airc.validator import validate_checklist, ChecklistValidationError
6+
7+
8+
MINIMAL_CONFIG = {
9+
"metadata": {
10+
"project": "test-project",
11+
"version": "1.0.0",
12+
"environment": "staging",
13+
"regulated_industry": "general",
14+
"risk_classification": "low",
15+
},
16+
"model_validation": {
17+
"performance": {"accuracy_threshold": 0.90, "bias_evaluation_complete": True}
18+
},
19+
"governance": {
20+
"approvals": {"technical_review": True}
21+
},
22+
"infrastructure": {
23+
"testing": {"unit_tests_passing": True}
24+
},
25+
}
26+
27+
28+
@pytest.fixture
29+
def config_file(tmp_path):
30+
def _write(config_dict):
31+
p = tmp_path / "checklist.yaml"
32+
p.write_text(yaml.dump(config_dict))
33+
return p
34+
return _write
35+
36+
37+
def test_minimal_low_risk_config_passes(config_file):
38+
path = config_file(MINIMAL_CONFIG)
39+
result = validate_checklist(path)
40+
assert result.passed
41+
42+
43+
def test_missing_required_section_raises(config_file):
44+
bad = {k: v for k, v in MINIMAL_CONFIG.items() if k != "governance"}
45+
path = config_file(bad)
46+
with pytest.raises(ChecklistValidationError):
47+
validate_checklist(path)
48+
49+
50+
def test_failed_required_gate_fails(config_file):
51+
config = {**MINIMAL_CONFIG, "metadata": {**MINIMAL_CONFIG["metadata"], "risk_classification": "medium"}}
52+
config["governance"]["documentation"] = {"risk_assessment_complete": False}
53+
path = config_file(config)
54+
result = validate_checklist(path)
55+
assert not result.passed
56+
assert result.failed_count > 0
57+
58+
59+
def test_result_metadata_populated(config_file):
60+
path = config_file(MINIMAL_CONFIG)
61+
result = validate_checklist(path)
62+
assert result.project == "test-project"
63+
assert result.version == "1.0.0"
64+
assert result.environment == "staging"
65+
assert result.risk_classification == "low"
66+
assert result.regulated_industry == "general"
67+
68+
69+
def test_invalid_yaml_raises(tmp_path):
70+
p = tmp_path / "bad.yaml"
71+
p.write_text("{invalid: yaml: content: [}")
72+
with pytest.raises(ChecklistValidationError):
73+
validate_checklist(p)
74+
75+
76+
def test_industry_override(config_file):
77+
config = {**MINIMAL_CONFIG}
78+
path = config_file(config)
79+
result = validate_checklist(path, industry_override="healthcare")
80+
assert result.regulated_industry == "healthcare"

0 commit comments

Comments
 (0)