forked from pals-project/pals-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate_standard_examples.py
More file actions
49 lines (40 loc) · 1.65 KB
/
validate_standard_examples.py
File metadata and controls
49 lines (40 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
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)
# 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()