-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
test_install_markers.py
191 lines (154 loc) · 5.91 KB
/
test_install_markers.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function
import os
import pytest
from flaky import flaky
from pipenv.patched import pipfile
from pipenv.project import Project
from pipenv.utils import temp_environ
@flaky
@pytest.mark.markers
def test_package_environment_markers(PipenvInstance):
with PipenvInstance() as p:
with open(p.pipfile_path, 'w') as f:
contents = """
[packages]
fake_package = {version = "*", markers="os_name=='splashwear'"}
""".strip()
f.write(contents)
c = p.pipenv('install')
assert c.return_code == 0
assert 'Ignoring' in c.out
assert 'markers' in p.lockfile['default']['fake-package'], p.lockfile["default"]
c = p.pipenv('run python -c "import fake_package;"')
assert c.return_code == 1
@flaky
@pytest.mark.markers
def test_platform_python_implementation_marker(PipenvInstance):
"""Markers should be converted during locking to help users who input this
incorrectly.
"""
with PipenvInstance() as p:
with open(p.pipfile_path, 'w') as f:
contents = """
[packages]
depends-on-marked-package = "*"
""".strip()
f.write(contents)
c = p.pipenv('install')
assert c.return_code == 0
# depends-on-marked-package has an install_requires of
# 'pytz; platform_python_implementation=="CPython"'
# Verify that that marker shows up in our lockfile unaltered.
assert 'pytz' in p.lockfile['default']
assert p.lockfile['default']['pytz'].get('markers') == \
"platform_python_implementation == 'CPython'"
@flaky
@pytest.mark.run
@pytest.mark.alt
@pytest.mark.install
def test_specific_package_environment_markers(PipenvInstance):
with PipenvInstance() as p:
with open(p.pipfile_path, 'w') as f:
contents = """
[packages]
fake-package = {version = "*", os_name = "== 'splashwear'"}
""".strip()
f.write(contents)
c = p.pipenv('install')
assert c.return_code == 0
assert 'Ignoring' in c.out
assert 'markers' in p.lockfile['default']['fake-package']
c = p.pipenv('run python -c "import fake_package;"')
assert c.return_code == 1
@flaky
@pytest.mark.markers
def test_top_level_overrides_environment_markers(PipenvInstance):
"""Top-level environment markers should take precedence.
"""
with PipenvInstance() as p:
with open(p.pipfile_path, 'w') as f:
contents = """
[packages]
apscheduler = "*"
funcsigs = {version = "*", os_name = "== 'splashwear'"}
""".strip()
f.write(contents)
c = p.pipenv('install')
assert c.return_code == 0
assert "markers" in p.lockfile['default']['funcsigs'], p.lockfile['default']['funcsigs']
assert p.lockfile['default']['funcsigs']['markers'] == "os_name == 'splashwear'", p.lockfile['default']['funcsigs']
@flaky
@pytest.mark.markers
@pytest.mark.install
def test_global_overrides_environment_markers(PipenvInstance):
"""Empty (unconditional) dependency should take precedence.
If a dependency is specified without environment markers, it should
override dependencies with environment markers. In this example,
APScheduler requires funcsigs only on Python 2, but since funcsigs is
also specified as an unconditional dep, its markers should be empty.
"""
with PipenvInstance() as p:
with open(p.pipfile_path, 'w') as f:
contents = """
[packages]
apscheduler = "*"
funcsigs = "*"
""".strip()
f.write(contents)
c = p.pipenv('install')
assert c.return_code == 0
assert p.lockfile['default']['funcsigs'].get('markers', '') == ''
@flaky
@pytest.mark.lock
@pytest.mark.complex
@pytest.mark.py3_only
@pytest.mark.lte_py36
def test_resolver_unique_markers(PipenvInstance):
"""vcrpy has a dependency on `yarl` which comes with a marker
of 'python version in "3.4, 3.5, 3.6" - this marker duplicates itself:
'yarl; python version in "3.4, 3.5, 3.6"; python version in "3.4, 3.5, 3.6"'
This verifies that we clean that successfully.
"""
with PipenvInstance(chdir=True) as p:
c = p.pipenv('install vcrpy==2.0.1')
assert c.return_code == 0
c = p.pipenv('lock')
assert c.return_code == 0
assert 'yarl' in p.lockfile['default']
yarl = p.lockfile['default']['yarl']
assert 'markers' in yarl
# Two possible marker sets are ok here
assert yarl['markers'] in ["python_version in '3.4, 3.5, 3.6'", "python_version >= '3.4'"]
@flaky
@pytest.mark.project
def test_environment_variable_value_does_not_change_hash(PipenvInstance):
with PipenvInstance(chdir=True) as p:
with temp_environ():
with open(p.pipfile_path, 'w') as f:
f.write("""
[[source]]
url = 'https://${PYPI_USERNAME}:${PYPI_PASSWORD}@pypi.org/simple'
verify_ssl = true
name = 'pypi'
[packages]
six = "*"
""")
project = Project()
os.environ['PYPI_USERNAME'] = 'whatever'
os.environ['PYPI_PASSWORD'] = 'pass'
assert project.get_lockfile_hash() is None
c = p.pipenv('install')
assert c.return_code == 0
lock_hash = project.get_lockfile_hash()
assert lock_hash is not None
assert lock_hash == project.calculate_pipfile_hash()
# sanity check on pytest
assert 'PYPI_USERNAME' not in str(pipfile.load(p.pipfile_path))
assert c.return_code == 0
assert project.get_lockfile_hash() == project.calculate_pipfile_hash()
os.environ['PYPI_PASSWORD'] = 'pass2'
assert project.get_lockfile_hash() == project.calculate_pipfile_hash()
with open(p.pipfile_path, 'a') as f:
f.write('requests = "==2.14.0"\n')
assert project.get_lockfile_hash() != project.calculate_pipfile_hash()