Debian Codegraph @

examples_trame/tests/test_trame.py

raw
1 from __future__ import annotations
2
3 import os
4 from pathlib import Path
5 import subprocess
6
7 import pytest
8
9 THIS_PATH = Path(__file__).parent.absolute()
10 EXAMPLES_DIR = Path(__file__).parent.parent.absolute()
11
12
13 def collect_example_files():
14 test_files = []
15 for dirpath, _, filenames in os.walk(EXAMPLES_DIR):
16 if THIS_PATH.match(dirpath) or dirpath.endswith('__pycache__'):
17 continue
18 for filename in filenames:
19 full_path = Path(dirpath) / filename
20 if not filename.endswith('.py'):
21 continue
22 # Use relative path and cast to str for better repr in pytest output
23 rel_path = full_path.relative_to(EXAMPLES_DIR)
24 test_files.append(str(rel_path))
25 return test_files
26
27
28 @pytest.mark.parametrize('test_file', collect_example_files())
29 def test_serve(test_file):
30 returncode = subprocess.run(
31 ['python', EXAMPLES_DIR / test_file, '--serve', '--timeout', '1', '--port', '0'],
32 check=False,
33 ).returncode
34 assert returncode == 0