@@ -16,6 +16,9 @@ def run_pipeline(self, config_file, name, lines):
16
16
output = ""
17
17
success = True
18
18
19
+ # List of tuples containing old and new test suite name
20
+ test_suite_renames = []
21
+
19
22
test_name_rgx = regex .compile (
20
23
r"\b(?P<test_type>TEST(_F|_P)?)\((?P<whitespace>\s*)(?P<test_suite>\w+), (?P<test_case>\w+)\)"
21
24
)
@@ -34,10 +37,13 @@ def run_pipeline(self, config_file, name, lines):
34
37
output += match .group ("whitespace" )
35
38
36
39
# Fix test suite name
40
+ old_test_suite = test_suite
37
41
if test_suite .endswith ("Tests" ):
38
42
test_suite = test_suite [:- 1 ]
39
43
if not test_suite .endswith ("Test" ):
40
44
test_suite += "Test"
45
+ if old_test_suite != test_suite :
46
+ test_suite_renames .append ((old_test_suite , test_suite ))
41
47
42
48
# Write test suite name
43
49
output += test_suite
@@ -53,6 +59,8 @@ def run_pipeline(self, config_file, name, lines):
53
59
test_case = test_case [:- 4 ]
54
60
if test_case .endswith ("Tests" ):
55
61
test_case = test_case [:- 5 ]
62
+ if test_case .startswith ("Test" ) or test_case .startswith ("test" ):
63
+ test_case = test_case [4 :]
56
64
57
65
# Write test case name
58
66
output += ", " + test_case + ")"
@@ -82,19 +90,31 @@ def run_pipeline(self, config_file, name, lines):
82
90
output += match .group ("whitespace" )
83
91
84
92
# Fix test suite name
93
+ old_test_suite = test_suite
85
94
if test_suite .endswith ("Test" ):
86
95
test_suite += "s"
87
96
if not test_suite .endswith ("Tests" ):
88
97
test_suite += "Tests"
98
+ if old_test_suite != test_suite :
99
+ test_suite_renames .append ((old_test_suite , test_suite ))
89
100
90
101
# Write test suite name
91
102
output += test_suite
92
103
93
104
# Fix test case name
105
+ # TODO: Add NOLINT support since TimedRobot has a "TestMode" test
106
+ # case
107
+ # linenum = lines.count(linesep, 0, match.start()) + 1
108
+ # if "NOLINT" not in lines.splitlines()[linenum - 1]:
109
+ # format_succeeded = False
110
+ # print(name + ": " + str(linenum) + ": '" + token + \
111
+ # "' in global namespace")
94
112
if test_case .endswith ("Tests" ):
95
113
test_case = test_case [:- 1 ]
96
114
if not test_case .endswith ("Test" ):
97
115
test_case += "Test"
116
+ if test_case .startswith ("Test" ) or test_case .startswith ("test" ):
117
+ test_case = test_case [4 :]
98
118
99
119
# Write test case name
100
120
output += ", " + test_case
@@ -105,4 +125,9 @@ def run_pipeline(self, config_file, name, lines):
105
125
if extract_location < len (lines ):
106
126
output += lines [extract_location :]
107
127
128
+ # If test suites for fixtures or parameterized tests were renamed,
129
+ # rename the corresponding classes too
130
+ for rename in test_suite_renames :
131
+ output = regex .sub (f"class { rename [0 ]} " , f"class { rename [1 ]} " , output )
132
+
108
133
return output , success
0 commit comments