|
4 | 4 |
|
5 | 5 | import pytest
|
6 | 6 |
|
| 7 | +from tests.lib.server import file_response, package_page |
| 8 | + |
7 | 9 |
|
8 | 10 | def test_options_from_env_vars(script):
|
9 | 11 | """
|
@@ -44,26 +46,15 @@ def test_command_line_options_override_env_vars(script, virtualenv):
|
44 | 46 | def test_env_vars_override_config_file(script, virtualenv):
|
45 | 47 | """
|
46 | 48 | Test that environmental variables override settings in config files.
|
47 |
| -
|
48 | 49 | """
|
49 |
| - fd, config_file = tempfile.mkstemp('-pip.cfg', 'test-') |
50 |
| - try: |
51 |
| - _test_env_vars_override_config_file(script, virtualenv, config_file) |
52 |
| - finally: |
53 |
| - # `os.close` is a workaround for a bug in subprocess |
54 |
| - # https://bugs.python.org/issue3210 |
55 |
| - os.close(fd) |
56 |
| - os.remove(config_file) |
57 |
| - |
58 |
| - |
59 |
| -def _test_env_vars_override_config_file(script, virtualenv, config_file): |
| 50 | + config_file = script.scratch_path / "test-pip.cfg" |
60 | 51 | # set this to make pip load it
|
61 |
| - script.environ['PIP_CONFIG_FILE'] = config_file |
| 52 | + script.environ['PIP_CONFIG_FILE'] = str(config_file) |
62 | 53 | # It's important that we test this particular config value ('no-index')
|
63 | 54 | # because there is/was a bug which only shows up in cases in which
|
64 | 55 | # 'config-item' and 'config_item' hash to the same value modulo the size
|
65 | 56 | # of the config dictionary.
|
66 |
| - (script.scratch_path / config_file).write_text(textwrap.dedent("""\ |
| 57 | + config_file.write_text(textwrap.dedent("""\ |
67 | 58 | [global]
|
68 | 59 | no-index = 1
|
69 | 60 | """))
|
@@ -133,56 +124,55 @@ def test_command_line_appends_correctly(script, data):
|
133 | 124 | ), 'stdout: {}'.format(result.stdout)
|
134 | 125 |
|
135 | 126 |
|
136 |
| -@pytest.mark.network |
137 |
| -def test_config_file_override_stack(script, virtualenv): |
| 127 | +def test_config_file_override_stack( |
| 128 | + script, virtualenv, mock_server, shared_data |
| 129 | +): |
138 | 130 | """
|
139 | 131 | Test config files (global, overriding a global config with a
|
140 | 132 | local, overriding all with a command line flag).
|
141 |
| -
|
142 | 133 | """
|
143 |
| - fd, config_file = tempfile.mkstemp('-pip.cfg', 'test-') |
144 |
| - try: |
145 |
| - _test_config_file_override_stack(script, virtualenv, config_file) |
146 |
| - finally: |
147 |
| - # `os.close` is a workaround for a bug in subprocess |
148 |
| - # https://bugs.python.org/issue3210 |
149 |
| - os.close(fd) |
150 |
| - os.remove(config_file) |
| 134 | + mock_server.set_responses([ |
| 135 | + package_page({}), |
| 136 | + package_page({}), |
| 137 | + package_page({"INITools-0.2.tar.gz": "/files/INITools-0.2.tar.gz"}), |
| 138 | + file_response(shared_data.packages.joinpath("INITools-0.2.tar.gz")), |
| 139 | + ]) |
| 140 | + mock_server.start() |
| 141 | + base_address = "http://{}:{}".format(mock_server.host, mock_server.port) |
151 | 142 |
|
| 143 | + config_file = script.scratch_path / "test-pip.cfg" |
152 | 144 |
|
153 |
| -def _test_config_file_override_stack(script, virtualenv, config_file): |
154 | 145 | # set this to make pip load it
|
155 |
| - script.environ['PIP_CONFIG_FILE'] = config_file |
156 |
| - (script.scratch_path / config_file).write_text(textwrap.dedent("""\ |
| 146 | + script.environ['PIP_CONFIG_FILE'] = str(config_file) |
| 147 | + |
| 148 | + config_file.write_text(textwrap.dedent("""\ |
157 | 149 | [global]
|
158 |
| - index-url = https://download.zope.org/ppix |
159 |
| - """)) |
160 |
| - result = script.pip('install', '-vvv', 'INITools', expect_error=True) |
161 |
| - assert ( |
162 |
| - "Getting page https://download.zope.org/ppix/initools" in result.stdout |
163 |
| - ) |
| 150 | + index-url = {}/simple1 |
| 151 | + """.format(base_address))) |
| 152 | + script.pip('install', '-vvv', 'INITools', expect_error=True) |
164 | 153 | virtualenv.clear()
|
165 |
| - (script.scratch_path / config_file).write_text(textwrap.dedent("""\ |
| 154 | + |
| 155 | + config_file.write_text(textwrap.dedent("""\ |
166 | 156 | [global]
|
167 |
| - index-url = https://download.zope.org/ppix |
| 157 | + index-url = {address}/simple1 |
168 | 158 | [install]
|
169 |
| - index-url = https://pypi.gocept.com/ |
170 |
| - """)) |
171 |
| - result = script.pip('install', '-vvv', 'INITools', expect_error=True) |
172 |
| - assert "Getting page https://pypi.gocept.com/initools" in result.stdout |
173 |
| - result = script.pip( |
174 |
| - 'install', '-vvv', '--index-url', 'https://pypi.org/simple/', |
175 |
| - 'INITools', |
176 |
| - ) |
177 |
| - assert ( |
178 |
| - "Getting page http://download.zope.org/ppix/INITools" |
179 |
| - not in result.stdout |
| 159 | + index-url = {address}/simple2 |
| 160 | + """.format(address=base_address)) |
180 | 161 | )
|
181 |
| - assert "Getting page https://pypi.gocept.com/INITools" not in result.stdout |
182 |
| - assert ( |
183 |
| - "Getting page https://pypi.org/simple/initools" in result.stdout |
| 162 | + script.pip('install', '-vvv', 'INITools', expect_error=True) |
| 163 | + script.pip( |
| 164 | + 'install', '-vvv', '--index-url', "{}/simple3".format(base_address), |
| 165 | + 'INITools', |
184 | 166 | )
|
185 | 167 |
|
| 168 | + mock_server.stop() |
| 169 | + requests = mock_server.get_requests() |
| 170 | + assert len(requests) == 4 |
| 171 | + assert requests[0]["PATH_INFO"] == "/simple1/initools/" |
| 172 | + assert requests[1]["PATH_INFO"] == "/simple2/initools/" |
| 173 | + assert requests[2]["PATH_INFO"] == "/simple3/initools/" |
| 174 | + assert requests[3]["PATH_INFO"] == "/files/INITools-0.2.tar.gz" |
| 175 | + |
186 | 176 |
|
187 | 177 | def test_options_from_venv_config(script, virtualenv):
|
188 | 178 | """
|
|
0 commit comments