diff --git a/tests/fixtures/inspection/demo_poetry_package/pyproject.toml b/tests/fixtures/inspection/demo_poetry_package/pyproject.toml new file mode 100644 index 00000000000..011338ea91a --- /dev/null +++ b/tests/fixtures/inspection/demo_poetry_package/pyproject.toml @@ -0,0 +1,15 @@ +[tool.poetry] +name = "demo-poetry" +version = "0.1.0" +description = "" +authors = ["John Doe "] + +[tool.poetry.dependencies] +python = "^3.10" +pendulum = "*" + +[tool.poetry.dev-dependencies] + +[build-system] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api" diff --git a/tests/inspection/test_info.py b/tests/inspection/test_info.py index c242fb90937..f9e1022ee62 100644 --- a/tests/inspection/test_info.py +++ b/tests/inspection/test_info.py @@ -131,6 +131,27 @@ def test_info_from_poetry_directory(): demo_check_info(info) +def test_info_from_poetry_directory_fallback_on_poetry_create_error( + mocker: MockerFixture, +): + import poetry.inspection.info + + mocker.patch( + "poetry.inspection.info.Factory.create_poetry", side_effect=RuntimeError + ) + mock_get_poetry_package = mocker.spy( + poetry.inspection.info.PackageInfo, "_get_poetry_package" + ) + mock_get_pep517_metadata = mocker.patch( + "poetry.inspection.info.get_pep517_metadata" + ) + + PackageInfo.from_directory(FIXTURE_DIR_INSPECTIONS / "demo_poetry_package") + + assert mock_get_poetry_package.call_count == 1 + assert mock_get_pep517_metadata.call_count == 1 + + def test_info_from_requires_txt(): info = PackageInfo.from_metadata( FIXTURE_DIR_INSPECTIONS / "demo_only_requires_txt.egg-info" diff --git a/tests/installation/test_executor.py b/tests/installation/test_executor.py index c7555bbd375..c9ec997edd0 100644 --- a/tests/installation/test_executor.py +++ b/tests/installation/test_executor.py @@ -618,3 +618,56 @@ def test_executor_should_be_initialized_with_correct_workers( executor = Executor(tmp_venv, pool, config, io) assert executor._max_workers == expected_workers + + +def test_executer_fallback_on_poetry_create_error( + mocker: MockerFixture, + config: Config, + pool: Pool, + io: BufferedIO, + tmp_dir: str, + mock_file_downloads: None, + env: MockEnv, +): + mock_pip_install = mocker.patch("poetry.installation.executor.pip_install") + mock_sdist_builder = mocker.patch("poetry.core.masonry.builders.sdist.SdistBuilder") + mock_editable_builder = mocker.patch( + "poetry.masonry.builders.editable.EditableBuilder" + ) + mocker.patch("poetry.factory.Factory.create_poetry", side_effect=RuntimeError) + + config.merge({"cache-dir": tmp_dir}) + + executor = Executor(env, pool, config, io) + + directory_package = Package( + "simple-project", + "1.2.3", + source_type="directory", + source_url=Path(__file__) + .parent.parent.joinpath("fixtures/simple_project") + .resolve() + .as_posix(), + ) + + return_code = executor.execute( + [ + Install(directory_package), + ] + ) + + expected = f""" +Package operations: 1 install, 0 updates, 0 removals + + • Installing simple-project (1.2.3 {directory_package.source_url}) +""" + + expected = set(expected.splitlines()) + output = set(io.fetch_output().splitlines()) + assert output == expected + assert return_code == 0 + assert mock_sdist_builder.call_count == 0 + assert mock_editable_builder.call_count == 0 + assert mock_pip_install.call_count == 1 + assert mock_pip_install.call_args[1].get("upgrade") is True + assert mock_pip_install.call_args[1].get("editable") is False diff --git a/tests/installation/test_pip_installer.py b/tests/installation/test_pip_installer.py index 5d84fef22c9..1a732726087 100644 --- a/tests/installation/test_pip_installer.py +++ b/tests/installation/test_pip_installer.py @@ -234,3 +234,32 @@ def test_install_with_trusted_host(config: Config): assert "--trusted-host" in cmd cert_index = cmd.index("--trusted-host") assert cmd[cert_index + 1] == "foo.bar" + + +def test_install_directory_fallback_on_poetry_create_error( + mocker: MockerFixture, tmp_venv: VirtualEnv, pool: Pool +): + mocker.patch("poetry.factory.Factory.create_poetry", side_effect=RuntimeError) + mock_sdist_builder = mocker.patch("poetry.core.masonry.builders.sdist.SdistBuilder") + mock_editable_builder = mocker.patch( + "poetry.masonry.builders.editable.EditableBuilder" + ) + mock_pip_install = mocker.patch("poetry.installation.pip_installer.pip_install") + + package = Package( + "demo", + "1.0.0", + source_type="directory", + source_url=str( + Path(__file__).parent.parent / "fixtures/inspection/demo_poetry_package" + ), + ) + + installer = PipInstaller(tmp_venv, NullIO(), pool) + installer.install_directory(package) + + assert mock_sdist_builder.call_count == 0 + assert mock_editable_builder.call_count == 0 + assert mock_pip_install.call_count == 1 + assert mock_pip_install.call_args[1].get("deps") is False + assert mock_pip_install.call_args[1].get("upgrade") is True