Skip to content

Commit b48562a

Browse files
committed
Remove test case prefix
1 parent 7c04d3b commit b48562a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

wpiformat/wpiformat/gtestname.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ def run_pipeline(self, config_file, name, lines):
1616
output = ""
1717
success = True
1818

19+
# List of tuples containing old and new test suite name
20+
test_suite_renames = []
21+
1922
test_name_rgx = regex.compile(
2023
r"\b(?P<test_type>TEST(_F|_P)?)\((?P<whitespace>\s*)(?P<test_suite>\w+), (?P<test_case>\w+)\)"
2124
)
@@ -34,10 +37,13 @@ def run_pipeline(self, config_file, name, lines):
3437
output += match.group("whitespace")
3538

3639
# Fix test suite name
40+
old_test_suite = test_suite
3741
if test_suite.endswith("Tests"):
3842
test_suite = test_suite[:-1]
3943
if not test_suite.endswith("Test"):
4044
test_suite += "Test"
45+
if old_test_suite != test_suite:
46+
test_suite_renames.append((old_test_suite, test_suite))
4147

4248
# Write test suite name
4349
output += test_suite
@@ -53,6 +59,8 @@ def run_pipeline(self, config_file, name, lines):
5359
test_case = test_case[:-4]
5460
if test_case.endswith("Tests"):
5561
test_case = test_case[:-5]
62+
if test_case.startswith("Test") or test_case.startswith("test"):
63+
test_case = test_case[4:]
5664

5765
# Write test case name
5866
output += ", " + test_case + ")"
@@ -82,19 +90,31 @@ def run_pipeline(self, config_file, name, lines):
8290
output += match.group("whitespace")
8391

8492
# Fix test suite name
93+
old_test_suite = test_suite
8594
if test_suite.endswith("Test"):
8695
test_suite += "s"
8796
if not test_suite.endswith("Tests"):
8897
test_suite += "Tests"
98+
if old_test_suite != test_suite:
99+
test_suite_renames.append((old_test_suite, test_suite))
89100

90101
# Write test suite name
91102
output += test_suite
92103

93104
# 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")
94112
if test_case.endswith("Tests"):
95113
test_case = test_case[:-1]
96114
if not test_case.endswith("Test"):
97115
test_case += "Test"
116+
if test_case.startswith("Test") or test_case.startswith("test"):
117+
test_case = test_case[4:]
98118

99119
# Write test case name
100120
output += ", " + test_case
@@ -105,4 +125,9 @@ def run_pipeline(self, config_file, name, lines):
105125
if extract_location < len(lines):
106126
output += lines[extract_location:]
107127

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+
108133
return output, success

0 commit comments

Comments
 (0)