-
-
Notifications
You must be signed in to change notification settings - Fork 261
/
Copy pathtest_harness.py
53 lines (34 loc) · 1.32 KB
/
test_harness.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
"""
Simple tests for python harness
Usage:
$ pytest test_harness.py
"""
from crawleruseragents import is_crawler, matching_crawlers
def test_nomatch():
assert is_crawler("!!!!!!!!!!!!") is False
def test_case_sensitive():
assert is_crawler("test googlebot/2.0 test") is False
def test_case_insensitive():
assert is_crawler("test googlebot/2.0 test", case_sensitive=False) is True
def test_matching_crawlers_match_case_sensitive():
result = matching_crawlers("test Googlebot/2.0 test")
assert isinstance(result, list)
assert len(result) > 0
assert all(isinstance(val, int) for val in result)
def test_matching_crawlers_match_case_insensitive():
result = matching_crawlers("test googlebot/2.0 test", False)
assert isinstance(result, list)
assert len(result) > 0
assert all(isinstance(val, int) for val in result)
def test_matching_crawlers_match_lower_case_agent():
result = matching_crawlers("test googlebot/2.0 test")
assert isinstance(result, list)
assert len(result) == 0
def test_matching_crawlers_nomatch():
result = matching_crawlers("!!!!!!!!!!!!")
assert isinstance(result, list)
assert len(result) == 0
def test_matching_crawlers_case():
result = matching_crawlers("test googlebot/2.0 test")
assert isinstance(result, list)
assert len(result) == 0