tests.test_examples

Loads all scripts in the examples folder and runs them to ensure they execute without error.

 1"""
 2Loads all scripts in the examples folder and runs them to ensure they execute without error.
 3"""
 4
 5import os
 6
 7
 8def test_all_examples():
 9    # Gather all .py files in the examples folder
10    repository_path = os.path.dirname(os.path.dirname(__file__))
11    examples_folder = os.path.join(repository_path, "examples")
12    example_files = [
13        os.path.join(examples_folder, f)
14        for f in os.listdir(examples_folder)
15        if f.endswith(".py")
16    ]
17
18    # Run each example file, capturing the exit code
19    for example_file in example_files:
20        print(f"Running {example_file}...")
21        exit_code = os.system(f"python {example_file}")
22        assert exit_code == 0
def test_all_examples():
 9def test_all_examples():
10    # Gather all .py files in the examples folder
11    repository_path = os.path.dirname(os.path.dirname(__file__))
12    examples_folder = os.path.join(repository_path, "examples")
13    example_files = [
14        os.path.join(examples_folder, f)
15        for f in os.listdir(examples_folder)
16        if f.endswith(".py")
17    ]
18
19    # Run each example file, capturing the exit code
20    for example_file in example_files:
21        print(f"Running {example_file}...")
22        exit_code = os.system(f"python {example_file}")
23        assert exit_code == 0