Skip to content

Commit

Permalink
Invalid browser should now be caught at the type level
Browse files Browse the repository at this point in the history
  • Loading branch information
n8henrie committed Dec 29, 2023
1 parent cbce71c commit 3b395ab
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 1 addition & 4 deletions src/pycookiecheat/firefox.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ def _get_profiles_dir_for_os(
raise ValueError(
f"OS must be one of {list(FIREFOX_OS_PROFILE_DIRS.keys())}"
)
try:
return Path(os_config[browser]).expanduser()
except KeyError:
raise ValueError(f"Browser must be one of {list(os_config.keys())}")
return Path(os_config[browser]).expanduser()


def _find_firefox_default_profile(firefox_dir: Path) -> str:
Expand Down
6 changes: 4 additions & 2 deletions tests/test_firefox.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,10 @@ def test_get_profiles_dir_for_os_invalid() -> None:
"""Test invalid OS and browser names."""
with pytest.raises(ValueError, match="OS must be one of"):
_get_profiles_dir_for_os("invalid")
with pytest.raises(ValueError, match="Browser must be one of"):
_get_profiles_dir_for_os("linux", "invalid") # type: ignore
with pytest.raises(
ValueError, match="'invalid' is not a valid BrowserType"
):
_get_profiles_dir_for_os("linux", BrowserType("invalid"))


# _find_firefox_default_profile()
Expand Down

0 comments on commit 3b395ab

Please sign in to comment.