No issue - Add first tests for test_api_helpers.py
This commit is contained in:
Родитель
6d9086a4f4
Коммит
96b5be34a6
|
@ -2,3 +2,4 @@ Flask==1.1.2
|
|||
markdown==3.2.1
|
||||
requests==2.23.0
|
||||
tqdm==4.46.0
|
||||
pytest
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
1,google.com
|
||||
2,youtube.com
|
||||
3,facebook.com
|
||||
4,tmall.com
|
||||
5,qq.com
|
||||
6,netflix.com
|
||||
7,baidu.com
|
||||
8,microsoft.com
|
||||
9,sohu.com
|
||||
10,twitter.com
|
||||
11,login.tmall.com
|
||||
12,instagram.com
|
||||
13,taobao.com
|
||||
14,360.cn
|
||||
15,linkedin.com
|
||||
16,jd.com
|
||||
17,wikipedia.org
|
||||
18,yahoo.com
|
||||
19,windowsupdate.com
|
||||
20,amazon.com
|
||||
21,apple.com
|
||||
22,zoom.us
|
||||
23,sina.com.cn
|
||||
24,live.com
|
||||
25,pages.tmall.com
|
||||
26,weibo.com
|
||||
27,reddit.com
|
||||
28,googletagmanager.com
|
||||
29,adobe.com
|
||||
30,doubleclick.net
|
|
|
@ -0,0 +1,48 @@
|
|||
import os
|
||||
from trexa.api.endpoints import trim_csv
|
||||
|
||||
"""Tests for the API helper methods."""
|
||||
|
||||
test_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
test_csv = os.path.join(test_dir, 'fixtures',
|
||||
'test_file_with_thirty_lines.csv')
|
||||
|
||||
|
||||
def get_csv_length(desired_length):
|
||||
"""Helper method for trimming."""
|
||||
f = trim_csv(test_csv, desired_length)
|
||||
new_file = []
|
||||
while True:
|
||||
try:
|
||||
new_file.append(next(f))
|
||||
except StopIteration:
|
||||
break
|
||||
return len(new_file)
|
||||
|
||||
|
||||
def test_trimming_smaller():
|
||||
"""Test that we end up with a smaller file."""
|
||||
assert get_csv_length(10) == 10
|
||||
assert get_csv_length(0) == 0
|
||||
|
||||
|
||||
def test_trimming_none():
|
||||
"""Test that passing in None returns the entire file."""
|
||||
assert get_csv_length(None) == 30
|
||||
# Test not passing in a count
|
||||
f = trim_csv(test_csv)
|
||||
new_file = []
|
||||
while True:
|
||||
try:
|
||||
new_file.append(next(f))
|
||||
except StopIteration:
|
||||
break
|
||||
assert len(new_file) == 30
|
||||
|
||||
|
||||
def test_trimming_with_garbage():
|
||||
"""Test that nothing weird happens."""
|
||||
assert get_csv_length(35) == 30
|
||||
assert get_csv_length('WHAT') == 30
|
||||
assert get_csv_length('🤬') == 30
|
||||
assert get_csv_length(hex(10)) == 30
|
Загрузка…
Ссылка в новой задаче