Skip to content

Commit 164b093

Browse files
committed
tests: add stubbed mock dists and improve mocking
1 parent 8235b0e commit 164b093

File tree

94 files changed

+182
-304
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+182
-304
lines changed

tests/conftest.py

+2
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ def legacy_repository(
630630
mock_files_python_hosted_factory(
631631
[
632632
FIXTURE_PATH_REPOSITORIES_PYPI / "dists",
633+
FIXTURE_PATH_REPOSITORIES_PYPI / "stubbed",
633634
FIXTURE_PATH_DISTRIBUTIONS,
634635
],
635636
FIXTURE_PATH_REPOSITORIES / "metadata",
@@ -714,6 +715,7 @@ def pypi_repository(
714715
mock_files_python_hosted_factory(
715716
[
716717
FIXTURE_PATH_REPOSITORIES_PYPI / "dists",
718+
FIXTURE_PATH_REPOSITORIES_PYPI / "stubbed",
717719
FIXTURE_PATH_DISTRIBUTIONS,
718720
],
719721
FIXTURE_PATH_REPOSITORIES / "metadata",

tests/installation/conftest.py

-45
Original file line numberDiff line numberDiff line change
@@ -1,45 +0,0 @@
1-
from __future__ import annotations
2-
3-
import re
4-
5-
from pathlib import Path
6-
from typing import TYPE_CHECKING
7-
from typing import Any
8-
from urllib.parse import urlparse
9-
10-
import pytest
11-
12-
13-
if TYPE_CHECKING:
14-
from httpretty import httpretty
15-
from httpretty.core import HTTPrettyRequest
16-
17-
from tests.types import FixtureDirGetter
18-
19-
20-
@pytest.fixture
21-
def mock_file_downloads(http: type[httpretty], fixture_dir: FixtureDirGetter) -> None:
22-
def callback(
23-
request: HTTPrettyRequest, uri: str, headers: dict[str, Any]
24-
) -> list[int | dict[str, Any] | bytes]:
25-
name = Path(urlparse(uri).path).name
26-
27-
fixture = Path(__file__).parent.parent.joinpath(
28-
"repositories/fixtures/pypi.org/dists/" + name
29-
)
30-
31-
if not fixture.exists():
32-
fixture = fixture_dir("distributions") / name
33-
34-
if not fixture.exists():
35-
fixture = (
36-
fixture_dir("distributions") / "demo-0.1.0-py2.py3-none-any.whl"
37-
)
38-
39-
return [200, headers, fixture.read_bytes()]
40-
41-
http.register_uri(
42-
http.GET,
43-
re.compile("^https://files.pythonhosted.org/.*$"),
44-
body=callback,
45-
)

tests/installation/fixtures/old-lock.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ py = [
103103
{file = "py-1.5.3.tar.gz", hash = "sha256:29c9fab495d7528e80ba1e343b958684f4ace687327e6f789a94bf3d1915f881"},
104104
]
105105
pytest = [
106-
{file = "pytest-3.5.0-py2.py3-none-any.whl", hash = "sha256:6266f87ab64692112e5477eba395cfedda53b1933ccd29478e671e73b420c19c"},
106+
{file = "pytest-3.5.0-py2.py3-none-any.whl", hash = "sha256:28e4d9c2ae3196d74805c2eba24f350ae4c791a5b9b397c79b41506a48dc64ca"},
107107
{file = "pytest-3.5.0.tar.gz", hash = "sha256:fae491d1874f199537fd5872b5e1f0e74a009b979df9d53d1553fd03da1703e1"},
108108
]
109109
six = [

tests/installation/fixtures/with-pypi-repository.test

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This file is automatically @generated by Poetry 1.5.0.dev0 and should not be changed by hand.
1+
# This file is automatically @generated by Poetry 1.9.0.dev0 and should not be changed by hand.
22

33
[[package]]
44
name = "attrs"
@@ -7,8 +7,8 @@ description = "Classes Without Boilerplate"
77
optional = false
88
python-versions = "*"
99
files = [
10-
{file = "attrs-17.4.0-py2.py3-none-any.whl", hash = "sha256:a17a9573a6f475c99b551c0e0a812707ddda1ec9653bed04c13841404ed6f450"},
11-
{file = "attrs-17.4.0.tar.gz", hash = "sha256:1c7960ccfd6a005cd9f7ba884e6316b5e430a3f1a6c37c5f87d8b43f83b54ec9"},
10+
{file = "attrs-17.4.0-py2.py3-none-any.whl", hash = "sha256:d38e57f381e891928357c68e300d28d3d4dcddc50486d5f8dfaf743d40477619"},
11+
{file = "attrs-17.4.0.tar.gz", hash = "sha256:a8727b9fe35f8938cbb51a5ce3b219a21e119f31593a530db429c2c37ebaa8c6"},
1212
]
1313

1414
[package.extras]
@@ -23,8 +23,8 @@ description = "Cross-platform colored terminal text."
2323
optional = false
2424
python-versions = "*"
2525
files = [
26-
{file = "colorama-0.3.9-py2.py3-none-any.whl", hash = "sha256:463f8483208e921368c9f306094eb6f725c6ca42b0f97e313cb5d5512459feda"},
27-
{file = "colorama-0.3.9.tar.gz", hash = "sha256:48eb22f4f8461b1df5734a074b57042430fb06e1d61bd1e11b078c0fe6d7a1f1"},
26+
{file = "colorama-0.3.9-py2.py3-none-any.whl", hash = "sha256:5b632359f1ed2b7676a869812ba0edaacb99be04679b29eb56c07a5e137ab5a2"},
27+
{file = "colorama-0.3.9.tar.gz", hash = "sha256:0a7cdc22e8579dae1cb9d5f5e65b9eb538fec711bf0dcb07a61b4f2701f544f0"},
2828
]
2929

3030
[[package]]
@@ -34,9 +34,9 @@ description = "More routines for operating on iterables, beyond itertools"
3434
optional = false
3535
python-versions = "*"
3636
files = [
37-
{file = "more-itertools-4.1.0.tar.gz", hash = "sha256:c9ce7eccdcb901a2c75d326ea134e0886abfbea5f93e91cc95de9507c0816c44"},
38-
{file = "more_itertools-4.1.0-py2-none-any.whl", hash = "sha256:11a625025954c20145b37ff6309cd54e39ca94f72f6bb9576d1195db6fa2442e"},
39-
{file = "more_itertools-4.1.0-py3-none-any.whl", hash = "sha256:0dd8f72eeab0d2c3bd489025bb2f6a1b8342f9b198f6fc37b52d15cfa4531fea"},
37+
{file = "more-itertools-4.1.0.tar.gz", hash = "sha256:ba5dd3cc0a0d2c036497bbaefe6a8130d9c8b4ac0563e3df5dfdabb8044981c6"},
38+
{file = "more_itertools-4.1.0-py2-none-any.whl", hash = "sha256:5dd7dfd88d2fdaea446da478ffef8d7151fdf26ee92ac7ed7b14e8d71efe4b62"},
39+
{file = "more_itertools-4.1.0-py3-none-any.whl", hash = "sha256:29b1e1661aaa56875ce090fa219fa84dfc13daecb52cd4fae321f6f57b419ec4"},
4040
]
4141

4242
[package.dependencies]
@@ -49,7 +49,7 @@ description = "plugin and hook calling mechanisms for python"
4949
optional = false
5050
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
5151
files = [
52-
{file = "pluggy-0.6.0.tar.gz", hash = "sha256:7f8ae7f5bdf75671a718d2daf0a64b7885f74510bcd98b1a0bb420eb9a9d0cff"},
52+
{file = "pluggy-0.6.0.tar.gz", hash = "sha256:c764684334fefd2390e89d15a9f37f8f8ca6ae0535c93954b26fbf6dace56808"},
5353
]
5454

5555
[[package]]
@@ -59,8 +59,8 @@ description = "library with cross-python path, ini-parsing, io, code, log facili
5959
optional = false
6060
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
6161
files = [
62-
{file = "py-1.5.3-py2.py3-none-any.whl", hash = "sha256:983f77f3331356039fdd792e9220b7b8ee1aa6bd2b25f567a963ff1de5a64f6a"},
63-
{file = "py-1.5.3.tar.gz", hash = "sha256:29c9fab495d7528e80ba1e343b958684f4ace687327e6f789a94bf3d1915f881"},
62+
{file = "py-1.5.3-py2.py3-none-any.whl", hash = "sha256:43ee6c7f95e0ec6a906de49906b79d138d89728fff17109d49f086abc2fdd985"},
63+
{file = "py-1.5.3.tar.gz", hash = "sha256:fb6b107b5494ac7c13c76221002934ae27d38cee67b21131f13e4b668562005f"},
6464
]
6565

6666
[[package]]
@@ -70,8 +70,8 @@ description = "pytest: simple powerful testing with Python"
7070
optional = false
7171
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
7272
files = [
73-
{file = "pytest-3.5.0-py2.py3-none-any.whl", hash = "sha256:6266f87ab64692112e5477eba395cfedda53b1933ccd29478e671e73b420c19c"},
74-
{file = "pytest-3.5.0.tar.gz", hash = "sha256:fae491d1874f199537fd5872b5e1f0e74a009b979df9d53d1553fd03da1703e1"},
73+
{file = "pytest-3.5.0-py2.py3-none-any.whl", hash = "sha256:28e4d9c2ae3196d74805c2eba24f350ae4c791a5b9b397c79b41506a48dc64ca"},
74+
{file = "pytest-3.5.0.tar.gz", hash = "sha256:0db90e9c56935b2376a7e286f079183c756677ae565e3ca72e90fefd928229b5"},
7575
]
7676

7777
[package.dependencies]
@@ -106,8 +106,8 @@ description = "Python 2 and 3 compatibility utilities"
106106
optional = false
107107
python-versions = "*"
108108
files = [
109-
{file = "six-1.11.0-py2.py3-none-any.whl", hash = "sha256:832dc0e10feb1aa2c68dcc57dbb658f1c7e65b9b61af69048abc87a2db00a0eb"},
110-
{file = "six-1.11.0.tar.gz", hash = "sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9"},
109+
{file = "six-1.11.0-py2.py3-none-any.whl", hash = "sha256:112f5b46e6aa106db3e4e2494a03694c938f41c4c4535edbdfc816c2e0cb50f2"},
110+
{file = "six-1.11.0.tar.gz", hash = "sha256:a88c970d719b44e5297022628e578615ede4b0d040f9cff2d0695c048cd07f24"},
111111
]
112112

113113
[metadata]

tests/installation/test_chef.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ def setup(mocker: MockerFixture, pool: RepositoryPool) -> None:
5050
mocker.patch.object(Factory, "create_pool", return_value=pool)
5151

5252

53-
def test_isolated_env_install_success(
54-
pool: RepositoryPool, mock_file_downloads: None
55-
) -> None:
53+
def test_isolated_env_install_success(pool: RepositoryPool) -> None:
5654
with ephemeral_environment(Path(sys.executable)) as venv:
5755
env = IsolatedEnv(venv, pool)
5856
assert "poetry-core" not in venv.run("pip", "freeze")
@@ -92,7 +90,6 @@ def test_prepare_sdist(
9290
config_cache_dir: Path,
9391
artifact_cache: ArtifactCache,
9492
fixture_dir: FixtureDirGetter,
95-
mock_file_downloads: None,
9693
) -> None:
9794
chef = Chef(
9895
artifact_cache, EnvManager.get_system_env(), Factory.create_pool(config)
@@ -111,7 +108,6 @@ def test_prepare_directory(
111108
config_cache_dir: Path,
112109
artifact_cache: ArtifactCache,
113110
fixture_dir: FixtureDirGetter,
114-
mock_file_downloads: None,
115111
) -> None:
116112
chef = Chef(
117113
artifact_cache, EnvManager.get_system_env(), Factory.create_pool(config)
@@ -155,7 +151,6 @@ def test_prepare_directory_editable(
155151
config_cache_dir: Path,
156152
artifact_cache: ArtifactCache,
157153
fixture_dir: FixtureDirGetter,
158-
mock_file_downloads: None,
159154
) -> None:
160155
chef = Chef(
161156
artifact_cache, EnvManager.get_system_env(), Factory.create_pool(config)

tests/installation/test_executor.py

+4-22
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
from poetry.installation.operations import Uninstall
3030
from poetry.installation.operations import Update
3131
from poetry.installation.wheel_installer import WheelInstaller
32-
from poetry.repositories.pypi_repository import PyPiRepository
3332
from poetry.repositories.repository_pool import RepositoryPool
3433
from poetry.utils.cache import ArtifactCache
3534
from poetry.utils.env import MockEnv
@@ -43,6 +42,7 @@
4342

4443
from poetry.config.config import Config
4544
from poetry.installation.operations.operation import Operation
45+
from poetry.repositories.pypi_repository import PyPiRepository
4646
from poetry.utils.env import VirtualEnv
4747
from tests.types import FixtureDirGetter
4848

@@ -125,7 +125,9 @@ def io_not_decorated() -> BufferedIO:
125125
@pytest.fixture
126126
def pool(pypi_repository: PyPiRepository) -> RepositoryPool:
127127
pool = RepositoryPool()
128-
pool.add_repository(PyPiRepository(fallback=False))
128+
129+
pypi_repository._fallback = True
130+
pool.add_repository(pypi_repository)
129131

130132
return pool
131133

@@ -161,7 +163,6 @@ def test_execute_executes_a_batch_of_operations(
161163
pool: RepositoryPool,
162164
io: BufferedIO,
163165
tmp_path: Path,
164-
mock_file_downloads: None,
165166
env: MockEnv,
166167
copy_wheel: Callable[[], Path],
167168
fixture_dir: FixtureDirGetter,
@@ -274,7 +275,6 @@ def test_execute_prints_warning_for_yanked_package(
274275
pool: RepositoryPool,
275276
io: BufferedIO,
276277
tmp_path: Path,
277-
mock_file_downloads: None,
278278
env: MockEnv,
279279
operations: list[Operation],
280280
has_warning: bool,
@@ -308,7 +308,6 @@ def test_execute_prints_warning_for_invalid_wheels(
308308
pool: RepositoryPool,
309309
io: BufferedIO,
310310
tmp_path: Path,
311-
mock_file_downloads: None,
312311
env: MockEnv,
313312
) -> None:
314313
config.merge({"cache-dir": str(tmp_path)})
@@ -423,7 +422,6 @@ def test_execute_works_with_ansi_output(
423422
pool: RepositoryPool,
424423
io_decorated: BufferedIO,
425424
tmp_path: Path,
426-
mock_file_downloads: None,
427425
env: MockEnv,
428426
) -> None:
429427
config.merge({"cache-dir": str(tmp_path)})
@@ -460,7 +458,6 @@ def test_execute_works_with_no_ansi_output(
460458
pool: RepositoryPool,
461459
io_not_decorated: BufferedIO,
462460
tmp_path: Path,
463-
mock_file_downloads: None,
464461
env: MockEnv,
465462
) -> None:
466463
config.merge({"cache-dir": str(tmp_path)})
@@ -547,7 +544,6 @@ def test_executor_should_delete_incomplete_downloads(
547544
tmp_path: Path,
548545
mocker: MockerFixture,
549546
pool: RepositoryPool,
550-
mock_file_downloads: None,
551547
env: MockEnv,
552548
) -> None:
553549
cached_archive = tmp_path / "tomlkit-0.5.3-py2.py3-none-any.whl"
@@ -694,7 +690,6 @@ def test_executor_should_write_pep610_url_references_for_non_wheel_files(
694690
config: Config,
695691
io: BufferedIO,
696692
fixture_dir: FixtureDirGetter,
697-
mock_file_downloads: None,
698693
) -> None:
699694
url = (fixture_dir("distributions") / "demo-0.1.0.tar.gz").resolve()
700695
package = Package("demo", "0.1.0", source_type="file", source_url=url.as_posix())
@@ -790,7 +785,6 @@ def test_executor_should_write_pep610_url_references_for_wheel_urls(
790785
pool: RepositoryPool,
791786
config: Config,
792787
io: BufferedIO,
793-
mock_file_downloads: None,
794788
mocker: MockerFixture,
795789
fixture_dir: FixtureDirGetter,
796790
is_artifact_cached: bool,
@@ -866,7 +860,6 @@ def test_executor_should_write_pep610_url_references_for_non_wheel_urls(
866860
pool: RepositoryPool,
867861
config: Config,
868862
io: BufferedIO,
869-
mock_file_downloads: None,
870863
mocker: MockerFixture,
871864
fixture_dir: FixtureDirGetter,
872865
is_sdist_cached: bool,
@@ -953,7 +946,6 @@ def test_executor_should_write_pep610_url_references_for_git(
953946
config: Config,
954947
artifact_cache: ArtifactCache,
955948
io: BufferedIO,
956-
mock_file_downloads: None,
957949
wheel: Path,
958950
mocker: MockerFixture,
959951
fixture_dir: FixtureDirGetter,
@@ -1017,7 +1009,6 @@ def test_executor_should_write_pep610_url_references_for_editable_git(
10171009
config: Config,
10181010
artifact_cache: ArtifactCache,
10191011
io: BufferedIO,
1020-
mock_file_downloads: None,
10211012
wheel: Path,
10221013
mocker: MockerFixture,
10231014
fixture_dir: FixtureDirGetter,
@@ -1066,7 +1057,6 @@ def test_executor_should_append_subdirectory_for_git(
10661057
config: Config,
10671058
artifact_cache: ArtifactCache,
10681059
io: BufferedIO,
1069-
mock_file_downloads: None,
10701060
wheel: Path,
10711061
) -> None:
10721062
package = Package(
@@ -1097,7 +1087,6 @@ def test_executor_should_write_pep610_url_references_for_git_with_subdirectories
10971087
config: Config,
10981088
artifact_cache: ArtifactCache,
10991089
io: BufferedIO,
1100-
mock_file_downloads: None,
11011090
wheel: Path,
11021091
) -> None:
11031092
package = Package(
@@ -1168,7 +1157,6 @@ def test_executor_fallback_on_poetry_create_error_without_wheel_installer(
11681157
pool: RepositoryPool,
11691158
io: BufferedIO,
11701159
tmp_path: Path,
1171-
mock_file_downloads: None,
11721160
env: MockEnv,
11731161
fixture_dir: FixtureDirGetter,
11741162
) -> None:
@@ -1244,7 +1232,6 @@ def test_build_backend_errors_are_reported_correctly_if_caused_by_subprocess(
12441232
config: Config,
12451233
pool: RepositoryPool,
12461234
io: BufferedIO,
1247-
mock_file_downloads: None,
12481235
env: MockEnv,
12491236
fixture_dir: FixtureDirGetter,
12501237
) -> None:
@@ -1313,7 +1300,6 @@ def test_build_backend_errors_are_reported_correctly_if_caused_by_subprocess_enc
13131300
config: Config,
13141301
pool: RepositoryPool,
13151302
io: BufferedIO,
1316-
mock_file_downloads: None,
13171303
env: MockEnv,
13181304
fixture_dir: FixtureDirGetter,
13191305
) -> None:
@@ -1349,7 +1335,6 @@ def test_build_system_requires_not_available(
13491335
config: Config,
13501336
pool: RepositoryPool,
13511337
io: BufferedIO,
1352-
mock_file_downloads: None,
13531338
env: MockEnv,
13541339
fixture_dir: FixtureDirGetter,
13551340
) -> None:
@@ -1395,7 +1380,6 @@ def test_build_system_requires_install_failure(
13951380
config: Config,
13961381
pool: RepositoryPool,
13971382
io: BufferedIO,
1398-
mock_file_downloads: None,
13991383
env: MockEnv,
14001384
fixture_dir: FixtureDirGetter,
14011385
) -> None:
@@ -1450,7 +1434,6 @@ def test_other_error(
14501434
config: Config,
14511435
pool: RepositoryPool,
14521436
io: BufferedIO,
1453-
mock_file_downloads: None,
14541437
env: MockEnv,
14551438
fixture_dir: FixtureDirGetter,
14561439
) -> None:
@@ -1562,7 +1545,6 @@ def test_executor_known_hashes(
15621545
config: Config,
15631546
io: BufferedIO,
15641547
fixture_dir: FixtureDirGetter,
1565-
mock_file_downloads: None,
15661548
) -> None:
15671549
# when installing sdist, an isolated build environment is required to extract metadata
15681550
# this will install any build system requirements into the environment, to avoid failures when

0 commit comments

Comments
 (0)