Skip to content

Commit 27ec7fa

Browse files
committed
Improve utf-8 in test_config_discovery
1 parent 9e0a888 commit 27ec7fa

File tree

1 file changed

+31
-21
lines changed

1 file changed

+31
-21
lines changed

setuptools/tests/test_config_discovery.py

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,11 @@ def test_purposefully_empty(self, tmp_path, config_file, param, circumstance):
176176
else:
177177
# Make sure build works with or without setup.cfg
178178
pyproject = self.PURPOSEFULLY_EMPY["template-pyproject.toml"]
179-
(tmp_path / "pyproject.toml").write_text(pyproject)
179+
(tmp_path / "pyproject.toml").write_text(pyproject, encoding="utf-8")
180180
template_param = param
181181

182182
config = self.PURPOSEFULLY_EMPY[config_file].format(param=template_param)
183-
(tmp_path / config_file).write_text(config)
183+
(tmp_path / config_file).write_text(config, encoding="utf-8")
184184

185185
dist = _get_dist(tmp_path, {})
186186
# When either parameter package or py_modules is an empty list,
@@ -292,11 +292,13 @@ class TestWithAttrDirective:
292292
def test_setupcfg_metadata(self, tmp_path, folder, opts):
293293
files = [f"{folder}/pkg/__init__.py", "setup.cfg"]
294294
_populate_project_dir(tmp_path, files, opts)
295-
(tmp_path / folder / "pkg/__init__.py").write_text("version = 42")
296-
(tmp_path / "setup.cfg").write_text(
297-
"[metadata]\nversion = attr: pkg.version\n"
298-
+ (tmp_path / "setup.cfg").read_text()
299-
)
295+
296+
config = (tmp_path / "setup.cfg").read_text(encoding="utf-8")
297+
overwrite = {
298+
folder: {"pkg": {"__init__.py": "version = 42"}},
299+
"setup.cfg": "[metadata]\nversion = attr: pkg.version\n" + config,
300+
}
301+
jaraco.path.build(overwrite, prefix=tmp_path)
300302

301303
dist = _get_dist(tmp_path, {})
302304
assert dist.get_name() == "pkg"
@@ -312,11 +314,16 @@ def test_setupcfg_metadata(self, tmp_path, folder, opts):
312314

313315
def test_pyproject_metadata(self, tmp_path):
314316
_populate_project_dir(tmp_path, ["src/pkg/__init__.py"], {})
315-
(tmp_path / "src/pkg/__init__.py").write_text("version = 42")
316-
(tmp_path / "pyproject.toml").write_text(
317-
"[project]\nname = 'pkg'\ndynamic = ['version']\n"
318-
"[tool.setuptools.dynamic]\nversion = {attr = 'pkg.version'}\n"
319-
)
317+
318+
overwrite = {
319+
"src": {"pkg": {"__init__.py": "version = 42"}},
320+
"pyproject.toml": (
321+
"[project]\nname = 'pkg'\ndynamic = ['version']\n"
322+
"[tool.setuptools.dynamic]\nversion = {attr = 'pkg.version'}\n"
323+
),
324+
}
325+
jaraco.path.build(overwrite, prefix=tmp_path)
326+
320327
dist = _get_dist(tmp_path, {})
321328
assert dist.get_version() == "42"
322329
assert dist.package_dir == {"": "src"}
@@ -354,7 +361,7 @@ def _simulate_package_with_extension(self, tmp_path):
354361
]
355362
setup(ext_modules=ext_modules)
356363
"""
357-
(tmp_path / "setup.py").write_text(DALS(setup_script))
364+
(tmp_path / "setup.py").write_text(DALS(setup_script), encoding="utf-8")
358365

359366
def test_skip_discovery_with_setupcfg_metadata(self, tmp_path):
360367
"""Ensure that auto-discovery is not triggered when the project is based on
@@ -367,14 +374,14 @@ def test_skip_discovery_with_setupcfg_metadata(self, tmp_path):
367374
requires = []
368375
build-backend = 'setuptools.build_meta'
369376
"""
370-
(tmp_path / "pyproject.toml").write_text(DALS(pyproject))
377+
(tmp_path / "pyproject.toml").write_text(DALS(pyproject), encoding="utf-8")
371378

372379
setupcfg = """
373380
[metadata]
374381
name = proj
375382
version = 42
376383
"""
377-
(tmp_path / "setup.cfg").write_text(DALS(setupcfg))
384+
(tmp_path / "setup.cfg").write_text(DALS(setupcfg), encoding="utf-8")
378385

379386
dist = _get_dist(tmp_path, {})
380387
assert dist.get_name() == "proj"
@@ -399,7 +406,7 @@ def test_dont_skip_discovery_with_pyproject_metadata(self, tmp_path):
399406
name = 'proj'
400407
version = '42'
401408
"""
402-
(tmp_path / "pyproject.toml").write_text(DALS(pyproject))
409+
(tmp_path / "pyproject.toml").write_text(DALS(pyproject), encoding="utf-8")
403410
with pytest.raises(PackageDiscoveryError, match="multiple (packages|modules)"):
404411
_get_dist(tmp_path, {})
405412

@@ -416,7 +423,7 @@ def _simulate_package_with_data_files(self, tmp_path, src_root):
416423
manifest = """
417424
global-include *.py *.txt
418425
"""
419-
(tmp_path / "MANIFEST.in").write_text(DALS(manifest))
426+
(tmp_path / "MANIFEST.in").write_text(DALS(manifest), encoding="utf-8")
420427

421428
EXAMPLE_SETUPCFG = """
422429
[metadata]
@@ -564,9 +571,12 @@ def _populate_project_dir(root, files, options):
564571
# NOTE: Currently pypa/build will refuse to build the project if no
565572
# `pyproject.toml` or `setup.py` is found. So it is impossible to do
566573
# completely "config-less" projects.
567-
(root / "setup.py").write_text("import setuptools\nsetuptools.setup()")
568-
(root / "README.md").write_text("# Example Package")
569-
(root / "LICENSE").write_text("Copyright (c) 2018")
574+
basic = {
575+
"setup.py": "import setuptools\nsetuptools.setup()",
576+
"README.md": "# Example Package",
577+
"LICENSE": "Copyright (c) 2018",
578+
}
579+
jaraco.path.build(basic, prefix=root)
570580
_write_setupcfg(root, options)
571581
paths = (root / f for f in files)
572582
for path in paths:
@@ -594,7 +604,7 @@ def _write_setupcfg(root, options):
594604
with open(root / "setup.cfg", "w", encoding="utf-8") as f:
595605
setupcfg.write(f)
596606
print("~~~~~ setup.cfg ~~~~~")
597-
print((root / "setup.cfg").read_text())
607+
print((root / "setup.cfg").read_text(encoding="utf-8"))
598608

599609

600610
def _run_build(path, *flags):

0 commit comments

Comments
 (0)