From a9df6283699d832c344c3b47c33f14154f9dcc1a Mon Sep 17 00:00:00 2001 From: Simon Blanke Date: Sun, 28 Apr 2024 20:21:17 +0200 Subject: [PATCH] add script to test all examples --- Makefile | 6 +++++- tests/_test_examples.py | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 tests/_test_examples.py diff --git a/Makefile b/Makefile index a767ccf..52c0269 100644 --- a/Makefile +++ b/Makefile @@ -24,13 +24,17 @@ reinstall: uninstall install reinstall-editable: uninstall install-editable +test-examples: + cd tests; \ + python _test_examples.py + tox-test: tox -- -x -p no:warnings -rfEX tests/ \ py-test: python -m pytest -x -p no:warnings tests/; \ -test: py-test tox-test +test: py-test test-examples requirement: cd requirements/; \ diff --git a/tests/_test_examples.py b/tests/_test_examples.py new file mode 100644 index 0000000..8447e98 --- /dev/null +++ b/tests/_test_examples.py @@ -0,0 +1,24 @@ +import os, sys, glob +import subprocess +from subprocess import DEVNULL, STDOUT + +here = os.path.dirname(os.path.abspath(__file__)) + +files0 = glob.glob(here+"/../examples/*/*.py") +files1 = glob.glob(here+"/../examples/*.py") + +files = files0 + files1 + +print("run files:", files) + +for file_path in files: + file_name = str(file_path.rsplit("/", maxsplit=1)[1]) + + try: + print("\033[0;33;40m Testing", file_name, end="...\r") + subprocess.check_call(["python", file_path], stdout=DEVNULL, stderr=STDOUT) + except subprocess.CalledProcessError: + print("\033[0;31;40m Error in", file_name) + else: + print("\033[0;32;40m", file_name, "is correct") +print("\n")