|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# |
| 3 | +# Copyright 2026 The Ethos maintainers |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | + |
| 18 | +from __future__ import annotations |
| 19 | + |
| 20 | +import importlib.util |
| 21 | +import unittest |
| 22 | +from pathlib import Path |
| 23 | + |
| 24 | + |
| 25 | +ROOT = Path(__file__).resolve().parent |
| 26 | +SCRIPT = ROOT / "check_golden_change_rationale.py" |
| 27 | + |
| 28 | + |
| 29 | +def load_module(): |
| 30 | + spec = importlib.util.spec_from_file_location( |
| 31 | + "check_golden_change_rationale_under_test", |
| 32 | + SCRIPT, |
| 33 | + ) |
| 34 | + if spec is None or spec.loader is None: |
| 35 | + raise RuntimeError(f"could not load {SCRIPT}") |
| 36 | + module = importlib.util.module_from_spec(spec) |
| 37 | + spec.loader.exec_module(module) |
| 38 | + return module |
| 39 | + |
| 40 | + |
| 41 | +CHECK = load_module() |
| 42 | + |
| 43 | + |
| 44 | +class GoldenChangeRationaleTests(unittest.TestCase): |
| 45 | + def test_fixture_stage_goldens_are_golden_like(self) -> None: |
| 46 | + for name in [ |
| 47 | + "extraction.json", |
| 48 | + "layout.json", |
| 49 | + "markdown.md", |
| 50 | + "tables.json", |
| 51 | + "text.txt", |
| 52 | + ]: |
| 53 | + with self.subTest(name=name): |
| 54 | + self.assertTrue( |
| 55 | + CHECK.is_golden_like(f"fixtures/synthetic/simple-text/{name}") |
| 56 | + ) |
| 57 | + |
| 58 | + def test_fixture_metadata_is_not_golden_like(self) -> None: |
| 59 | + self.assertFalse( |
| 60 | + CHECK.is_golden_like("fixtures/synthetic/simple-text/fixture.json") |
| 61 | + ) |
| 62 | + self.assertFalse(CHECK.is_golden_like("fixtures/manifest.json")) |
| 63 | + |
| 64 | + def test_existing_golden_patterns_still_match(self) -> None: |
| 65 | + self.assertTrue( |
| 66 | + CHECK.is_golden_like("examples/verify/goldens/native_grounded_report.json") |
| 67 | + ) |
| 68 | + self.assertTrue( |
| 69 | + CHECK.is_golden_like( |
| 70 | + "fixtures/foreign/opendataloader/real/expected.verification_report.json" |
| 71 | + ) |
| 72 | + ) |
| 73 | + |
| 74 | + |
| 75 | +if __name__ == "__main__": |
| 76 | + unittest.main() |
0 commit comments