fix: Update regex to support TC-I-XXX tests in CLI#66
fix: Update regex to support TC-I-XXX tests in CLI#66aligruenhaupt wants to merge 1 commit intoproject-chip:mainfrom
Conversation
Edited the regex pattern, so that Tests such as TC-I-XXX work with the CLI, which threw an error before.
Summary of ChangesHello @aligruenhaupt, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical bug in the CLI tool's test ID validation logic. Previously, the regex pattern was too restrictive, preventing certain valid test case formats from being recognized, which led to errors when attempting to execute them. The updated regex now correctly accommodates these formats, ensuring that all intended test cases can be processed without issues through the command-line interface. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request updates the regular expression for test ID validation to support test cases with single-character components, such as TC-I-XXX. The change correctly modifies the quantifier to allow for this. I've added one suggestion regarding regex compilation performance.
|
|
||
| # Validate each test ID format | ||
| valid_pattern = re.compile(r"^TC[-_][A-Z_]{2,20}([-_\.]\d+){2,3}(-custom)?$") | ||
| valid_pattern = re.compile(r"^TC[-_][A-Z_]{1,20}([-_\.]\d+){2,3}(-custom)?$") |
There was a problem hiding this comment.
For improved performance, it's recommended to compile this regex at the module level, outside of this function. Compiling a regex can be a relatively expensive operation, and doing it inside a function that might be called in a loop can lead to unnecessary overhead. By defining the compiled pattern as a module-level constant, it's compiled only once when the module is imported.
For example:
# At module level, outside any function
_VALID_TEST_ID_PATTERN = re.compile(r"^TC[-_][A-Z_]{1,20}([-_.]\d+){2,3}(-custom)?$")
def validate_test_ids(test_ids: str) -> list[str]:
# ...
# inside the function, just use it
for test_id in ids:
if not _VALID_TEST_ID_PATTERN.match(test_id):
# ...As a minor point, the backslash before the dot in [-_\.] is not necessary as . is not a special character inside a character set []. You can simplify it to [-_.].
References
- For performance, regular expressions should be compiled once at the module level rather than inside a function that may be called multiple times.
What this PR does:
This PR updates the regex pattern to properly handle test cases like TC-I-XXX.
Why it is needed:
Previously, running these specific tests via the CLI tool threw an error because the regex did not match the test case format correctly.
Fixes #873