|
| 1 | +"""Utility script to validate standard PALS example files. |
| 2 | +
|
| 3 | +This script is not run by pytest and is intended to be used as a standalone script. |
| 4 | +Run it from the repository root like: |
| 5 | +
|
| 6 | + python tests/validate_standard_examples.py --path /path/to/example.pals.yaml |
| 7 | +
|
| 8 | +Before running, download the desired standard PALS example files from pals-project/pals/examples. |
| 9 | +""" |
| 10 | + |
| 11 | +import argparse |
| 12 | + |
| 13 | +from pals import load |
| 14 | +from pals.kinds import PlaceholderName |
| 15 | +from pals.kinds.BeamLine import BeamLine |
| 16 | +from pals.kinds.Drift import Drift |
| 17 | +from pals.kinds.Lattice import Lattice |
| 18 | +from pals.kinds.Quadrupole import Quadrupole |
| 19 | + |
| 20 | + |
| 21 | +def main(): |
| 22 | + # Parse command-line arguments |
| 23 | + parser = argparse.ArgumentParser() |
| 24 | + parser.add_argument( |
| 25 | + "--path", |
| 26 | + required=True, |
| 27 | + help="Path to the example file", |
| 28 | + ) |
| 29 | + args = parser.parse_args() |
| 30 | + example_file = args.path |
| 31 | + # Parse and validate YAML data from file |
| 32 | + lattice = load(example_file) |
| 33 | + # The following assertions are based on the standard PALS example file |
| 34 | + # fodo.pals.yaml from pals-project/pals/examples |
| 35 | + assert isinstance(lattice.facility[0], Drift) |
| 36 | + assert lattice.facility[0].name == "drift1" |
| 37 | + assert isinstance(lattice.facility[1], Quadrupole) |
| 38 | + assert lattice.facility[1].name == "quad1" |
| 39 | + assert isinstance(lattice.facility[2], BeamLine) |
| 40 | + assert lattice.facility[2].name == "fodo_cell" |
| 41 | + assert isinstance(lattice.facility[3], BeamLine) |
| 42 | + assert lattice.facility[3].name == "fodo_channel" |
| 43 | + assert isinstance(lattice.facility[4], Lattice) |
| 44 | + assert lattice.facility[4].name == "fodo_lattice" |
| 45 | + assert isinstance(lattice.facility[5], PlaceholderName) |
| 46 | + |
| 47 | + |
| 48 | +if __name__ == "__main__": |
| 49 | + main() |
0 commit comments