-
Notifications
You must be signed in to change notification settings - Fork 54
/
test_utils.py
60 lines (43 loc) · 1.62 KB
/
test_utils.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
from pytest import raises
from piptools.utils import (
as_tuple, format_requirement, format_specifier, flat_map, dedup)
def test_format_requirement(from_line):
ireq = from_line('test==1.2')
assert format_requirement(ireq) == 'test==1.2'
def test_format_requirement_editable(from_editable):
ireq = from_editable('git+git://fake.org/x/y.git#egg=y')
assert format_requirement(ireq) == '-e git+git://fake.org/x/y.git#egg=y'
def test_format_specifier(from_line):
ireq = from_line('foo')
assert format_specifier(ireq) == '<any>'
ireq = from_line('foo==1.2')
assert format_specifier(ireq) == '==1.2'
ireq = from_line('foo>1.2,~=1.1,<1.5')
assert format_specifier(ireq) == '~=1.1,>1.2,<1.5'
ireq = from_line('foo~=1.1,<1.5,>1.2')
assert format_specifier(ireq) == '~=1.1,>1.2,<1.5'
def test_as_tuple(from_line):
ireq = from_line('foo==1.1')
name, version, extras = as_tuple(ireq)
assert name == 'foo'
assert version == '1.1'
assert extras == ()
ireq = from_line('foo[extra1,extra2]==1.1')
name, version, extras = as_tuple(ireq)
assert name == 'foo'
assert version == '1.1'
assert extras == ("extra1", "extra2")
# Non-pinned versions aren't accepted
should_be_rejected = [
'foo==1.*',
'foo~=1.1,<1.5,>1.2',
'foo',
]
for spec in should_be_rejected:
ireq = from_line(spec)
with raises(TypeError):
as_tuple(ireq)
def test_flat_map():
assert [1, 2, 4, 1, 3, 9] == list(flat_map(lambda x: [1, x, x * x], [2, 3]))
def test_dedup():
assert list(dedup([3, 1, 2, 4, 3, 5])) == [3, 1, 2, 4, 5]