Skip to content

Commit ec7ca6b

Browse files
committed
[Tests] Improve argument description and snake_case name conversion of test generator script
1 parent 906a4e9 commit ec7ca6b

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

tests/create_test.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ def main():
1313
os.chdir(os.path.dirname(os.path.realpath(__file__)))
1414

1515
parser = argparse.ArgumentParser(description="Creates a new unit test file.")
16-
parser.add_argument("name", type=str, help="The unit test name in PascalCase notation")
16+
parser.add_argument(
17+
"name",
18+
type=str,
19+
help="Specifies the class or component name to be tested, in PascalCase (e.g., MeshInstance3D). The name will be prefixed with 'test_' for the header file and 'Test' for the namespace.",
20+
)
1721
parser.add_argument(
1822
"path",
1923
type=str,
2024
nargs="?",
21-
help="The path to the unit test file relative to the tests folder (default: .)",
25+
help="The path to the unit test file relative to the tests folder (e.g. core). This should correspond to the relative path of the class or component being tested. (default: .)",
2226
default=".",
2327
)
2428
parser.add_argument(
@@ -29,9 +33,10 @@ def main():
2933
)
3034
args = parser.parse_args()
3135

32-
snake_case_regex = re.compile(r"(?<!^)(?=[A-Z])")
33-
name_snake_case = snake_case_regex.sub("_", args.name).lower()
34-
36+
snake_case_regex = re.compile(r"(?<!^)(?=[A-Z, 0-9])")
37+
# Replace 2D, 3D, and 4D with 2d, 3d, and 4d, respectively. This avoids undesired splits like node_3_d.
38+
prefiltered_name = re.sub(r"([234])D", lambda match: match.group(1).lower() + "d", args.name)
39+
name_snake_case = snake_case_regex.sub("_", prefiltered_name).lower()
3540
file_path = os.path.normpath(os.path.join(args.path, f"test_{name_snake_case}.h"))
3641

3742
print(file_path)

0 commit comments

Comments
 (0)