Skip to content

Commit c78a626

Browse files
committed
Add test to validate examples in the main PALS repository
1 parent 6998a31 commit c78a626

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

.github/workflows/tests.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ jobs:
3030
- name: Test
3131
run: |
3232
pytest tests -v
33-
- name: Examples
33+
- name: Examples (internal)
3434
run: |
3535
python examples/fodo.py
36+
- name: Examples (external)
37+
run: |
38+
# Copy examples directory from the main PALS repository
39+
cd examples
40+
git clone --no-checkout https://github.com/pals-project/pals.git pals_temp
41+
cd pals_temp
42+
git sparse-checkout init
43+
git sparse-checkout set examples/
44+
git checkout main
45+
# Test all external examples
46+
cd -
47+
for file in pals_temp/examples/*.pals.yaml; do
48+
python test_external_examples.py --path "${file}"
49+
done

examples/test_external_examples.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# ruff: noqa: F841
2+
3+
import argparse
4+
import yaml
5+
6+
from pals import BeamLine
7+
8+
9+
def main():
10+
# Parse command-line arguments
11+
parser = argparse.ArgumentParser()
12+
parser.add_argument(
13+
"--path",
14+
required=True,
15+
help="Path to the example file",
16+
)
17+
args = parser.parse_args()
18+
example_file = args.path
19+
# Read YAML data from file
20+
with open(example_file, "r") as file:
21+
data = yaml.safe_load(file)
22+
# Parse and validate YAML data
23+
print(f"Parsing data from {example_file}...")
24+
beamline = BeamLine(**data)
25+
26+
27+
if __name__ == "__main__":
28+
main()

0 commit comments

Comments
 (0)