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

Fix --tools=all not working properly #3361

Merged
merged 29 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5faebf3
add fix
SajidAlamQB Nov 29, 2023
0f61dd5
Merge branch 'develop' into bugfix/addons=all-fix
lrcouto Nov 29, 2023
7e7ca3f
add fix
SajidAlamQB Nov 29, 2023
16ef432
Rename addons to tools (#3357)
AhdraMeraliQB Nov 29, 2023
87e2e1e
Fix broken tests (#3366)
AhdraMeraliQB Nov 29, 2023
9ab8759
Merge branch 'develop' into bugfix/addons=all-fix
lrcouto Nov 30, 2023
f127b48
Fix variable names on _convert_tool_names_to_numbers
lrcouto Nov 30, 2023
4090586
Merge branch 'bugfix/addons=all-fix' of github.com:kedro-org/kedro in…
lrcouto Nov 30, 2023
47c4118
Merge branch 'bugfix/addons=all-fix' of https://github.com/kedro-org/…
SajidAlamQB Nov 30, 2023
70985cc
Merge branch 'develop' into bugfix/addons=all-fix
SajidAlamQB Nov 30, 2023
a3eea61
Merge branch 'develop' into bugfix/addons=all-fix
SajidAlamQB Nov 30, 2023
fd7b734
Merge branch 'develop' into bugfix/addons=all-fix
lrcouto Nov 30, 2023
6888463
Merge branch 'develop' into bugfix/addons=all-fix
lrcouto Nov 30, 2023
143b204
Merge branch 'develop' into bugfix/addons=all-fix
lrcouto Nov 30, 2023
ba0d696
Add tests for helper functions
lrcouto Dec 1, 2023
dab4d29
Merge branch 'develop' into bugfix/addons=all-fix
SajidAlamQB Dec 5, 2023
d6672a3
Merge branch 'develop' into bugfix/addons=all-fix
lrcouto Dec 5, 2023
f9802c7
Merge branch 'develop' into bugfix/addons=all-fix
lrcouto Dec 6, 2023
b353f63
Merge branch 'develop' into bugfix/addons=all-fix
lrcouto Dec 6, 2023
545755a
Lint
lrcouto Dec 6, 2023
4bc1748
Merge branch 'develop' into bugfix/addons=all-fix
lrcouto Dec 6, 2023
93d5b50
Merge branch 'develop' into bugfix/addons=all-fix
lrcouto Dec 7, 2023
c875b3c
Merge branch 'develop' into bugfix/addons=all-fix
lrcouto Dec 7, 2023
3df74ab
Return numbers to tools names on conversion from all
lrcouto Dec 7, 2023
a821ede
Merge branch 'bugfix/addons=all-fix' of github.com:kedro-org/kedro in…
lrcouto Dec 7, 2023
d33b745
Merge branch 'develop' into bugfix/addons=all-fix
lrcouto Dec 7, 2023
a228843
Merge branch 'develop' into bugfix/addons=all-fix
SajidAlamQB Dec 8, 2023
31d7a3f
Merge branch 'develop' into bugfix/addons=all-fix
SajidAlamQB Dec 8, 2023
3e6666e
Merge branch 'develop' into bugfix/addons=all-fix
SajidAlamQB Dec 8, 2023
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
4 changes: 4 additions & 0 deletions kedro/framework/cli/starters.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,10 @@ def _convert_tool_names_to_numbers(selected_tools: str | None) -> str | None:
"""
if selected_tools is None:
return None
if selected_tools.lower() == "none":
return ""
if selected_tools.lower() == "all":
return ",".join(NUMBER_TO_TOOLS_NAME.keys())

tools = []
for tool in selected_tools.lower().split(","):
Expand Down
164 changes: 129 additions & 35 deletions tests/framework/cli/test_starters.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,43 +291,42 @@ def test_starter_list_with_invalid_starter_plugin(
assert expected in result.output


@pytest.mark.parametrize(
"input,expected",
[
("1", ["1"]),
("1,2,3", ["1", "2", "3"]),
("2-4", ["2", "3", "4"]),
("3-3", ["3"]),
("all", ["1", "2", "3", "4", "5", "6", "7"]),
("none", []),
],
)
def test_parse_tools_valid(input, expected):
result = _parse_tools_input(input)
assert result == expected


@pytest.mark.parametrize(
"input",
["5-2", "3-1"],
)
def test_parse_tools_invalid_range(input, capsys):
with pytest.raises(SystemExit):
_parse_tools_input(input)
message = f"'{input}' is an invalid range for project tools.\nPlease ensure range values go from smaller to larger."
assert message in capsys.readouterr().err
class TestParseToolsInput:
@pytest.mark.parametrize(
"input,expected",
[
("1", ["1"]),
("1,2,3", ["1", "2", "3"]),
("2-4", ["2", "3", "4"]),
("3-3", ["3"]),
("all", ["1", "2", "3", "4", "5", "6", "7"]),
("none", []),
],
)
def test_parse_tools_valid(self, input, expected):
result = _parse_tools_input(input)
assert result == expected

@pytest.mark.parametrize(
"input",
["5-2", "3-1"],
)
def test_parse_tools_invalid_range(self, input, capsys):
with pytest.raises(SystemExit):
_parse_tools_input(input)
message = f"'{input}' is an invalid range for project tools.\nPlease ensure range values go from smaller to larger."
assert message in capsys.readouterr().err

@pytest.mark.parametrize(
"input,last_invalid",
[("0,3,5", "0"), ("1,3,8", "8"), ("0-4", "0"), ("3-9", "9")],
)
def test_parse_tools_invalid_selection(input, last_invalid, capsys):
with pytest.raises(SystemExit):
selected = _parse_tools_input(input)
_validate_selection(selected)
message = f"'{last_invalid}' is not a valid selection.\nPlease select from the available tools: 1, 2, 3, 4, 5, 6, 7."
assert message in capsys.readouterr().err
@pytest.mark.parametrize(
"input,last_invalid",
[("0,3,5", "0"), ("1,3,8", "8"), ("0-4", "0"), ("3-9", "9")],
)
def test_parse_tools_invalid_selection(self, input, last_invalid, capsys):
with pytest.raises(SystemExit):
selected = _parse_tools_input(input)
_validate_selection(selected)
message = f"'{last_invalid}' is not a valid selection.\nPlease select from the available tools: 1, 2, 3, 4, 5, 6, 7."
assert message in capsys.readouterr().err


@pytest.mark.usefixtures("chdir_to_tmp")
Expand Down Expand Up @@ -1366,3 +1365,98 @@ def test_invalid_names(self, fake_kedro_cli, name):
"Kedro project names must contain only alphanumeric symbols, spaces, underscores and hyphens and be at least 2 characters long"
in result.output
)


class TestParseYesNoToBools:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we move the tests for parse_tools_input into their own class as well? For consistency

@pytest.mark.parametrize(
"input",
["yes", "YES", "y", "Y", "yEs"],
)
def parse_yes_no_to_bool_responds_true(self, input):
assert _parse_yes_no_to_bool(input) is True

@pytest.mark.parametrize(
"input",
["no", "NO", "n", "N", "No", ""],
)
def parse_yes_no_to_bool_responds_false(self, input):
assert _parse_yes_no_to_bool(input) is False

def parse_yes_no_to_bool_responds_none(self):
assert _parse_yes_no_to_bool(None) is None


class TestValidateSelection:
def test_validate_selection_valid(self):
tools = ["1", "2", "3", "4"]
assert _validate_selection(tools) is None

def test_validate_selection_invalid_single_tool(self, capsys):
tools = ["8"]
with pytest.raises(SystemExit):
_validate_selection(tools)
Copy link
Contributor

@AhdraMeraliQB AhdraMeraliQB Dec 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add an assert for the correct error message? E.g the implementation for test_parse_tools_invalid_selection

message = "is not a valid selection.\nPlease select from the available tools: 1, 2, 3, 4, 5, 6, 7."
assert message in capsys.readouterr().err

def test_validate_selection_invalid_multiple_tools(self, capsys):
tools = ["8", "10", "15"]
with pytest.raises(SystemExit):
_validate_selection(tools)
message = "is not a valid selection.\nPlease select from the available tools: 1, 2, 3, 4, 5, 6, 7."
assert message in capsys.readouterr().err

def test_validate_selection_mix_valid_invalid_tools(self, capsys):
tools = ["1", "8", "3", "15"]
with pytest.raises(SystemExit):
_validate_selection(tools)
message = "is not a valid selection.\nPlease select from the available tools: 1, 2, 3, 4, 5, 6, 7."
assert message in capsys.readouterr().err

def test_validate_selection_empty_list(self):
tools = []
assert _validate_selection(tools) is None


class TestConvertToolNamesToNumbers:
def test_convert_tool_names_to_numbers_with_valid_tools(self):
selected_tools = "lint,test,docs"
result = _convert_tool_names_to_numbers(selected_tools)
assert result == "1,2,4"

def test_convert_tool_names_to_numbers_with_none(self):
result = _convert_tool_names_to_numbers(None)
assert result is None

def test_convert_tool_names_to_numbers_with_empty_string(self):
selected_tools = ""
result = _convert_tool_names_to_numbers(selected_tools)
assert result == ""

def test_convert_tool_names_to_numbers_with_none_string(self):
selected_tools = "none"
result = _convert_tool_names_to_numbers(selected_tools)
assert result == ""

def test_convert_tool_names_to_numbers_with_all_string(self):
result = _convert_tool_names_to_numbers("all")
assert result == "1,2,3,4,5,6,7"

def test_convert_tool_names_to_numbers_with_mixed_valid_invalid_tools(self):
selected_tools = "lint,invalid_tool,docs"
result = _convert_tool_names_to_numbers(selected_tools)
assert result == "1,4"

def test_convert_tool_names_to_numbers_with_whitespace(self):
selected_tools = " lint , test , docs "
result = _convert_tool_names_to_numbers(selected_tools)
assert result == "1,2,4"

def test_convert_tool_names_to_numbers_with_case_insensitive_tools(self):
selected_tools = "Lint,TEST,Docs"
result = _convert_tool_names_to_numbers(selected_tools)
assert result == "1,2,4"

def test_convert_tool_names_to_numbers_with_invalid_tools(self):
selected_tools = "invalid_tool1,invalid_tool2"
result = _convert_tool_names_to_numbers(selected_tools)
assert result == ""