Skip to content

Commit

Permalink
command/new: add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
abn committed Aug 4, 2020
1 parent 1599b8e commit 22df8d0
Showing 1 changed file with 126 additions and 0 deletions.
126 changes: 126 additions & 0 deletions tests/console/commands/test_new.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import pytest

from cleo.testers import CommandTester

from poetry.console import Application
from poetry.factory import Factory
from poetry.poetry import Poetry
from poetry.utils._compat import Path # noqa


@pytest.fixture
def command(app, poetry): # type: (Application, Poetry) -> CommandTester
command = app.find("new")
command._pool = poetry.pool
return CommandTester(command)


def verify_project_directory(path, package_name, package_path, include_from=None):
package_path = Path(package_path)
assert path.is_dir()

pyproject = path / "pyproject.toml"
assert pyproject.is_file()

init_file = path / package_path / "__init__.py"
assert init_file.is_file()

tests_init_file = path / "tests" / "__init__.py"
assert tests_init_file.is_file()

poetry = Factory().create_poetry(cwd=path)
assert poetry.package.name == package_name

if include_from:
package_include = {
"include": package_path.relative_to(include_from).parts[0],
"from": include_from,
}
else:
package_include = {"include": package_path.parts[0]}

packages = poetry.local_config.get("packages")
assert len(packages) == 1
assert packages[0] == package_include


@pytest.mark.parametrize(
"options,directory,package_name,package_path,include_from",
[
([], "package", "package", "package", None),
(["--src"], "package", "package", "src/package", "src"),
([], "namespace-package", "namespace-package", "namespace/package", None),
(
["--src"],
"namespace-package",
"namespace-package",
"src/namespace/package",
"src",
),
([], "namespace-package_a", "namespace-package-a", "namespace/package_a", None),
(
["--src"],
"namespace-package_a",
"namespace-package-a",
"src/namespace/package_a",
"src",
),
(
["--name namespace_package"],
"namespace-package",
"namespace-package",
"namespace_package",
None,
),
(
["--name namespace_package --src"],
"namespace-package",
"namespace-package",
"src/namespace_package",
"src",
),
(
["--name namespace.package"],
"package",
"namespace-package",
"namespace/package",
None,
),
(
["--name namespace.package --src"],
"package",
"namespace-package",
"src/namespace/package",
"src",
),
(
["--name namespace-package"],
"package",
"namespace-package",
"namespace/package",
None,
),
(
["--name namespace-package --src"],
"package",
"namespace-package",
"src/namespace/package",
"src",
),
([], "namespace_package", "namespace-package", "namespace_package", None),
(
["--src"],
"namespace_package",
"namespace-package",
"src/namespace_package",
"src",
),
],
)
def test_command_new(
options, directory, package_name, package_path, include_from, command, tmp_dir
):
path = Path(tmp_dir) / directory
options.append(path.as_posix())
command.execute(" ".join(options))
verify_project_directory(path, package_name, package_path, include_from)

0 comments on commit 22df8d0

Please sign in to comment.