Skip to content

Commit

Permalink
test(console/commands/init): package include (#6352)
Browse files Browse the repository at this point in the history
Add test for generating "packages" in pyproject.toml.
Originally implemented in this commit:

85f922d

Co-authored-by: Arun Babu Neelicattu <arun.neelicattu@gmail.com>
  • Loading branch information
lukany and abn committed Sep 18, 2022
1 parent 526e6a1 commit cc97101
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions tests/console/commands/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,3 +1005,54 @@ def test__validate_package_valid(name: str | None):
def test__validate_package_invalid(name: str):
with pytest.raises(ValueError):
assert InitCommand._validate_package(name)


@pytest.mark.parametrize(
"package_name, include",
(
("mypackage", None),
("my-package", "my_package"),
("my.package", "my"),
("my-awesome-package", "my_awesome_package"),
("my.awesome.package", "my"),
),
)
def test_package_include(
tester: CommandTester,
package_name: str,
include: str | None,
):
tester.execute(
inputs="\n".join(
(
package_name,
"", # Version
"", # Description
"poetry", # Author
"", # License
"^3.10", # Python
"n", # Interactive packages
"n", # Interactive dev packages
"\n", # Generate
),
),
)

if include is None:
packages = ""
else:
packages = f'packages = [{{include = "{include}"}}]\n'

expected = (
f"[tool.poetry]\n"
f'name = "{package_name.replace(".", "-")}"\n' # canonicalized
f'version = "0.1.0"\n'
f'description = ""\n'
f'authors = ["poetry"]\n'
f'readme = "README.md"\n'
f"{packages}" # This line is optional. Thus no newline here.
f"\n"
f"[tool.poetry.dependencies]\n"
f'python = "^3.10"\n'
)
assert expected in tester.io.fetch_output()

0 comments on commit cc97101

Please sign in to comment.