diff --git a/poetry/core/factory.py b/poetry/core/factory.py index 23e02f8f2..d248dbb74 100644 --- a/poetry/core/factory.py +++ b/poetry/core/factory.py @@ -27,7 +27,9 @@ class Factory(object): Factory class to create various elements needed by Poetry. """ - def create_poetry(self, cwd=None, with_dev=True): # type: (Optional[Path]. bool) -> Poetry + def create_poetry( + self, cwd=None, with_dev=True + ): # type: (Optional[Path]. bool) -> Poetry poetry_file = self.locate(cwd) local_config = PyProjectTOML(path=poetry_file).poetry_config diff --git a/tests/masonry/builders/fixtures/with_bad_path_dep/pyproject.toml b/tests/masonry/builders/fixtures/with_bad_path_dep/pyproject.toml new file mode 100644 index 000000000..3c7edf13a --- /dev/null +++ b/tests/masonry/builders/fixtures/with_bad_path_dep/pyproject.toml @@ -0,0 +1,9 @@ +[tool.poetry] +name = "with_bad_path_dep" +version = "1.2.3" +description = "Some description." +authors = ["Awesome Hacker "] + +[tool.poetry.dependencies] +python = "^3.6" +bogus = { path = "../only/in/dev", develop = true } diff --git a/tests/json/__init__.py b/tests/masonry/builders/fixtures/with_bad_path_dep/with_bad_path_dep/__init__.py similarity index 100% rename from tests/json/__init__.py rename to tests/masonry/builders/fixtures/with_bad_path_dep/with_bad_path_dep/__init__.py diff --git a/tests/masonry/builders/fixtures/with_bad_path_dev_dep/pyproject.toml b/tests/masonry/builders/fixtures/with_bad_path_dev_dep/pyproject.toml new file mode 100644 index 000000000..921d93af5 --- /dev/null +++ b/tests/masonry/builders/fixtures/with_bad_path_dev_dep/pyproject.toml @@ -0,0 +1,11 @@ +[tool.poetry] +name = "with_bad_path_dev_dep" +version = "1.2.3" +description = "Some description." +authors = ["Awesome Hacker "] + +[tool.poetry.dependencies] +python = "^3.6" + +[tool.poetry.dev-dependencies] +bogus = { path = "../only/in/dev", develop = true } diff --git a/tests/masonry/builders/fixtures/with_bad_path_dev_dep/with_bad_path_dev_dep/__init__.py b/tests/masonry/builders/fixtures/with_bad_path_dev_dep/with_bad_path_dev_dep/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/masonry/test_api.py b/tests/masonry/test_api.py index 9f8cfc95c..7f0eb59d4 100644 --- a/tests/masonry/test_api.py +++ b/tests/masonry/test_api.py @@ -65,6 +65,21 @@ def test_build_wheel_with_include(): ) +def test_build_wheel_with_bad_path_dev_dep_succeeds(): + with temporary_directory() as tmp_dir, cwd( + os.path.join(fixtures, "with_bad_path_dev_dep") + ): + api.build_wheel(tmp_dir) + + +def test_build_wheel_with_bad_path_dep_fails(): + with pytest.raises(ValueError) as err, temporary_directory() as tmp_dir, cwd( + os.path.join(fixtures, "with_bad_path_dep") + ): + api.build_wheel(tmp_dir) + assert "../only/in/dev" in str(err.value) + + @pytest.mark.skipif( sys.platform == "win32" and sys.version_info <= (3, 6) @@ -101,6 +116,21 @@ def test_build_sdist_with_include(): ) +def test_build_sdist_with_bad_path_dev_dep_succeeds(): + with temporary_directory() as tmp_dir, cwd( + os.path.join(fixtures, "with_bad_path_dev_dep") + ): + api.build_sdist(tmp_dir) + + +def test_build_sdist_with_bad_path_dep_fails(): + with pytest.raises(ValueError) as err, temporary_directory() as tmp_dir, cwd( + os.path.join(fixtures, "with_bad_path_dep") + ): + api.build_sdist(tmp_dir) + assert "../only/in/dev" in str(err.value) + + def test_prepare_metadata_for_build_wheel(): entry_points = """\ [console_scripts] @@ -170,3 +200,18 @@ def test_prepare_metadata_for_build_wheel(): with (dist_info / "METADATA").open(encoding="utf-8") as f: assert metadata == decode(f.read()) + + +def test_prepare_metadata_for_build_wheel_with_bad_path_dev_dep_succeeds(): + with temporary_directory() as tmp_dir, cwd( + os.path.join(fixtures, "with_bad_path_dev_dep") + ): + api.prepare_metadata_for_build_wheel(tmp_dir) + + +def test_prepare_metadata_for_build_wheel_with_bad_path_dep_succeeds(): + with pytest.raises(ValueError) as err, temporary_directory() as tmp_dir, cwd( + os.path.join(fixtures, "with_bad_path_dep") + ): + api.prepare_metadata_for_build_wheel(tmp_dir) + assert "../only/in/dev" in str(err.value) diff --git a/tests/test_factory.py b/tests/test_factory.py index 72c2d5abc..0703d9f12 100644 --- a/tests/test_factory.py +++ b/tests/test_factory.py @@ -9,7 +9,6 @@ from poetry.core.utils._compat import PY2 from poetry.core.utils._compat import Path - fixtures_dir = Path(__file__).parent / "fixtures" @@ -201,14 +200,19 @@ def test_create_poetry_fails_on_invalid_configuration(): assert expected == str(e.value) -def test_create_poetry_with_invalid_dev_dependencies(): +def test_create_poetry_omits_dev_dependencies_iff_with_dev_is_false(): + poetry = Factory().create_poetry(fixtures_dir / "sample_project", with_dev=False) + assert not any(r for r in poetry.package.dev_requires if "pytest" in str(r)) + + poetry = Factory().create_poetry(fixtures_dir / "sample_project") + assert any(r for r in poetry.package.dev_requires if "pytest" in str(r)) + + +def test_create_poetry_fails_with_invalid_dev_dependencies_iff_with_dev_is_true(): with pytest.raises(ValueError) as err: Factory().create_poetry(fixtures_dir / "project_with_invalid_dev_deps") assert "../mylib does not exist" in str(err.value) - -def test_create_poetry_skipping_dev_dependencies(): - poetry = Factory().create_poetry( + Factory().create_poetry( fixtures_dir / "project_with_invalid_dev_deps", with_dev=False ) - assert not poetry.package.dev_requires