Skip to content

Commit 3f7a566

Browse files
committed
Tests (inspired by #8)
1 parent 34ec65c commit 3f7a566

File tree

5 files changed

+60
-1
lines changed

5 files changed

+60
-1
lines changed

setup.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,11 @@
2020
],
2121
install_requires=[
2222
'requests'
23-
]
23+
],
24+
extras_require={
25+
'dev': [
26+
'pytest',
27+
'codetiming'
28+
]
29+
},
2430
)

tests/__init__.py

Whitespace-only changes.

tests/conftest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import pytest
2+
from tranco.tranco import Tranco
3+
4+
5+
@pytest.fixture(scope="session")
6+
def tranco():
7+
t = Tranco(cache=True, cache_dir='.tranco')
8+
t.list() # prefetch list
9+
return t
10+
11+
12+
@pytest.fixture(scope="session")
13+
def tranco_list(tranco):
14+
return tranco.list()
15+

tests/test_list.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import uuid
2+
3+
4+
def test_top_10(tranco_list):
5+
assert len(tranco_list.top(10)) == 10
6+
7+
8+
def test_top_1000000(tranco_list):
9+
assert len(tranco_list.top(1000000)) == 1000000
10+
11+
12+
def test_domain_rank(tranco_list):
13+
top_1 = tranco_list.top(1)[0]
14+
assert tranco_list.rank(top_1) == 1
15+
16+
17+
def test_domain_not_in_list_rank(tranco_list):
18+
assert tranco_list.rank(f"domaindoesntexist{uuid.uuid4().hex.upper()[0:6]}.com") == -1

tests/test_performance.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from codetiming import Timer
2+
import pytest
3+
4+
5+
def test_performance_rank(tranco_list):
6+
core_list = tranco_list.top(1000000)
7+
# test dictionary
8+
timer = Timer(name="class", logger=None)
9+
timer.start()
10+
for i, domain in enumerate(core_list, start=1):
11+
assert i == tranco_list.rank(domain)
12+
print("Rank:", timer.stop())
13+
14+
15+
def test_performance_top(tranco_list):
16+
# test dictionary
17+
timer = Timer(name="class", logger=None)
18+
timer.start()
19+
core_list = tranco_list.top(1000000)
20+
print("Top:", timer.stop())

0 commit comments

Comments
 (0)