Skip to content

Commit 085fc2c

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

File tree

2 files changed

+41
-1
lines changed

2 files changed

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

0 commit comments

Comments
 (0)