Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add tests for utils.get_netrc_auth logging #143

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
from unittest import mock

from unearth.utils import LazySequence
from unearth.utils import LazySequence, get_netrc_auth


def test_lazy_sequence():
Expand All @@ -23,3 +24,29 @@ def gen(size):
assert len(seq) == 5
assert list(seq) == [0, 1, 2, 3, 4]
assert func.call_count == 5


def test_get_netrc_auth_when_unparsable(caplog, monkeypatch, tmp_path):
url = "https://test.invalid/blah"
netrc_path = tmp_path / "netrc"
netrc_path.write_text("invalid netrc entry", encoding="utf8")
monkeypatch.setenv("NETRC", str(netrc_path))
caplog.set_level(logging.WARNING)

get_netrc_auth(url)

msgs = [i.msg for i in caplog.records]
msg = "Couldn't parse netrc because of %s: %s"
assert msg in msgs


def test_get_netrc_auth_when_netrc_missing(caplog, monkeypatch, tmp_path):
url = "https://test.invalid/blah"
monkeypatch.setenv("NETRC", str(tmp_path / "bogus"))
caplog.set_level(logging.WARNING)

get_netrc_auth(url)

msgs = [i.msg for i in caplog.records]
msg = "Couldn't parse netrc because of %s: %s"
assert msg not in msgs