|
16 | 16 | from poetry.puzzle.exceptions import SolverProblemError |
17 | 17 | from poetry.repositories.repository import Repository |
18 | 18 | from poetry.repositories.repository_pool import RepositoryPool |
| 19 | +from poetry.utils.env import EnvManager |
19 | 20 | from poetry.utils.env import MockEnv |
| 21 | +from poetry.utils.env import VirtualEnv |
20 | 22 |
|
21 | 23 | from poetry_plugin_bundle.bundlers.venv_bundler import VenvBundler |
22 | 24 |
|
23 | 25 |
|
24 | 26 | if TYPE_CHECKING: |
25 | 27 | from poetry.config.config import Config |
26 | 28 | from poetry.poetry import Poetry |
27 | | - from poetry.utils.env import VirtualEnv |
28 | 29 | from pytest_mock import MockerFixture |
29 | 30 |
|
30 | 31 |
|
@@ -353,3 +354,44 @@ def test_bundler_editable_deps( |
353 | 354 |
|
354 | 355 | editable_installs = list(filter(lambda package: package.develop, dep_installs)) |
355 | 356 | assert len(editable_installs) == 0 |
| 357 | + |
| 358 | + |
| 359 | +def test_bundler_should_build_a_venv_at_specified_path_if_centralized_venv_exists( |
| 360 | + io: BufferedIO, |
| 361 | + tmpdir: str, |
| 362 | + tmp_venv: VirtualEnv, |
| 363 | + poetry: Poetry, |
| 364 | + mocker: MockerFixture, |
| 365 | +) -> None: |
| 366 | + """ |
| 367 | + Test coverage for [Issue #112](https://github.com/python-poetry/poetry-plugin-bundle/issues/112), which involves |
| 368 | + a pre-existing "centralized" venv at the path specified in the Poetry configuration. |
| 369 | + The test is intended to verify that the VenvBundler will build a new venv at the specified path if a centralized |
| 370 | + venv already exists. |
| 371 | + """ |
| 372 | + mocker.patch("poetry.installation.executor.Executor._execute_operation") |
| 373 | + |
| 374 | + poetry.config.config["virtualenvs"]["in-project"] = False |
| 375 | + poetry.config.config["virtualenvs"]["path"] = tmp_venv.path |
| 376 | + |
| 377 | + env_manager = EnvManager(poetry) |
| 378 | + env_manager.activate(sys.executable) |
| 379 | + |
| 380 | + bundler_venv_path = Path(tmpdir) / "bundler" |
| 381 | + bundler = VenvBundler() |
| 382 | + bundler.set_path(bundler_venv_path) |
| 383 | + |
| 384 | + assert bundler.bundle(poetry, io) |
| 385 | + |
| 386 | + bundler_venv = VirtualEnv(bundler_venv_path) |
| 387 | + assert bundler_venv.is_sane() |
| 388 | + |
| 389 | + path = bundler_venv_path |
| 390 | + expected = f"""\ |
| 391 | + • Bundling simple-project (1.2.3) into {path} |
| 392 | + • Bundling simple-project (1.2.3) into {path}: Creating a virtual environment using Poetry-determined Python |
| 393 | + • Bundling simple-project (1.2.3) into {path}: Installing dependencies |
| 394 | + • Bundling simple-project (1.2.3) into {path}: Installing simple-project (1.2.3) |
| 395 | + • Bundled simple-project (1.2.3) into {path} |
| 396 | +""" |
| 397 | + assert expected == io.fetch_output() |
0 commit comments