Commit c3212bef by Arun Babu Neelicattu Committed by finswimmer

tests: improve init command test setup

This change ensures that we create closer to reality scenarios when
testing init command.

Relates-to: #3073
parent ae6f574b
import os
import shutil
import sys import sys
import pytest import pytest
from cleo import CommandTester
from poetry.repositories import Pool
from poetry.utils._compat import Path from poetry.utils._compat import Path
from poetry.utils._compat import decode from poetry.utils._compat import decode
from tests.helpers import TestApplication
from tests.helpers import get_package from tests.helpers import get_package
@pytest.fixture @pytest.fixture
def source_dir(tmp_path): # type: (Path) -> Path def source_dir(tmp_path): # type: (...) -> Path
yield Path(tmp_path.as_posix()) cwd = os.getcwd()
try:
os.chdir(str(tmp_path))
yield Path(tmp_path.as_posix())
finally:
os.chdir(cwd)
@pytest.fixture(autouse=True)
def patches(mocker, source_dir): @pytest.fixture
patch = mocker.patch("poetry.utils._compat.Path.cwd") def patches(mocker, source_dir, repo):
patch.return_value = source_dir mocker.patch("poetry.utils._compat.Path.cwd", return_value=source_dir)
mocker.patch(
"poetry.console.commands.init.InitCommand._get_pool", return_value=Pool([repo])
)
@pytest.fixture @pytest.fixture
def tester(command_tester_factory): def tester(patches):
return command_tester_factory("init") # we need a test application without poetry here.
app = TestApplication(None)
return CommandTester(app.find("init"))
@pytest.fixture @pytest.fixture
...@@ -265,10 +281,13 @@ pytest = "^3.6.0" ...@@ -265,10 +281,13 @@ pytest = "^3.6.0"
assert expected in tester.io.fetch_output() assert expected in tester.io.fetch_output()
def test_interactive_with_directory_dependency(tester, repo): def test_interactive_with_directory_dependency(tester, repo, source_dir, fixture_dir):
repo.add_package(get_package("pendulum", "2.0.0")) repo.add_package(get_package("pendulum", "2.0.0"))
repo.add_package(get_package("pytest", "3.6.0")) repo.add_package(get_package("pytest", "3.6.0"))
demo = fixture_dir("git") / "github.com" / "demo" / "demo"
shutil.copytree(str(demo), str(source_dir / "demo"))
inputs = [ inputs = [
"my-package", # Package name "my-package", # Package name
"1.2.3", # Version "1.2.3", # Version
...@@ -277,7 +296,7 @@ def test_interactive_with_directory_dependency(tester, repo): ...@@ -277,7 +296,7 @@ def test_interactive_with_directory_dependency(tester, repo):
"MIT", # License "MIT", # License
"~2.7 || ^3.6", # Python "~2.7 || ^3.6", # Python
"", # Interactive packages "", # Interactive packages
"../../fixtures/git/github.com/demo/demo", # Search for package "./demo", # Search for package
"", # Stop searching for packages "", # Stop searching for packages
"", # Interactive dev packages "", # Interactive dev packages
"pytest", # Search for package "pytest", # Search for package
...@@ -298,19 +317,23 @@ license = "MIT" ...@@ -298,19 +317,23 @@ license = "MIT"
[tool.poetry.dependencies] [tool.poetry.dependencies]
python = "~2.7 || ^3.6" python = "~2.7 || ^3.6"
demo = {path = "../../fixtures/git/github.com/demo/demo"} demo = {path = "demo"}
[tool.poetry.dev-dependencies] [tool.poetry.dev-dependencies]
pytest = "^3.6.0" pytest = "^3.6.0"
""" """
assert expected in tester.io.fetch_output() assert expected in tester.io.fetch_output()
def test_interactive_with_directory_dependency_and_other_name(tester, repo): def test_interactive_with_directory_dependency_and_other_name(
tester, repo, source_dir, fixture_dir
):
repo.add_package(get_package("pendulum", "2.0.0")) repo.add_package(get_package("pendulum", "2.0.0"))
repo.add_package(get_package("pytest", "3.6.0")) repo.add_package(get_package("pytest", "3.6.0"))
demo = fixture_dir("git") / "github.com" / "demo" / "pyproject-demo"
shutil.copytree(str(demo), str(source_dir / "pyproject-demo"))
inputs = [ inputs = [
"my-package", # Package name "my-package", # Package name
"1.2.3", # Version "1.2.3", # Version
...@@ -319,7 +342,7 @@ def test_interactive_with_directory_dependency_and_other_name(tester, repo): ...@@ -319,7 +342,7 @@ def test_interactive_with_directory_dependency_and_other_name(tester, repo):
"MIT", # License "MIT", # License
"~2.7 || ^3.6", # Python "~2.7 || ^3.6", # Python
"", # Interactive packages "", # Interactive packages
"../../fixtures/git/github.com/demo/pyproject-demo", # Search for package "./pyproject-demo", # Search for package
"", # Stop searching for packages "", # Stop searching for packages
"", # Interactive dev packages "", # Interactive dev packages
"pytest", # Search for package "pytest", # Search for package
...@@ -340,7 +363,7 @@ license = "MIT" ...@@ -340,7 +363,7 @@ license = "MIT"
[tool.poetry.dependencies] [tool.poetry.dependencies]
python = "~2.7 || ^3.6" python = "~2.7 || ^3.6"
demo = {path = "../../fixtures/git/github.com/demo/pyproject-demo"} demo = {path = "pyproject-demo"}
[tool.poetry.dev-dependencies] [tool.poetry.dev-dependencies]
pytest = "^3.6.0" pytest = "^3.6.0"
...@@ -349,10 +372,13 @@ pytest = "^3.6.0" ...@@ -349,10 +372,13 @@ pytest = "^3.6.0"
assert expected in tester.io.fetch_output() assert expected in tester.io.fetch_output()
def test_interactive_with_file_dependency(tester, repo): def test_interactive_with_file_dependency(tester, repo, source_dir, fixture_dir):
repo.add_package(get_package("pendulum", "2.0.0")) repo.add_package(get_package("pendulum", "2.0.0"))
repo.add_package(get_package("pytest", "3.6.0")) repo.add_package(get_package("pytest", "3.6.0"))
demo = fixture_dir("distributions") / "demo-0.1.0-py2.py3-none-any.whl"
shutil.copyfile(str(demo), str(source_dir / demo.name))
inputs = [ inputs = [
"my-package", # Package name "my-package", # Package name
"1.2.3", # Version "1.2.3", # Version
...@@ -361,7 +387,7 @@ def test_interactive_with_file_dependency(tester, repo): ...@@ -361,7 +387,7 @@ def test_interactive_with_file_dependency(tester, repo):
"MIT", # License "MIT", # License
"~2.7 || ^3.6", # Python "~2.7 || ^3.6", # Python
"", # Interactive packages "", # Interactive packages
"../../fixtures/distributions/demo-0.1.0-py2.py3-none-any.whl", # Search for package "./demo-0.1.0-py2.py3-none-any.whl", # Search for package
"", # Stop searching for packages "", # Stop searching for packages
"", # Interactive dev packages "", # Interactive dev packages
"pytest", # Search for package "pytest", # Search for package
...@@ -382,7 +408,7 @@ license = "MIT" ...@@ -382,7 +408,7 @@ license = "MIT"
[tool.poetry.dependencies] [tool.poetry.dependencies]
python = "~2.7 || ^3.6" python = "~2.7 || ^3.6"
demo = {path = "../../fixtures/distributions/demo-0.1.0-py2.py3-none-any.whl"} demo = {path = "demo-0.1.0-py2.py3-none-any.whl"}
[tool.poetry.dev-dependencies] [tool.poetry.dev-dependencies]
pytest = "^3.6.0" pytest = "^3.6.0"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment