Skip to content

Commit

Permalink
Fix test failures and clean up pyright controls.
Browse files Browse the repository at this point in the history
Related #38
  • Loading branch information
aholmes committed Feb 16, 2024
1 parent f66b3ff commit dd03338
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/programming/BL_Python/programming/cli/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def __call__(
option_string: str | None = None,
) -> None:
if (associated_arg_value := getattr(namespace, associated_arg, None)):
if values in associated_arg_value or associated_arg_value == values:
if associated_arg_value == values or (isinstance(associated_arg_value, Iterable) and values in associated_arg_value):
raise ArgumentError(
self,
f"The {self.option_strings} argument cannot be equivalent to the `{associated_arg}` argument. The value `{values}` is equivalent to the value `{associated_arg_value}`.",
Expand Down
27 changes: 15 additions & 12 deletions src/programming/test/unit/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
disallow,
)

# pyright: reportUnknownVariableType=false
# pyright: reportUninitializedInstanceVariable=false


def test__disallow__raises_ArgumentTypeError_when_disallowed_value_is_used():
argument_type = disallow(["foo"], "argument")
Expand Down Expand Up @@ -34,7 +37,7 @@ def test__disallow__returns_argument_value_as_custom_type_when_disallowed_value_

def test__DisallowDuplicateValues__allows_repeated_use_of_argument():
class ParserNamespace(Namespace):
a: str # pyright: ignore[reportUninitializedInstanceVariable]
a: str

parser = ArgumentParser()
argument_action = DisallowDuplicateValues(["-a"], "a")
Expand All @@ -51,7 +54,7 @@ class ParserNamespace(Namespace):

def test__DisallowDuplicateValues__raises_ArgumentError_when_duplicate_value_for_argument_is_used():
class ParserNamespace(Namespace):
a: str # pyright: ignore[reportUninitializedInstanceVariable]
a: str

parser = ArgumentParser()
argument_action = DisallowDuplicateValues(["-a"], "a")
Expand All @@ -69,8 +72,8 @@ class ParserNamespace(Namespace):

def test__associate_disallow_duplicate_values__allows_use_of_associated_arguments_with_differing_values():
class ParserNamespace(Namespace):
a: str # pyright: ignore[reportUninitializedInstanceVariable]
b: str # pyright: ignore[reportUninitializedInstanceVariable]
a: str
b: str

parser = ArgumentParser()
# associate "b" with "a" - this means "b" cannot have
Expand All @@ -88,8 +91,8 @@ class ParserNamespace(Namespace):

def test__associate_disallow_duplicate_values__raises_ArgumentError_when_associated_argument_value_is_not_unique():
class ParserNamespace(Namespace):
a: str # pyright: ignore[reportUninitializedInstanceVariable]
b: str # pyright: ignore[reportUninitializedInstanceVariable]
a: str
b: str

parser = ArgumentParser()
action = associate_disallow_duplicate_values("a")
Expand All @@ -106,8 +109,8 @@ class ParserNamespace(Namespace):

def test__associate_disallow_duplicate_values__allows_use_of_associated_arguments_when_associated_argument_is_repeated():
class ParserNamespace(Namespace):
a: list[str] # pyright: ignore[reportUninitializedInstanceVariable]
b: str # pyright: ignore[reportUninitializedInstanceVariable]
a: list[str]
b: str

parser = ArgumentParser()
action = associate_disallow_duplicate_values("a")
Expand All @@ -124,8 +127,8 @@ class ParserNamespace(Namespace):

def test__associate_disallow_duplicate_values__raises_ArgumentError_when_handling_non_unique_values_when_associated_argument_is_repeated():
class ParserNamespace(Namespace):
a: list[str] # pyright: ignore[reportUninitializedInstanceVariable]
b: str # pyright: ignore[reportUninitializedInstanceVariable]
a: list[str]
b: str

parser = ArgumentParser()
action = associate_disallow_duplicate_values("a")
Expand All @@ -142,8 +145,8 @@ class ParserNamespace(Namespace):

def test__associate_disallow_duplicate_values__falls_back_to_DisallowDuplicateValues_when_associated_argument_value_is_unique():
class ParserNamespace(Namespace):
a: str # pyright: ignore[reportUninitializedInstanceVariable]
b: str # pyright: ignore[reportUninitializedInstanceVariable]
a: str
b: str

parser = ArgumentParser()
action = associate_disallow_duplicate_values("a")
Expand Down
4 changes: 2 additions & 2 deletions src/web/test/unit/scaffolding/test_scaffolding.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def test__parse_args__disallows_duplicated_endpoint_names(
captured = capsys.readouterr()
assert e.value.code == 2
assert (
f"{mode}: error: argument -e: The `endpoint` argument does not allow duplicate values. The value `foo-bar` duplicates the value `foo_bar`."
f"{mode}: error: argument -e: The ['-e'] argument does not allow duplicate values. The value `foo-bar` duplicates the value `foo_bar`."
in captured.err
)

Expand All @@ -211,7 +211,7 @@ def test__parse_args__disallows_endpoints_with_same_name_as_application(
captured = capsys.readouterr()
assert e.value.code == 2
assert (
f"{mode}: error: argument -e: The `endpoint` argument cannot be equivalent to the `name` argument. The value `foo_bar` is equivalent to the value `foo-bar`."
f"{mode}: error: argument -e: The ['-e'] argument cannot be equivalent to the `name` argument. The value `foo_bar` is equivalent to the value `foo-bar`."
in captured.err
)

Expand Down

0 comments on commit dd03338

Please sign in to comment.