Skip to content

Commit e1cd88c

Browse files
committed
Rework test_pyprojecttoml.create_example
1 parent f51351e commit e1cd88c

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

setuptools/tests/config/test_pyprojecttoml.py

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pytest
66
import tomli_w
77
from path import Path
8+
from jaraco.path import build as path_build
89

910
from setuptools.config.pyprojecttoml import (
1011
read_configuration,
@@ -82,25 +83,32 @@
8283

8384

8485
def create_example(path, pkg_root):
85-
pyproject = path / "pyproject.toml"
86+
files = {
87+
"pyproject.toml": EXAMPLE,
88+
"README.md": "hello world",
89+
"_files": {
90+
"file.txt": "",
91+
},
92+
}
93+
packages = {
94+
"pkg": {
95+
"__init__.py": "",
96+
"mod.py": "class CustomSdist: pass",
97+
"__version__.py": "VERSION = (3, 10)",
98+
"__main__.py": "def exec(): print('hello')",
99+
},
100+
}
101+
102+
assert pkg_root # Meta-test: cannot be empty string.
86103

87-
files = [
88-
f"{pkg_root}/pkg/__init__.py",
89-
"_files/file.txt",
90-
]
91-
if pkg_root != ".": # flat-layout will raise error for multi-package dist
92-
# Ensure namespaces are discovered
93-
files.append(f"{pkg_root}/other/nested/__init__.py")
94-
95-
for file in files:
96-
(path / file).parent.mkdir(exist_ok=True, parents=True)
97-
(path / file).touch()
98-
99-
pyproject.write_text(EXAMPLE)
100-
(path / "README.md").write_text("hello world")
101-
(path / f"{pkg_root}/pkg/mod.py").write_text("class CustomSdist: pass")
102-
(path / f"{pkg_root}/pkg/__version__.py").write_text("VERSION = (3, 10)")
103-
(path / f"{pkg_root}/pkg/__main__.py").write_text("def exec(): print('hello')")
104+
if pkg_root == ".":
105+
files = {**files, **packages}
106+
# skip other files: flat-layout will raise error for multi-package dist
107+
else:
108+
# Use this opportunity to ensure namespaces are discovered
109+
files[pkg_root] = {**packages, "other": {"nested": {"__init__.py": ""}}}
110+
111+
path_build(files, prefix=path)
104112

105113

106114
def verify_example(config, path, pkg_root):

0 commit comments

Comments
 (0)