Skip to content

Commit

Permalink
chore: add tests for utils.get_netrc_auth logging (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
enku authored Sep 2, 2024
1 parent a56035f commit 3672fc3
Showing 1 changed file with 28 additions and 1 deletion.
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

0 comments on commit 3672fc3

Please # to comment.