-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_requirement.py
92 lines (80 loc) · 2.32 KB
/
test_requirement.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import pytest
import wild_requirements as requirements
@pytest.mark.parametrize("req", [
"numpy",
"NumPy",
"numpy==1",
"numpy==1.0",
"numpy==1.0.0",
"numpy===1.0.0",
"numpy<1.0.0",
"numpy<=1.0.0",
"numpy>1.0.0",
"numpy>=1.0.0",
"numpy~=1.0.0",
"numpy==1.0.*",
"numpy==1.*",
"numpy==*",
])
def test_grammar_valid_requirement(req):
"""
Test valid requirement against the grammar.
"""
requirements.REQUIREMENT.parse_string(req)
@pytest.mark.parametrize("req", [
"numpy*",
"*numpy*",
"numpy*==1.0",
"*numpy*==1.0.0",
"*numpy*==1.0.*",
"numpy_*",
"numpy-*",
"*numpy-*",
"*numpy*-*",
])
def test_grammar_wild_requirement(req):
"""
Test valid wild (*) requirement against the grammar.
"""
requirements.REQUIREMENT.parse_string(req)
@pytest.mark.parametrize("req", [
"nu!mpy",
"*num*py*",
"(numpy)",
"[numpy]",
"*numpy*cli-*",
])
def test_grammar_invalid_requirement(req):
"""
Test invalid requirement against the grammar.
"""
with pytest.raises(Exception):
requirements.REQUIREMENT.parse_string(req)
def test_requirement_class():
"""
Test the Requirement class.
The Requirement class should parse the requirement string and store its parts.
The name should be normalized to lowercase. And `-` should be replaced with `_`.
"""
req = requirements.Requirement("NumPy==1.0.0")
assert req.name == "numpy"
assert req.specifier == "==1.0.0"
assert req.extras == set()
assert req.url is None
assert req.marker is None
assert str(req) == "numpy==1.0.0"
assert repr(req) == "<Requirement('numpy==1.0.0')>"
req = requirements.Requirement("SpaCy-metrics!=1.0.0")
assert req.name == "spacy_metrics"
assert req.specifier == "!=1.0.0"
assert req.extras == set()
assert req.url is None
assert req.marker is None
assert str(req) == "spacy_metrics!=1.0.0"
assert repr(req) == "<Requirement('spacy_metrics!=1.0.0')>"
def test_requirement_eq():
"""
Test that the requirement compare to each other.
"""
assert requirements.Requirement("SpaCy-metrics!=1.0.0") == requirements.Requirement("SpaCy-metrics!=1.0.0")
assert requirements.Requirement("SpaCy-metrics!=1.0.0") != requirements.Requirement("SpaCy-metrics!=1.1.0")