Skip to content

Commit

Permalink
feat: add automated expected structure-and-text postprocessing
Browse files Browse the repository at this point in the history
  • Loading branch information
Elijas committed Dec 19, 2023
1 parent ea491ec commit 7853d24
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/accuracy/structure_and_text/test_structure_and_text.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import importlib.util
import json
import warnings
from collections import Counter
Expand Down Expand Up @@ -47,6 +48,21 @@ def test_structure_and_text(
if request.config.getoption("--create-missing-files"):
with report.expected_structure_and_text.open("w") as f:
json.dump(actual_json, f, sort_keys=True, indent=4, ensure_ascii=False)
if report.expected_structure_and_text_postprocessor.exists():
path = report.expected_structure_and_text_postprocessor
if path.exists():
spec = importlib.util.spec_from_file_location("postprocessor", path)
assert spec is not None, f"Could not load {path} (spec is None))"
assert (
spec.loader is not None
), f"Could not load {path} (spec.loader is None))"
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
if hasattr(module, "main"):
module.main()
else:
msg = f"The module {module.__name__} does not have a main function."
raise AttributeError(msg)
warnings.warn(
f"Created {report.expected_structure_and_text.name}. Please manually review it and commit the file.",
stacklevel=0,
Expand Down
4 changes: 4 additions & 0 deletions tests/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def expected_structure_and_text(self) -> Path:
def actual_structure_and_text(self) -> Path:
return self.path / "actual-structure-and-text.json"

@property
def expected_structure_and_text_postprocessor(self) -> Path:
return self.path / "postprocess_expected_structure_and_text.py"

@property
def actual_structure_and_text_summary(self) -> Path:
return self.path / "actual-structure-and-text_summary.json"
Expand Down

0 comments on commit 7853d24

Please sign in to comment.