From 085fc2c23daec409d01a282f262411177635d977 Mon Sep 17 00:00:00 2001 From: Edoardo Zoni Date: Wed, 17 Dec 2025 09:58:00 -0800 Subject: [PATCH] Add test to validate examples in the main PALS repository --- .github/workflows/tests.yml | 16 +++++++++++++++- examples/test_external_examples.py | 26 ++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 examples/test_external_examples.py diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e4d8a66..a4887be 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -30,6 +30,20 @@ jobs: - name: Test run: | pytest tests -v - - name: Examples + - name: Examples (internal) run: | python examples/fodo.py + - name: Examples (external) + run: | + # Copy examples directory from the main PALS repository + cd examples + git clone --no-checkout https://github.com/pals-project/pals.git pals_temp + cd pals_temp + git sparse-checkout init + git sparse-checkout set examples/ + git checkout main + # Test all external examples + cd - + for file in pals_temp/examples/*.pals.yaml; do + python test_external_examples.py --path "${file}" + done \ No newline at end of file diff --git a/examples/test_external_examples.py b/examples/test_external_examples.py new file mode 100644 index 0000000..d61bd03 --- /dev/null +++ b/examples/test_external_examples.py @@ -0,0 +1,26 @@ +import argparse +import yaml + +from pals import BeamLine + + +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 + # Read YAML data from file + with open(example_file, "r") as file: + data = yaml.safe_load(file) + # Parse and validate YAML data + print(f"Parsing data from {example_file}...") + BeamLine(**data) + + +if __name__ == "__main__": + main()