Skip to content

Commit 0aac59e

Browse files
committed
Add unit tests for py-modules
1 parent fa7da9f commit 0aac59e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

setuptools/tests/config/test_apply_pyprojecttoml.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,33 @@ def test_default_patterns(self, tmp_path):
297297
assert set(dist.metadata.license_files) == {*license_files, "LICENSE.txt"}
298298

299299

300+
class TestPyModules:
301+
# https://github.com/pypa/setuptools/issues/4316
302+
303+
def dist(self, name):
304+
toml_config = f"""
305+
[project]
306+
name = "test"
307+
version = "42.0"
308+
[tool.setuptools]
309+
py-modules = [{name!r}]
310+
"""
311+
pyproject = Path("pyproject.toml")
312+
pyproject.write_text(cleandoc(toml_config), encoding="utf-8")
313+
return pyprojecttoml.apply_configuration(Distribution({}), pyproject)
314+
315+
@pytest.mark.parametrize("module", ["pip-run", "abc-d.λ-xyz-e"])
316+
def test_valid_module_name(self, tmp_path, monkeypatch, module):
317+
monkeypatch.chdir(tmp_path)
318+
assert module in self.dist(module).py_modules
319+
320+
@pytest.mark.parametrize("module", ["pip run", "-pip-run", "pip-run-stubs"])
321+
def test_invalid_module_name(self, tmp_path, monkeypatch, module):
322+
monkeypatch.chdir(tmp_path)
323+
with pytest.raises(ValueError, match="py-modules"):
324+
self.dist(module).py_modules
325+
326+
300327
class TestDeprecatedFields:
301328
def test_namespace_packages(self, tmp_path):
302329
pyproject = tmp_path / "pyproject.toml"

0 commit comments

Comments
 (0)