Skip to content

Commit

Permalink
Remove explicit transformation to lowercase prior validation
Browse files Browse the repository at this point in the history
Signed-off-by: Hendrik Scherner <hendrik.scherner@web.de>
  • Loading branch information
SchernHe committed Jan 10, 2025
1 parent 396a1f5 commit 910fa71
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
3 changes: 1 addition & 2 deletions kedro/framework/cli/starters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,8 +1005,7 @@ def __str__(self) -> str:

def validate(self, user_input: str) -> None:
"""Validate a given prompt value against the regex validator"""

if self.regexp and not re.match(self.regexp, user_input.lower()):
if self.regexp and not re.match(self.regexp, user_input):
message = f"'{user_input}' is an invalid value for {(self.title).lower()}."
click.secho(message, fg="red", err=True)
click.secho(self.error_message, fg="red", err=True)
Expand Down
2 changes: 1 addition & 1 deletion kedro/templates/project/prompts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ tools:
7) Kedro-Viz: Kedro's native visualisation tool
Which tools would you like to include in your project? [1-7/1,3/all/none]:
regex_validator: "^(all|none|(( )*\\d+( *- *\\d+)?( *, *\\d+( *- *\\d+)?)*( )*)?)$"
regex_validator: "(?i)^(all|none|(( )*\\d+( *- *\\d+)?( *, *\\d+( *- *\\d+)?)*( )*)?)$"
error_message: |
Invalid input. Please select valid options for project tools using comma-separated values, ranges, or 'all/none'.
Expand Down
15 changes: 12 additions & 3 deletions tests/framework/cli/test_starters.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,19 +422,27 @@ def test_empty_prompts(self, fake_kedro_cli):
_assert_template_ok(result)
_clean_up_project(Path("./new-kedro-project"))

def test_custom_prompt_valid_input(self, fake_kedro_cli):
@pytest.mark.parametrize(
"regex, valid_value",
[
("^\\w+(-*\\w+)*$", "my-value"),
("^[A-Z_]+", "MY-VALUE"),
("^\\d+$", "123"),
],
)
def test_custom_prompt_valid_input(self, fake_kedro_cli, regex, valid_value):
shutil.copytree(TEMPLATE_PATH, "template")
_write_yaml(
Path("template") / "prompts.yml",
{
"project_name": {"title": "Project Name"},
"custom_value": {
"title": "Custom Value",
"regex_validator": "^\\w+(-*\\w+)*$",
"regex_validator": regex,
},
},
)
custom_input = "\n".join(["my-project", "My Project"])
custom_input = "\n".join([valid_value, "My Project"])
result = CliRunner().invoke(
fake_kedro_cli,
["new", "--starter", "template"],
Expand All @@ -446,6 +454,7 @@ def test_custom_prompt_valid_input(self, fake_kedro_cli):
repo_name="my-project",
python_package="my_project",
)

_clean_up_project(Path("./my-project"))

def test_custom_prompt_for_essential_variable(self, fake_kedro_cli):
Expand Down

0 comments on commit 910fa71

Please sign in to comment.