diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-09-04 17:12:25 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-09-04 17:12:25 +0200 |
commit | 139f9989e6afcc9376c1c3551cc410ce04981163 (patch) | |
tree | fa7d2cb33d39d32906a7a73af3aa82f0d3ae9d05 /tests | |
parent | 9b4a965407d8561677fe8ddc02390814c6ef0ec8 (diff) | |
parent | ec7ca6bab50f56a00821a90910a89c634fcd389f (diff) | |
download | redot-engine-139f9989e6afcc9376c1c3551cc410ce04981163.tar.gz |
Merge pull request #96565 from Geometror/improve-test-generator
[Tests] `create_test` script: Improve argument description and snake_case name conversion
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/create_test.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/tests/create_test.py b/tests/create_test.py index deb53aca20..ad6d6b882f 100755 --- a/tests/create_test.py +++ b/tests/create_test.py @@ -13,12 +13,16 @@ def main(): os.chdir(os.path.dirname(os.path.realpath(__file__))) parser = argparse.ArgumentParser(description="Creates a new unit test file.") - parser.add_argument("name", type=str, help="The unit test name in PascalCase notation") + parser.add_argument( + "name", + type=str, + 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.", + ) parser.add_argument( "path", type=str, nargs="?", - help="The path to the unit test file relative to the tests folder (default: .)", + 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: .)", default=".", ) parser.add_argument( @@ -29,9 +33,10 @@ def main(): ) args = parser.parse_args() - snake_case_regex = re.compile(r"(?<!^)(?=[A-Z])") - name_snake_case = snake_case_regex.sub("_", args.name).lower() - + snake_case_regex = re.compile(r"(?<!^)(?=[A-Z, 0-9])") + # Replace 2D, 3D, and 4D with 2d, 3d, and 4d, respectively. This avoids undesired splits like node_3_d. + prefiltered_name = re.sub(r"([234])D", lambda match: match.group(1).lower() + "d", args.name) + name_snake_case = snake_case_regex.sub("_", prefiltered_name).lower() file_path = os.path.normpath(os.path.join(args.path, f"test_{name_snake_case}.h")) print(file_path) |