Skip to content

Commit

Permalink
Type tests
Browse files Browse the repository at this point in the history
* Switch from legacy pytest fixture to newer, stdlib `pathlib.Path` fixture
  • Loading branch information
john-kurkowski committed Sep 19, 2023
1 parent d366c5f commit f4ea714
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 68 deletions.
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ version = {attr = "setuptools_scm.get_version"}
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_untyped_calls = true

[[tool.mypy.overrides]]
module = ["tldextract.*"]
disallow_untyped_defs = true

[tool.pytest.ini_options]
Expand Down
12 changes: 8 additions & 4 deletions tests/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,25 @@
from tldextract.tldextract import PUBLIC_SUFFIX_LIST_URLS


def test_cli_no_input(monkeypatch):
def test_cli_no_input(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(sys, "argv", ["tldextract"])
with pytest.raises(SystemExit) as ex:
main()

assert ex.value.code == 1


def test_cli_parses_args(monkeypatch):
def test_cli_parses_args(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(sys, "argv", ["tldextract", "--some", "nonsense"])
with pytest.raises(SystemExit) as ex:
main()

assert ex.value.code == 2


def test_cli_posargs(capsys, monkeypatch):
def test_cli_posargs(
capsys: pytest.CaptureFixture, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.setattr(
sys, "argv", ["tldextract", "example.com", "bbc.co.uk", "forums.bbc.co.uk"]
)
Expand All @@ -36,7 +38,9 @@ def test_cli_posargs(capsys, monkeypatch):
assert stdout == " example com\n bbc co.uk\nforums bbc co.uk\n"


def test_cli_namedargs(capsys, monkeypatch):
def test_cli_namedargs(
capsys: pytest.CaptureFixture, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.setattr(
sys,
"argv",
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


@pytest.fixture(autouse=True)
def reset_log_level():
def reset_log_level() -> None:
"""Automatically reset log level verbosity between tests.
Generally want test output the Unix way: silence is golden.
Expand Down
10 changes: 5 additions & 5 deletions tests/custom_suffix_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
)


def test_private_extraction():
def test_private_extraction() -> None:
tld = tldextract.TLDExtract(cache_dir=tempfile.mkdtemp(), suffix_list_urls=[])

assert tld("foo.blogspot.com") == ("foo", "blogspot", "com", False)
Expand All @@ -35,7 +35,7 @@ def test_private_extraction():
)


def test_suffix_which_is_not_in_custom_list():
def test_suffix_which_is_not_in_custom_list() -> None:
for fun in (
extract_using_fake_suffix_list,
extract_using_fake_suffix_list_no_cache,
Expand All @@ -44,7 +44,7 @@ def test_suffix_which_is_not_in_custom_list():
assert result.suffix == ""


def test_custom_suffixes():
def test_custom_suffixes() -> None:
for fun in (
extract_using_fake_suffix_list,
extract_using_fake_suffix_list_no_cache,
Expand All @@ -54,12 +54,12 @@ def test_custom_suffixes():
assert result.suffix == custom_suffix


def test_suffix_which_is_not_in_extra_list():
def test_suffix_which_is_not_in_extra_list() -> None:
result = extract_using_extra_suffixes("www.google.com")
assert result.suffix == ""


def test_extra_suffixes():
def test_extra_suffixes() -> None:
for custom_suffix in EXTRA_SUFFIXES:
netloc = "www.foo.bar.baz.quux" + "." + custom_suffix
result = extract_using_extra_suffixes(netloc)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import tldextract


def test_bad_kwargs():
def test_bad_kwargs() -> None:
with pytest.raises(ValueError):
tldextract.TLDExtract(
cache_dir=None, suffix_list_urls=(), fallback_to_snapshot=False
Expand Down
Loading

0 comments on commit f4ea714

Please sign in to comment.