|
1 |
| -import pytest |
| 1 | +from pathlib import Path |
| 2 | +from typing import Optional |
2 | 3 |
|
3 |
| -from cleo.testers import CommandTester |
| 4 | +import pytest |
4 | 5 |
|
5 |
| -from poetry.console import Application |
6 | 6 | from poetry.factory import Factory
|
7 | 7 | from poetry.poetry import Poetry
|
8 |
| -from poetry.utils._compat import Path # noqa |
9 | 8 |
|
10 | 9 |
|
11 | 10 | @pytest.fixture
|
12 |
| -def command(app, poetry): # type: (Application, Poetry) -> CommandTester |
13 |
| - command = app.find("new") |
14 |
| - command._pool = poetry.pool |
15 |
| - return CommandTester(command) |
| 11 | +def tester(command_tester_factory): |
| 12 | + return command_tester_factory("new") |
16 | 13 |
|
17 | 14 |
|
18 |
| -def verify_project_directory(path, package_name, package_path, include_from=None): |
| 15 | +def verify_project_directory( |
| 16 | + path: Path, package_name: str, package_path: str, include_from: Optional[str] = None |
| 17 | +) -> Poetry: |
19 | 18 | package_path = Path(package_path)
|
20 | 19 | assert path.is_dir()
|
21 | 20 |
|
@@ -47,6 +46,8 @@ def verify_project_directory(path, package_name, package_path, include_from=None
|
47 | 46 | assert len(packages) == 1
|
48 | 47 | assert packages[0] == package_include
|
49 | 48 |
|
| 49 | + return poetry |
| 50 | + |
50 | 51 |
|
51 | 52 | @pytest.mark.parametrize(
|
52 | 53 | "options,directory,package_name,package_path,include_from",
|
@@ -134,9 +135,21 @@ def verify_project_directory(path, package_name, package_path, include_from=None
|
134 | 135 | ],
|
135 | 136 | )
|
136 | 137 | def test_command_new(
|
137 |
| - options, directory, package_name, package_path, include_from, command, tmp_dir |
| 138 | + options, directory, package_name, package_path, include_from, tester, tmp_dir |
138 | 139 | ):
|
139 | 140 | path = Path(tmp_dir) / directory
|
140 | 141 | options.append(path.as_posix())
|
141 |
| - command.execute(" ".join(options)) |
| 142 | + tester.execute(" ".join(options)) |
142 | 143 | verify_project_directory(path, package_name, package_path, include_from)
|
| 144 | + |
| 145 | + |
| 146 | +@pytest.mark.parametrize("fmt", [(None,), ("md",), ("rst",)]) |
| 147 | +def test_command_new_with_readme(fmt, tester, tmp_dir): |
| 148 | + fmt = "md" |
| 149 | + package = "package" |
| 150 | + path = Path(tmp_dir) / package |
| 151 | + options = ["--readme {}".format(fmt) if fmt else "md", path.as_posix()] |
| 152 | + tester.execute(" ".join(options)) |
| 153 | + |
| 154 | + poetry = verify_project_directory(path, package, package, None) |
| 155 | + assert poetry.local_config.get("readme") == "README.{}".format(fmt or "md") |
0 commit comments