forked from jazzband/pip-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_cli.py
105 lines (75 loc) · 2.99 KB
/
test_cli.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
93
94
95
96
97
98
99
100
101
102
103
104
105
import os
from textwrap import dedent
from click.testing import CliRunner
import pytest
from piptools.scripts.compile import cli
@pytest.yield_fixture
def pip_conf(tmpdir):
test_conf = dedent("""\
[global]
index-url = http://example.com
trusted-host = example.com
""")
pip_conf_file = 'pip.conf' if os.name != 'nt' else 'pip.ini'
path = (tmpdir / pip_conf_file).strpath
with open(path, 'w') as f:
f.write(test_conf)
old_value = os.environ.get('PIP_CONFIG_FILE')
try:
os.environ['PIP_CONFIG_FILE'] = path
yield path
finally:
if old_value is not None:
os.environ['PIP_CONFIG_FILE'] = old_value
else:
del os.environ['PIP_CONFIG_FILE']
os.remove(path)
def test_default_pip_conf_read(pip_conf):
assert os.path.exists(pip_conf)
runner = CliRunner()
with runner.isolated_filesystem():
# preconditions
open('requirements.in', 'w').close()
out = runner.invoke(cli, ['-v'])
# check that we have our index-url as specified in pip.conf
assert 'Using indexes:\n http://example.com' in out.output
assert '--index-url http://example.com' in out.output
def test_command_line_overrides_pip_conf(pip_conf):
assert os.path.exists(pip_conf)
runner = CliRunner()
with runner.isolated_filesystem():
# preconditions
open('requirements.in', 'w').close()
out = runner.invoke(cli, ['-v', '-i', 'http://override.com'])
# check that we have our index-url as specified in pip.conf
assert 'Using indexes:\n http://override.com' in out.output
def test_find_links_option(pip_conf):
assert os.path.exists(pip_conf)
runner = CliRunner()
with runner.isolated_filesystem():
open('requirements.in', 'w').close()
out = runner.invoke(cli, ['-v', '-f', './libs1', '-f', './libs2'])
# Check that find-links has been passed to pip
assert 'Configuration:\n -f ./libs1\n -f ./libs2' in out.output
def test_extra_index_option(pip_conf):
assert os.path.exists(pip_conf)
runner = CliRunner()
with runner.isolated_filesystem():
open('requirements.in', 'w').close()
out = runner.invoke(cli, ['-v',
'--extra-index-url', 'http://extraindex1.com',
'--extra-index-url', 'http://extraindex2.com'])
assert ('Using indexes:\n'
' http://example.com\n'
' http://extraindex1.com\n'
' http://extraindex2.com' in out.output)
def test_trusted_host(pip_conf):
assert os.path.exists(pip_conf)
runner = CliRunner()
with runner.isolated_filesystem():
open('requirements.in', 'w').close()
out = runner.invoke(cli, ['-v',
'--trusted-host', 'example2.com'])
print(out.output)
assert ('--trusted-host example.com\n'
'--trusted-host example2.com\n' in out.output)