Skip to content

Commit

Permalink
Add test_examples.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ideoforms committed Nov 5, 2023
1 parent 5ce2fe3 commit e7d8881
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit e7d8881

Please sign in to comment.