-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(cli): add tests for CLI options utils (#67)
- Loading branch information
1 parent
3961938
commit 376b083
Showing
2 changed files
with
50 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from __future__ import annotations | ||
|
||
import pytest | ||
from click.core import Argument, BadParameter, Command, Context | ||
from spark_on_k8s.cli.options import validate_dictionary_option, validate_list_option | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"passed_value, expected_result", | ||
[ | ||
pytest.param([], {}, id="empty value"), | ||
pytest.param(["p1=v1"], {"p1": "v1"}, id="a single value"), | ||
pytest.param(["p1=v1", "p2=v2"], {"p1": "v1", "p2": "v2"}, id="multiple values"), | ||
pytest.param(["p1:v1"], BadParameter, id="a bad value"), | ||
pytest.param(["p1=v1", "p2"], BadParameter, id="multiple value with a bad one"), | ||
], | ||
) | ||
def test_validate_dictionary_option( | ||
passed_value: list[str], expected_result: dict[str, str] | type[Exception] | ||
): | ||
ctx = Context(Command("fake-command")) | ||
param = Argument(["--test-param"]) | ||
if isinstance(expected_result, type) and issubclass(expected_result, Exception): | ||
with pytest.raises(expected_result): | ||
validate_dictionary_option(ctx, param, passed_value) | ||
else: | ||
actual_result = validate_dictionary_option(ctx, param, passed_value) | ||
assert expected_result == actual_result | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"passed_value, expected_result", | ||
[ | ||
pytest.param("", [], id="empty value"), | ||
pytest.param("p1", ["p1"], id="a single value"), | ||
pytest.param("p1,p2,p3", ["p1", "p2", "p3"], id="multiple values"), | ||
], | ||
) | ||
def test_validate_list_option(passed_value: str, expected_result: list[str]): | ||
ctx = Context(Command("fake-command")) | ||
param = Argument(["--test-param"]) | ||
actual_result = validate_list_option(ctx, param, passed_value) | ||
assert expected_result == actual_result |