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
Open
EZoni
wants to merge
19
commits into
pals-project:main
Choose a base branch
from
EZoni:run_examples_from_pals
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 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 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| name: tests | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - "main" | ||
| pull_request: | ||
|
|
||
| concurrency: | ||
| group: ${{ github.ref }}-${{ github.head_ref }}-local-examples | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: | ||
| contents: read # access to check out code and install dependencies | ||
|
|
||
| jobs: | ||
| local-examples: | ||
| name: local examples | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| python-version: ["3.10", "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 local examples | ||
| run: | | ||
| python examples/fodo.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
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: tests | ||
EZoni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - "main" | ||
| pull_request: | ||
|
|
||
| concurrency: | ||
| group: ${{ github.ref }}-${{ github.head_ref }}-upstream-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
|
||
| upstream-examples: | ||
| name: upstream examples | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"] | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - name: Checkout upstream PALS repo | ||
| 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 upstream examples | ||
| run: | | ||
| for file in pals_temp/examples/*.pals.yaml; do | ||
EZoni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| python tests/validate_upstream_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
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,37 @@ | ||
| import argparse | ||
|
|
||
| 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
|
||
| 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.