forked from ax3l/pydantic-mad
-
Notifications
You must be signed in to change notification settings - Fork 3
Clean & Split Tests #36
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 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b7f518f
Clean & Split Tests
ax3l 3dda253
Clean Up Example
ax3l 9cbaa45
CI: Update
ax3l 5336228
Update README
ax3l 2a7ac79
CI w/ Test Component
ax3l 55c8af6
Drop Python 3.9, Add 3.14
ax3l 27b276b
README: Include Test Dependencies
ax3l 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
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
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 |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import json | ||
| import os | ||
| import yaml | ||
|
|
||
| from pals import BaseElement | ||
| from pals import ThickElement | ||
| from pals import BeamLine | ||
|
|
||
|
|
||
| def test_yaml(): | ||
| # Create one base element | ||
| element1 = BaseElement(name="element1") | ||
| # Create one thick element | ||
| element2 = ThickElement(name="element2", length=2.0) | ||
| # Create line with both elements | ||
| line = BeamLine(name="line", line=[element1, element2]) | ||
| # Serialize the BeamLine object to YAML | ||
| yaml_data = yaml.dump(line.model_dump(), default_flow_style=False) | ||
| print(f"\n{yaml_data}") | ||
| # Write the YAML data to a test file | ||
| test_file = "line.yaml" | ||
| with open(test_file, "w") as file: | ||
| file.write(yaml_data) | ||
| # Read the YAML data from the test file | ||
| with open(test_file, "r") as file: | ||
| yaml_data = yaml.safe_load(file) | ||
| # Parse the YAML data back into a BeamLine object | ||
| loaded_line = BeamLine(**yaml_data) | ||
| # Remove the test file | ||
| os.remove(test_file) | ||
| # Validate loaded BeamLine object | ||
| assert line == loaded_line | ||
|
|
||
|
|
||
| def test_json(): | ||
| # Create one base element | ||
| element1 = BaseElement(name="element1") | ||
| # Create one thick element | ||
| element2 = ThickElement(name="element2", length=2.0) | ||
| # Create line with both elements | ||
| line = BeamLine(name="line", line=[element1, element2]) | ||
| # Serialize the BeamLine object to JSON | ||
| json_data = json.dumps(line.model_dump(), sort_keys=True, indent=2) | ||
| print(f"\n{json_data}") | ||
| # Write the JSON data to a test file | ||
| test_file = "line.json" | ||
| with open(test_file, "w") as file: | ||
| file.write(json_data) | ||
| # Read the JSON data from the test file | ||
| with open(test_file, "r") as file: | ||
| json_data = json.loads(file.read()) | ||
| # Parse the JSON data back into a BeamLine object | ||
| loaded_line = BeamLine(**json_data) | ||
| # Remove the test file | ||
| os.remove(test_file) | ||
| # Validate loaded BeamLine object | ||
| assert line == loaded_line |
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.