Skip to content

Commit

Permalink
Add test for noninteractive init
Browse files Browse the repository at this point in the history
  • Loading branch information
rotu committed Sep 17, 2020
1 parent 50f0ada commit 9c2c4ab
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion poetry/console/commands/init.py
Expand Up @@ -142,7 +142,8 @@ def handle(self):
)
python = self.ask(question)

self.line("")
if self.io.is_interactive():
self.line("")

requirements = {}

Expand Down
22 changes: 22 additions & 0 deletions tests/console/commands/test_init.py
Expand Up @@ -45,6 +45,28 @@ def test_basic_interactive(app, mocker, poetry):
assert expected in tester.io.fetch_output()


def test_noninteractive(app, mocker, poetry, repo, tmp_path):
command = app.find("init")
command._pool = poetry.pool

repo.add_package(get_package("pytest", "3.6.0"))

p = mocker.patch("poetry.utils._compat.Path.cwd")
p.return_value = tmp_path

tester = CommandTester(command)
args = "--name my-package --dependency pytest"
tester.execute(args=args, interactive=False)

expected = "Using version ^3.6.0 for pytest\n"
assert tester.io.fetch_output() == expected
assert "" == tester.io.fetch_error()

toml_content = (tmp_path / "pyproject.toml").read_text()
assert 'name = "my-package"' in toml_content
assert 'pytest = "^3.6.0"' in toml_content


def test_interactive_with_dependencies(app, repo, mocker, poetry):
repo.add_package(get_package("django-pendulum", "0.1.6-pre4"))
repo.add_package(get_package("pendulum", "2.0.0"))
Expand Down

0 comments on commit 9c2c4ab

Please sign in to comment.