Commit cc971013 by Jan Lukány Committed by GitHub

test(console/commands/init): package include (#6352)

Add test for generating "packages" in pyproject.toml.
Originally implemented in this commit:

https://github.com/python-poetry/poetry/commit/85f922dfddb8d8e61408b5d8e53f3bffb6beb2b3

Co-authored-by: Arun Babu Neelicattu <arun.neelicattu@gmail.com>
parent 526e6a16
......@@ -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()
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