Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
john-kurkowski committed Dec 30, 2021
1 parent 5e8562f commit 500adb6
Show file tree
Hide file tree
Showing 6 changed files with 232 additions and 164 deletions.
40 changes: 22 additions & 18 deletions tests/custom_suffix_test.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,54 @@
'''tldextract unit tests with a custom suffix list.'''
"""tldextract unit tests with a custom suffix list."""

import os
import tempfile

import tldextract

FAKE_SUFFIX_LIST_URL = "file://" + os.path.join(
os.path.dirname(os.path.abspath(__file__)),
'fixtures/fake_suffix_list_fixture.dat'
os.path.dirname(os.path.abspath(__file__)), "fixtures/fake_suffix_list_fixture.dat"
)
EXTRA_SUFFIXES = ['foo1', 'bar1', 'baz1']
EXTRA_SUFFIXES = ["foo1", "bar1", "baz1"]

extract_using_fake_suffix_list = tldextract.TLDExtract(
cache_dir=tempfile.mkdtemp(),
suffix_list_urls=[FAKE_SUFFIX_LIST_URL]
cache_dir=tempfile.mkdtemp(), suffix_list_urls=[FAKE_SUFFIX_LIST_URL]
)
extract_using_fake_suffix_list_no_cache = tldextract.TLDExtract(
cache_dir=None,
suffix_list_urls=[FAKE_SUFFIX_LIST_URL]
cache_dir=None, suffix_list_urls=[FAKE_SUFFIX_LIST_URL]
)
extract_using_extra_suffixes = tldextract.TLDExtract(
cache_dir=None,
suffix_list_urls=[FAKE_SUFFIX_LIST_URL],
extra_suffixes=EXTRA_SUFFIXES
extra_suffixes=EXTRA_SUFFIXES,
)


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

assert tld("foo.blogspot.com") == ('foo', 'blogspot', 'com')
assert tld("foo.blogspot.com", include_psl_private_domains=True) == ('', 'foo', 'blogspot.com')
assert tld("foo.blogspot.com") == ("foo", "blogspot", "com")
assert tld("foo.blogspot.com", include_psl_private_domains=True) == (
"",
"foo",
"blogspot.com",
)


def test_suffix_which_is_not_in_custom_list():
for fun in (extract_using_fake_suffix_list, extract_using_fake_suffix_list_no_cache):
for fun in (
extract_using_fake_suffix_list,
extract_using_fake_suffix_list_no_cache,
):
result = fun("www.google.com")
assert result.suffix == ""


def test_custom_suffixes():
for fun in (extract_using_fake_suffix_list, extract_using_fake_suffix_list_no_cache):
for custom_suffix in ('foo', 'bar', 'baz'):
for fun in (
extract_using_fake_suffix_list,
extract_using_fake_suffix_list_no_cache,
):
for custom_suffix in ("foo", "bar", "baz"):
result = fun("www.foo.bar.baz.quux" + "." + custom_suffix)
assert result.suffix == custom_suffix

Expand Down
2 changes: 1 addition & 1 deletion tests/integration_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''tldextract integration tests.'''
"""tldextract integration tests."""

import pytest

Expand Down
Loading

0 comments on commit 500adb6

Please sign in to comment.