-
Notifications
You must be signed in to change notification settings - Fork 15
[TEST] Golden file test infrastructure for JSON Schema baselines #471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 8 additions & 26 deletions
34
packages/overture-schema-addresses-theme/tests/test_address_json_schema_baseline.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,14 @@ | ||
| """Baseline JSON Schema tests for address type.""" | ||
| """Golden JSON Schema test for Address type.""" | ||
|
|
||
| import json | ||
| import os | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| from overture.schema.addresses import Address | ||
| from overture.schema.system.json_schema import json_schema | ||
| from overture.schema.system.testing import assert_json_schema_golden | ||
|
|
||
| GOLDEN = Path(__file__).parent / "address_baseline_schema.json" | ||
|
|
||
| def test_address_json_schema_baseline() -> None: | ||
| """Test that Address generates consistent JSON Schema (baseline comparison).""" | ||
| schema = json_schema(Address) | ||
|
|
||
| # Path to baseline file | ||
| baseline_file = os.path.join( | ||
| os.path.dirname(__file__), "address_baseline_schema.json" | ||
| ) | ||
|
|
||
| # If baseline doesn't exist, create it | ||
| if not os.path.exists(baseline_file): | ||
| with open(baseline_file, "w") as f: | ||
| json.dump(schema, f, indent=2, sort_keys=True) | ||
|
|
||
| # Load baseline and compare | ||
| with open(baseline_file) as f: | ||
| baseline_schema = json.load(f) | ||
|
|
||
| # Compare the generated schema with the baseline | ||
| assert schema == baseline_schema, ( | ||
| "Generated JSON Schema differs from baseline. " | ||
| "If this change is intentional, delete the baseline file to regenerate it." | ||
| ) | ||
| @pytest.mark.baseline | ||
| def test_address_json_schema(update_baselines: bool) -> None: | ||
| assert_json_schema_golden(Address, GOLDEN, update=update_baselines) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 8 additions & 22 deletions
30
packages/overture-schema-annex/tests/test_sources_json_schema_baseline.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,14 @@ | ||
| """Baseline JSON Schema tests for sources model.""" | ||
| """Golden JSON Schema test for Sources type.""" | ||
|
|
||
| import json | ||
| import os | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| from overture.schema.annex import Sources | ||
| from overture.schema.system.json_schema import json_schema | ||
| from overture.schema.system.testing import assert_json_schema_golden | ||
|
|
||
| GOLDEN = Path(__file__).parent / "sources_baseline_schema.json" | ||
|
|
||
| def test_sources_json_schema_baseline() -> None: | ||
| """Ensure Sources model JSON Schema matches the committed baseline.""" | ||
| schema = json_schema(Sources) | ||
|
|
||
| baseline_file = os.path.join( | ||
| os.path.dirname(__file__), "sources_baseline_schema.json" | ||
| ) | ||
|
|
||
| if not os.path.exists(baseline_file): | ||
| with open(baseline_file, "w", encoding="utf-8") as f: | ||
| json.dump(schema, f, indent=2, sort_keys=True) | ||
|
|
||
| with open(baseline_file, encoding="utf-8") as f: | ||
| baseline_schema = json.load(f) | ||
|
|
||
| assert schema == baseline_schema, ( | ||
| "Generated JSON Schema differs from baseline. " | ||
| "If this change is intentional, delete the baseline file to regenerate it." | ||
| ) | ||
| @pytest.mark.baseline | ||
| def test_sources_json_schema(update_baselines: bool) -> None: | ||
| assert_json_schema_golden(Sources, GOLDEN, update=update_baselines) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 8 additions & 26 deletions
34
packages/overture-schema-base-theme/tests/test_bathymetry_json_schema_baseline.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,14 @@ | ||
| """Baseline JSON Schema tests for bathymetry type.""" | ||
| """Golden JSON Schema test for Bathymetry type.""" | ||
|
|
||
| import json | ||
| import os | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| from overture.schema.base import Bathymetry | ||
| from overture.schema.system.json_schema import json_schema | ||
| from overture.schema.system.testing import assert_json_schema_golden | ||
|
|
||
| GOLDEN = Path(__file__).parent / "bathymetry_baseline_schema.json" | ||
|
|
||
| def test_bathymetry_json_schema_baseline() -> None: | ||
| """Test that Bathymetry generates consistent JSON Schema (baseline comparison).""" | ||
| schema = json_schema(Bathymetry) | ||
|
|
||
| # Path to baseline file | ||
| baseline_file = os.path.join( | ||
| os.path.dirname(__file__), "bathymetry_baseline_schema.json" | ||
| ) | ||
|
|
||
| # If baseline doesn't exist, create it | ||
| if not os.path.exists(baseline_file): | ||
| with open(baseline_file, "w") as f: | ||
| json.dump(schema, f, indent=2, sort_keys=True) | ||
|
|
||
| # Load baseline and compare | ||
| with open(baseline_file) as f: | ||
| baseline_schema = json.load(f) | ||
|
|
||
| # Compare the generated schema with the baseline | ||
| assert schema == baseline_schema, ( | ||
| "Generated JSON Schema differs from baseline. " | ||
| "If this change is intentional, delete the baseline file to regenerate it." | ||
| ) | ||
| @pytest.mark.baseline | ||
| def test_bathymetry_json_schema(update_baselines: bool) -> None: | ||
| assert_json_schema_golden(Bathymetry, GOLDEN, update=update_baselines) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.