forked from ax3l/pydantic-mad
-
Notifications
You must be signed in to change notification settings - Fork 3
Add test to validate examples in the main PALS repository #55
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
Show all changes
24 commits
Select commit
Hold shift + click to select a range
085fc2c
Add test to validate examples in the main PALS repository
EZoni 4e722cc
Merge branch 'main' into run_examples_from_pals
EZoni 22c0f45
Use BeamLine.from_file to read from file
EZoni 82a2486
Start draft of new Lattice class
EZoni 89a5e53
Reexport, rebuild new Lattice class
EZoni d45ba9d
Replace `line` with `branches`, list of `BeamLine`s only
EZoni 3e0d72a
Simplify For Now
ax3l 11db528
Revert changes to Lattice class
EZoni 10d54f3
Merge branch 'main' into run_examples_from_pals
EZoni b39c90e
Merge branch 'main' into run_examples_from_pals
EZoni cfe45e8
Update test
EZoni 69e73ff
Workaround for 'use' syntax
EZoni 0a9732d
Split CI workflow into three separate workflows
EZoni 0e9b38d
Fix upstream examples workflow
EZoni 5960c67
Rename internal examples as local examples
EZoni d9fe6f3
CI Updates
ax3l 5707a69
Rename test_upstream_examples.py to avoid confusion with pytest
EZoni ed6f59c
Improve upstream example validation
EZoni 7d77edb
Improve comment on new 'use' syntax
EZoni 926399b
Merge branch 'main' into run_examples_from_pals
EZoni f066a5b
Do not test with Python 3.10
EZoni b1c76b7
Add instructions to validation script
EZoni 8ebee3d
Add inline comments before ad-hoc validation
EZoni 127796e
Adopt new naming convention
EZoni 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| name: pals | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - "main" | ||
| pull_request: | ||
|
|
||
| concurrency: | ||
| group: ${{ github.ref }}-${{ github.head_ref }}-standard-examples | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: | ||
| contents: read # access to check out code and install dependencies | ||
|
|
||
| jobs: | ||
ax3l marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| standard-examples: | ||
| name: standard examples | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| python-version: ["3.11", "3.12", "3.13", "3.14"] | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - name: Checkout PALS repository | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| repository: pals-project/pals | ||
| path: pals_temp | ||
| fetch-depth: 1 | ||
| sparse-checkout: | | ||
| examples/ | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v6 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
| - name: Install | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install ".[test]" | ||
| - name: Run standard examples | ||
| run: | | ||
| for file in pals_temp/examples/*.pals.yaml; do | ||
EZoni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| python tests/validate_standard_examples.py --path "${file}" | ||
| done | ||
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,35 @@ | ||
| name: pals | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - "main" | ||
| pull_request: | ||
|
|
||
| concurrency: | ||
| group: ${{ github.ref }}-${{ github.head_ref }}-unit-tests | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: | ||
| contents: read # access to check out code and install dependencies | ||
|
|
||
| jobs: | ||
ax3l marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| unit-tests: | ||
| name: unit tests | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| python-version: ["3.11", "3.12", "3.13", "3.14"] | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v6 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
| - name: Install | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install ".[test]" | ||
| - name: Run unit tests | ||
| run: | | ||
| pytest tests -v | ||
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Show fixed
Hide fixed
|
||
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,49 @@ | ||
| """Utility script to validate standard PALS example files. | ||
|
|
||
| This script is not run by pytest and is intended to be used as a standalone script. | ||
| Run it from the repository root like: | ||
|
|
||
| python tests/validate_standard_examples.py --path /path/to/example.pals.yaml | ||
|
|
||
| Before running, download the desired standard PALS example files from pals-project/pals/examples. | ||
| """ | ||
|
|
||
| import argparse | ||
ax3l marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| from pals import load | ||
| from pals.kinds import PlaceholderName | ||
| from pals.kinds.BeamLine import BeamLine | ||
| from pals.kinds.Drift import Drift | ||
| from pals.kinds.Lattice import Lattice | ||
| from pals.kinds.Quadrupole import Quadrupole | ||
|
|
||
|
|
||
| def main(): | ||
| # Parse command-line arguments | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument( | ||
| "--path", | ||
| required=True, | ||
| help="Path to the example file", | ||
| ) | ||
| args = parser.parse_args() | ||
| example_file = args.path | ||
| # Parse and validate YAML data from file | ||
| lattice = load(example_file) | ||
EZoni marked this conversation as resolved.
Show resolved
Hide resolved
ax3l marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # The following assertions are based on the standard PALS example file | ||
| # fodo.pals.yaml from pals-project/pals/examples | ||
| assert isinstance(lattice.facility[0], Drift) | ||
| assert lattice.facility[0].name == "drift1" | ||
| assert isinstance(lattice.facility[1], Quadrupole) | ||
| assert lattice.facility[1].name == "quad1" | ||
| assert isinstance(lattice.facility[2], BeamLine) | ||
| assert lattice.facility[2].name == "fodo_cell" | ||
| assert isinstance(lattice.facility[3], BeamLine) | ||
| assert lattice.facility[3].name == "fodo_channel" | ||
| assert isinstance(lattice.facility[4], Lattice) | ||
| assert lattice.facility[4].name == "fodo_lattice" | ||
| assert isinstance(lattice.facility[5], PlaceholderName) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
EZoni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.