Skip to content

Commit

Permalink
improve and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Tso committed Oct 15, 2020
1 parent 4205229 commit 457a86b
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 7 deletions.
4 changes: 3 additions & 1 deletion poetry/core/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[tool.poetry]
name = "with_bad_path_dep"
version = "1.2.3"
description = "Some description."
authors = ["Awesome Hacker <awesome@hacker.io>"]

[tool.poetry.dependencies]
python = "^3.6"
bogus = { path = "../only/in/dev", develop = true }
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[tool.poetry]
name = "with_bad_path_dev_dep"
version = "1.2.3"
description = "Some description."
authors = ["Awesome Hacker <awesome@hacker.io>"]

[tool.poetry.dependencies]
python = "^3.6"

[tool.poetry.dev-dependencies]
bogus = { path = "../only/in/dev", develop = true }
Empty file.
45 changes: 45 additions & 0 deletions tests/masonry/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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)
16 changes: 10 additions & 6 deletions tests/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from poetry.core.utils._compat import PY2
from poetry.core.utils._compat import Path


fixtures_dir = Path(__file__).parent / "fixtures"


Expand Down Expand Up @@ -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

0 comments on commit 457a86b

Please sign in to comment.