Skip to content

Commit 0fa2ce9

Browse files
authored
fix: raise custom exception on an invalid selector method (#466)
1 parent 932a4cc commit 0fa2ce9

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

src/twyn/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,14 @@ def _get_dependencies_list(
272272
raise InvalidArgumentsError(
273273
"Cannot show progress bar because `rich` and `click` dependencies are not installed. "
274274
"It is only meant to be shown when running `twyn` as a cli tool. "
275-
"If this is you case, install all the dependencies with `pip install twyn[cli]`. "
275+
"If this is your case, install all the dependencies with `pip install twyn[cli]`. "
276276
) from e
277277

278278

279279
def _get_selector_method(selector_method: str) -> SelectorMethod:
280280
"""Return the selector_method from set of available ones."""
281281
if selector_method not in SELECTOR_METHOD_MAPPING:
282-
InvalidSelectorMethodError("Invalid selector method")
282+
raise InvalidSelectorMethodError("Invalid selector method")
283283

284284
return SELECTOR_METHOD_MAPPING[selector_method]()
285285

tests/main/test_main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ def test_check_dependencies_detects_typosquats_from_file(
163163
]
164164
)
165165

166+
def test_check_dependencies_fails_if_unkown_selector_method(self) -> None:
167+
"""Check that if an invalid selector method is given, it raises InvalidSelectorMethodError."""
168+
with pytest.raises(InvalidSelectorMethodError):
169+
check_dependencies(selector_method="asfd")
170+
166171
@patch("twyn.trusted_packages.TopPyPiReference.get_packages")
167172
def test_check_dependencies_detects_typosquats_from_file_and_language_is_set(
168173
self, mock_get_packages: Mock, uv_lock_file_with_typo: Path

0 commit comments

Comments
 (0)