From e7d8881fb4023f1ac72f03507e6be265553101c6 Mon Sep 17 00:00:00 2001 From: Daniel Jones Date: Sun, 5 Nov 2023 11:35:08 +0000 Subject: [PATCH] Add test_examples.py --- tests/test_examples.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/test_examples.py diff --git a/tests/test_examples.py b/tests/test_examples.py new file mode 100644 index 00000000..32e5d00d --- /dev/null +++ b/tests/test_examples.py @@ -0,0 +1,28 @@ +import pytest +import subprocess +import glob +import os + +root_directory = "examples/python" + +def test_example(example_basename): + example_file = os.path.join(root_directory, example_basename) + pipe = subprocess.Popen([example_file], stdout=open("/dev/null", "w"), stderr=open("/dev/null", "w")) + try: + pipe.wait(0.5) + assert pipe.poll() == 0 + except subprocess.TimeoutExpired: + #-------------------------------------------------------------------------------- + # Process ran OK + #-------------------------------------------------------------------------------- + pipe.kill() + +def pytest_generate_tests(metafunc): + root_directory = "examples/python" + example_files = glob.glob(os.path.join(root_directory, "*.py")) + if len(example_files) == 0: + raise RuntimeError("Couldn't find any examples in directory: %s" % root_directory) + + example_basenames = [os.path.basename(file) for file in example_files] + metafunc.parametrize("example_basename", example_basenames) +