Skip to content

Commit

Permalink
fix: improve error message for unknown username extractor
Browse files Browse the repository at this point in the history
While adding tests, I caused `test_select_unknown_extractor` to fail and had a
hard time understanding why. This commit improves the error message for cases
where the the configured `username_extractor` does not match an existing
extractor.
  • Loading branch information
ktetzlaff committed Apr 24, 2024
1 parent ade878d commit 8c10441
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 9 additions & 3 deletions passgithelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,15 @@ def get_password(

password_extractor = SpecificLineExtractor(0, 0, option_suffix="_password")
password_extractor.configure(section)
username_extractor = _username_extractors[
section.get("username_extractor", fallback=_line_extractor_name)
]

username_extractor_name = section.get(
"username_extractor", fallback=_line_extractor_name
)
username_extractor = _username_extractors.get(username_extractor_name)
if username_extractor is None:
raise ValueError(
f"A username_extractor of type '{username_extractor_name}' does not exist"
)
username_extractor.configure(section)

environment = compute_pass_environment(section)
Expand Down
4 changes: 3 additions & 1 deletion test_passgithelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,11 @@ def test_prefix_skipping(self, capsys: Any) -> None:
indirect=True,
)
@pytest.mark.usefixtures("helper_config")
def test_select_unknown_extractor(self) -> None:
def test_select_unknown_extractor(self, capsys: Any) -> None:
with pytest.raises(SystemExit):
passgithelper.main(["get"])
_, err = capsys.readouterr()
assert "username_extractor of type 'doesntexist' does not exist" in err

@pytest.mark.parametrize(
"helper_config",
Expand Down

0 comments on commit 8c10441

Please sign in to comment.