Skip to content

Commit dc5d287

Browse files
SurajBDeoresuraj
andauthored
lobster-python: add system test infra and cases (#519)
Add runner, base, Bazel targets, tests, and data fixtures for lobster-python system tests, aligning with existing tool infra. Issue: SWF-20309 Co-authored-by: suraj <Suraj.DA.Deore@bti.bmwgroup.com>
1 parent c9acd6d commit dc5d287

13 files changed

+436
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
### 1.0.3-dev
77

8+
* `lobster-python`:
9+
- Added system test infrastructure and Bazel targets under `tests_system/lobster_python`.
10+
811
* API documentation
912
- Created comprehensive API documentation using Sphinx for better user experience across all LOBSTER tools
1013
- Added detailed examples and configuration parameters for `lobster-codebeamer`,

tests_system/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
!lobster_codebeamer/data/*.lobster
66
!lobster_html_report/data/*.lobster
77
!lobster_cpptest/data/*.lobster
8+
!lobster_python/data/*.lobster
89
!lobster_html_report/data/*.html
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
load("@rules_python//python:defs.bzl", "py_library", "py_test")
2+
3+
# BUILD.bazel
4+
# gazelle:exclude __init__.py
5+
6+
py_library(
7+
name = "lobster_python",
8+
srcs = [
9+
"lobster_python_system_test_case_base.py",
10+
"lobster_python_test_runner.py",
11+
"lobster_python_asserter.py",
12+
],
13+
data = [
14+
"//tests_system/lobster_python/data:python_data_system",
15+
],
16+
visibility = [
17+
"//visibility:public",
18+
],
19+
deps = [
20+
"//:lobster",
21+
"//tests_system",
22+
],
23+
)
24+
25+
py_test(
26+
name = "test_multiple_identical_function_names",
27+
srcs = ["test_multiple_identical_function_names.py"],
28+
deps = [
29+
":lobster_python",
30+
"//tests_system",
31+
],
32+
)
33+
34+
py_test(
35+
name = "test_valid_cases",
36+
srcs = ["test_valid_cases.py"],
37+
deps = [
38+
":lobster_python",
39+
"//tests_system",
40+
],
41+
)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
filegroup(
2+
name = "python_data_system",
3+
srcs = glob([
4+
"*.py",
5+
"*.lobster",
6+
]),
7+
visibility = ["//visibility:public"],
8+
)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"data": [
3+
{
4+
"tag": "python basic.trlc_reference",
5+
"location": {
6+
"kind": "file",
7+
"file": "basic.py",
8+
"line": 4,
9+
"column": null
10+
},
11+
"name": "basic.trlc_reference",
12+
"messages": [],
13+
"just_up": [
14+
"helper function"
15+
],
16+
"just_down": [],
17+
"just_global": [],
18+
"language": "Python",
19+
"kind": "Function"
20+
},
21+
{
22+
"tag": "python basic.Example.helper_function",
23+
"location": {
24+
"kind": "file",
25+
"file": "basic.py",
26+
"line": 13,
27+
"column": null
28+
},
29+
"name": "basic.Example.helper_function",
30+
"messages": [],
31+
"just_up": [],
32+
"just_down": [],
33+
"just_global": [],
34+
"language": "Python",
35+
"kind": "Method"
36+
},
37+
{
38+
"tag": "python basic.Example.nor",
39+
"location": {
40+
"kind": "file",
41+
"file": "basic.py",
42+
"line": 17,
43+
"column": null
44+
},
45+
"name": "basic.Example.nor",
46+
"messages": [],
47+
"just_up": [],
48+
"just_down": [],
49+
"just_global": [],
50+
"refs": [
51+
"req example.req_nor"
52+
],
53+
"language": "Python",
54+
"kind": "Method"
55+
}
56+
],
57+
"generator": "lobster_python",
58+
"schema": "lobster-imp-trace",
59+
"version": 3
60+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import potatolib
2+
3+
4+
def trlc_reference(requirement):
5+
# lobster-exclude: helper function
6+
def decorator(obj):
7+
return obj
8+
return decorator
9+
10+
11+
class Example:
12+
@trlc_reference(requirement="example.req_nor")
13+
def helper_function(a, b):
14+
# potato
15+
return a or b
16+
17+
def nor(a, b):
18+
# lobster-trace: example.req_nor
19+
assert isinstance(a, bool)
20+
assert isinstance(b, bool)
21+
22+
return not helper_function(a, b)
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{
2+
"data": [
3+
{
4+
"tag": "python multiple_identical_function_names.get_requirements",
5+
"location": {
6+
"kind": "file",
7+
"file": "multiple_identical_function_names.py",
8+
"line": 5,
9+
"column": null
10+
},
11+
"name": "multiple_identical_function_names.get_requirements",
12+
"messages": [],
13+
"just_up": [],
14+
"just_down": [],
15+
"just_global": [],
16+
"language": "Python",
17+
"kind": "Function"
18+
},
19+
{
20+
"tag": "python multiple_identical_function_names.set_requirements",
21+
"location": {
22+
"kind": "file",
23+
"file": "multiple_identical_function_names.py",
24+
"line": 8,
25+
"column": null
26+
},
27+
"name": "multiple_identical_function_names.set_requirements",
28+
"messages": [],
29+
"just_up": [],
30+
"just_down": [],
31+
"just_global": [],
32+
"language": "Python",
33+
"kind": "Function"
34+
},
35+
{
36+
"tag": "python multiple_identical_function_names.get_requirements-1",
37+
"location": {
38+
"kind": "file",
39+
"file": "multiple_identical_function_names.py",
40+
"line": 13,
41+
"column": null
42+
},
43+
"name": "multiple_identical_function_names.get_requirements",
44+
"messages": [],
45+
"just_up": [],
46+
"just_down": [],
47+
"just_global": [],
48+
"language": "Python",
49+
"kind": "Function"
50+
},
51+
{
52+
"tag": "python multiple_identical_function_names.display_requirements",
53+
"location": {
54+
"kind": "file",
55+
"file": "multiple_identical_function_names.py",
56+
"line": 17,
57+
"column": null
58+
},
59+
"name": "multiple_identical_function_names.display_requirements",
60+
"messages": [],
61+
"just_up": [],
62+
"just_down": [],
63+
"just_global": [],
64+
"language": "Python",
65+
"kind": "Function"
66+
},
67+
{
68+
"tag": "python multiple_identical_function_names.set_requirements-1",
69+
"location": {
70+
"kind": "file",
71+
"file": "multiple_identical_function_names.py",
72+
"line": 21,
73+
"column": null
74+
},
75+
"name": "multiple_identical_function_names.set_requirements",
76+
"messages": [],
77+
"just_up": [],
78+
"just_down": [],
79+
"just_global": [],
80+
"language": "Python",
81+
"kind": "Function"
82+
},
83+
{
84+
"tag": "python multiple_identical_function_names.get_requirements-2",
85+
"location": {
86+
"kind": "file",
87+
"file": "multiple_identical_function_names.py",
88+
"line": 26,
89+
"column": null
90+
},
91+
"name": "multiple_identical_function_names.get_requirements",
92+
"messages": [],
93+
"just_up": [],
94+
"just_down": [],
95+
"just_global": [],
96+
"language": "Python",
97+
"kind": "Function"
98+
}
99+
],
100+
"generator": "lobster_python",
101+
"schema": "lobster-imp-trace",
102+
"version": 3
103+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
flag = False
2+
requirements_global = None
3+
4+
if flag:
5+
def get_requirements(requirements):
6+
return requirements
7+
else:
8+
def set_requirements(requirements):
9+
requirements_global = requirements
10+
return requirements_global
11+
12+
13+
def get_requirements(requirements):
14+
return requirements
15+
16+
17+
def display_requirements():
18+
print(get_requirements())
19+
20+
21+
def set_requirements(requirements):
22+
requirements_global = requirements
23+
return requirements_global
24+
25+
26+
def get_requirements(requirements):
27+
return requirements
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from tests_system.asserter import Asserter
2+
3+
4+
# Setting this flag will tell unittest not to print tracebacks from this frame.
5+
# This way our custom assertions will show the interesting line number from the caller
6+
# frame, and not from this boring file.
7+
__unittest = True
8+
9+
10+
class LobsterPythonTestAsserter(Asserter):
11+
def assertStdOutNumAndFile(self, num_items: int, out_file: str):
12+
self.assertStdOutText(
13+
f"Written output for {num_items} items to {out_file}\n"
14+
)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from pathlib import Path
2+
from tests_system.lobster_python.lobster_python_test_runner import (
3+
LobsterPythonTestRunner,
4+
)
5+
from tests_system.system_test_case_base import SystemTestCaseBase
6+
7+
8+
class LobsterPythonSystemTestCaseBase(SystemTestCaseBase):
9+
def __init__(self, methodName):
10+
super().__init__(methodName)
11+
self._data_directory = Path(__file__).parents[0] / "data"
12+
13+
def create_test_runner(self) -> LobsterPythonTestRunner:
14+
tool_name = Path(__file__).parents[0].name
15+
test_runner = LobsterPythonTestRunner(
16+
self.create_temp_dir(prefix=f"test-{tool_name}-"),
17+
)
18+
return test_runner

0 commit comments

Comments
 (0)