Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tests] create_test script: Improve argument description and snake_case name conversion #96565

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions tests/create_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
Expand Down
Loading