Skip to content

Commit 7d6d5ab

Browse files
committed
Add a separate driver for Python
1 parent 5f7f124 commit 7d6d5ab

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed

testsuite/drivers/basic.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import glob
22
import os
3-
import sys
43

5-
from e3.os.process import Run, PIPE
64
from e3.testsuite.result import TestStatus
75

86
from drivers import ALSTestDriver

testsuite/drivers/python_driver.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import os
2+
3+
from e3.testsuite.result import TestStatus
4+
5+
from drivers import ALSTestDriver
6+
7+
import inspect
8+
import importlib.util
9+
10+
from drivers.lsp_python_driver import run_simple_test
11+
12+
13+
class PythonTestDriver(ALSTestDriver):
14+
"""Each test should have:
15+
- a test.yaml containing
16+
title: '<test name>'
17+
18+
- a number of test drivers, in .json files.
19+
"""
20+
21+
def run(self, previous_values, slot):
22+
# Check whether the test should be skipped
23+
if self.should_skip():
24+
return False
25+
26+
# The working directory
27+
wd = self.test_env["working_dir"]
28+
29+
status = TestStatus.PASS
30+
31+
# If there is a "test.py", evaluate it
32+
if os.path.exists(os.path.join(wd, "test.py")):
33+
# Load test.py as a module
34+
python_file = os.path.join(wd, "test.py")
35+
spec = importlib.util.spec_from_file_location("module.name", python_file)
36+
module = importlib.util.module_from_spec(spec)
37+
spec.loader.exec_module(module)
38+
39+
# Look for functions with the decorator @simple_test and run them
40+
errors = [
41+
f"no function with @simple_test or @complex_test found in {python_file}"
42+
]
43+
44+
for _, obj in inspect.getmembers(module):
45+
if inspect.isfunction(obj) and (
46+
hasattr(obj, "simple_test") or hasattr(obj, "complex_test")
47+
):
48+
errors = obj(wd)
49+
50+
if len(errors) > 0:
51+
self.result.log = "\n".join(errors)
52+
status = TestStatus.FAIL
53+
54+
self.result.set_status(status)
55+
self.push_result()

testsuite/testsuite.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from drivers.basic import JsonTestDriver
1010
from drivers.gnatcov import GNATcov
1111
from drivers.shell import ShellTestDriver
12+
from drivers.python_driver import PythonTestDriver
1213
from e3.testsuite import Testsuite
1314

1415
VALGRIND_OPTIONS = [
@@ -126,7 +127,7 @@ def tear_down(self):
126127

127128
@property
128129
def test_driver_map(self):
129-
return {"ada_lsp": JsonTestDriver, "shell": ShellTestDriver}
130+
return {"ada_lsp": JsonTestDriver, "shell": ShellTestDriver, "python": PythonTestDriver}
130131

131132
@property
132133
def default_driver(self):

0 commit comments

Comments
 (0)