"""Synthetic parser controls, not Windows application acceptance evidence.""" import copy import json import re from pathlib import Path import tempfile import unittest from unittest.mock import patch import xml.etree.ElementTree as ET import windows_acceptance as acceptance class WindowsAcceptanceTests(unittest.TestCase): def setUp(self): self.temp = tempfile.TemporaryDirectory() self.addCleanup(self.temp.cleanup) self.path = Path(self.temp.name) self.manifest = { "schema_version": 1, "projects": ["Example.Tests"], "groups": [{ "id": "example", "title": "Example", "required_tests": [{"project": "Example.Tests", "method": "Example.Tests.Form.Accept", "minimum_cases": 2}], "remaining_acceptance": ["Visual/operator check"], }], } self.rows = [("Example.Tests.Form.Accept", "Passed"), ("Example.Tests.Form.Accept", "Passed")] def write_trx(self, rows=None, total=None, summary="Completed"): rows = self.rows if rows is None else rows root = ET.Element("TestRun", xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010") definitions = ET.SubElement(root, "TestDefinitions") results = ET.SubElement(root, "Results") for index, (method, outcome) in enumerate(rows): test = ET.SubElement(definitions, "UnitTest", id=str(index)) class_name, name = method.rsplit(".", 1) ET.SubElement(test, "TestMethod", className=class_name, name=name) result = ET.SubElement(results, "UnitTestResult", testId=str(index), executionId=str(index), testName=f"{method}(case: {index})", outcome=outcome) if outcome != "Passed": ET.SubElement(ET.SubElement(result, "Output"), "StdOut").text = "fixture reason" result_summary = ET.SubElement(root, "ResultSummary", outcome=summary) ET.SubElement(result_summary, "Counters", total=str(len(rows) if total is None else total), executed=str(sum(r[1] != "NotExecuted" for r in rows)), passed=str(sum(r[1] == "Passed" for r in rows)), failed=str(sum(r[1] == "Failed" for r in rows)), notExecuted="0") path = self.path / "Example.Tests.trx" ET.ElementTree(root).write(path, encoding="utf-8", xml_declaration=True) return path def evaluate(self): return acceptance.evaluate(self.manifest, self.path) def test_repository_overlay_manifest_methods_exist_in_the_source(self): root = Path(__file__).resolve().parents[1] manifest = json.loads((root / "scripts/windows-acceptance.json").read_text(encoding="utf-8")) source = (root / "OpenNest.WinForms.Tests/PlateOverlapOverlayTests.cs").read_text(encoding="utf-8-sig") prefix = "OpenNest.WinForms.Tests.PlateOverlapOverlayTests." required = {test["method"] for group in manifest["groups"] for test in group["required_tests"] if test["method"].startswith(prefix)} declared = {prefix + name for name in re.findall(r"\bpublic\s+(?:async\s+)?(?:void|Task)\s+(\w+)\s*\(", source)} self.assertTrue(required, "The overlay acceptance mapping must not disappear") self.assertFalse(required - declared, f"Stale overlay test names: {sorted(required - declared)}") def test_complete_theory_passes_and_retains_manual_gate(self): self.write_trx() report = self.evaluate() self.assertEqual("passed", report["automated_status"]) self.assertEqual(2, report["groups"][0]["result_count"]) self.assertEqual(["Visual/operator check"], report["groups"][0]["remaining_acceptance"]) self.assertEqual(2, report["suites"]["Example.Tests"]["total"]) def test_missing_or_malformed_file_fails(self): self.assertEqual("failed", self.evaluate()["automated_status"]) (self.path / "Example.Tests.trx").write_text("