-
Notifications
You must be signed in to change notification settings - Fork 44
/
tests.py
58 lines (49 loc) · 1.24 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import random
import subprocess
from shopify_spy.spiders.shopify import get_sitemap_url
from shopify_spy.utils import as_bool
def test_contracts():
subprocess.run(["scrapy", "check", "shopify_spider"], check=True)
def test_get_sitemap_url():
inputs = [
"https://www.example.com",
"https://www.example.com/",
"https://www.example.com/products/big_fancy_table"
"https://www.example.com/products/big_fancy_table/",
]
correct = ["https://www.example.com/sitemap.xml"] * 4
for input, answer in zip(inputs, correct):
assert get_sitemap_url(input) == answer
def test_as_bool():
pos_inputs = [
"y",
"yes",
"t",
"T",
"TRue",
"on",
"ON",
"1",
True,
1,
]
neg_inputs = [
"n",
"NO",
"f",
"false",
"OfF",
"0",
"null",
"na",
"nan",
False,
0,
None,
]
pos_correct = [True] * len(pos_inputs)
neg_correct = [False] * len(neg_inputs)
queue = list(zip(pos_inputs, pos_correct)) + list(zip(neg_inputs, neg_correct))
random.shuffle(queue)
for input, answer in queue:
assert as_bool(input) is answer