Skip to content

Commit 5022126

Browse files
committed
Add missing encoding to setuptools tests
1 parent 9b081af commit 5022126

11 files changed

+59
-62
lines changed

setuptools/tests/config/test_pyprojecttoml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class TestEntryPoints:
174174
def write_entry_points(self, tmp_path):
175175
entry_points = ConfigParser()
176176
entry_points.read_dict(ENTRY_POINTS)
177-
with open(tmp_path / "entry-points.txt", "w") as f:
177+
with open(tmp_path / "entry-points.txt", "w", encoding="utf-8") as f:
178178
entry_points.write(f)
179179

180180
def pyproject(self, dynamic=None):

setuptools/tests/test_build_meta.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def test_build_with_existing_file_present(self, build_type, tmpdir_cwd):
296296
first_result = build_method(dist_dir)
297297

298298
# Change version.
299-
with open("VERSION", "wt") as version_file:
299+
with open("VERSION", "wt", encoding="utf-8") as version_file:
300300
version_file.write("0.0.2")
301301

302302
# Build a *second* sdist/wheel.
@@ -306,7 +306,7 @@ def test_build_with_existing_file_present(self, build_type, tmpdir_cwd):
306306
assert first_result != second_result
307307

308308
# And if rebuilding the exact same sdist/wheel?
309-
open(os.path.join(dist_dir, second_result), 'w').close()
309+
open(os.path.join(dist_dir, second_result), 'w', encoding="utf-8").close()
310310
third_result = build_method(dist_dir)
311311
assert third_result == second_result
312312
assert os.path.getsize(os.path.join(dist_dir, third_result)) > 0
@@ -568,9 +568,9 @@ def test_build_sdist_version_change(self, build_backend):
568568
if not os.path.exists(setup_loc):
569569
setup_loc = os.path.abspath("setup.cfg")
570570

571-
with open(setup_loc, 'rt') as file_handler:
571+
with open(setup_loc, 'rt', encoding="utf-8") as file_handler:
572572
content = file_handler.read()
573-
with open(setup_loc, 'wt') as file_handler:
573+
with open(setup_loc, 'wt', encoding="utf-8") as file_handler:
574574
file_handler.write(content.replace("version='0.0.0'", "version='0.0.1'"))
575575

576576
shutil.rmtree(sdist_into_directory)

setuptools/tests/test_build_py.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_recursive_in_package_data_glob(tmpdir_cwd):
4949
)
5050
)
5151
os.makedirs('path/subpath/subsubpath')
52-
open('path/subpath/subsubpath/data', 'w').close()
52+
open('path/subpath/subsubpath/data', 'w', encoding="utf-8").close()
5353

5454
dist.parse_command_line()
5555
dist.run_commands()
@@ -77,8 +77,8 @@ def test_read_only(tmpdir_cwd):
7777
)
7878
)
7979
os.makedirs('pkg')
80-
open('pkg/__init__.py', 'w').close()
81-
open('pkg/data.dat', 'w').close()
80+
open('pkg/__init__.py', 'w', encoding="utf-8").close()
81+
open('pkg/data.dat', 'w', encoding="utf-8").close()
8282
os.chmod('pkg/__init__.py', stat.S_IREAD)
8383
os.chmod('pkg/data.dat', stat.S_IREAD)
8484
dist.parse_command_line()
@@ -108,8 +108,8 @@ def test_executable_data(tmpdir_cwd):
108108
)
109109
)
110110
os.makedirs('pkg')
111-
open('pkg/__init__.py', 'w').close()
112-
open('pkg/run-me', 'w').close()
111+
open('pkg/__init__.py', 'w', encoding="utf-8").close()
112+
open('pkg/run-me', 'w', encoding="utf-8").close()
113113
os.chmod('pkg/run-me', 0o700)
114114

115115
dist.parse_command_line()

setuptools/tests/test_config_discovery.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ def _write_setupcfg(root, options):
591591
setupcfg["options"][key] = "\n" + str_value
592592
else:
593593
setupcfg["options"][key] = str(value)
594-
with open(root / "setup.cfg", "w") as f:
594+
with open(root / "setup.cfg", "w", encoding="utf-8") as f:
595595
setupcfg.write(f)
596596
print("~~~~~ setup.cfg ~~~~~")
597597
print((root / "setup.cfg").read_text())

setuptools/tests/test_easy_install.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ def distutils_package():
467467
'from distutils.core import setup',
468468
)
469469
with contexts.tempdir(cd=os.chdir):
470-
with open('setup.py', 'w') as f:
470+
with open('setup.py', 'w', encoding="utf-8") as f:
471471
f.write(distutils_setup_py)
472472
yield
473473

@@ -784,7 +784,7 @@ def test_setup_requires_honors_pip_env(self, mock_index, monkeypatch):
784784
setup_attrs=dict(dependency_links=[]),
785785
)
786786
test_setup_cfg = os.path.join(test_pkg, 'setup.cfg')
787-
with open(test_setup_cfg, 'w') as fp:
787+
with open(test_setup_cfg, 'w', encoding="utf-8") as fp:
788788
fp.write(
789789
DALS(
790790
"""
@@ -918,7 +918,7 @@ def test_setup_requires_with_find_links_in_setup_cfg(
918918
test_setup_py = os.path.join(test_pkg, 'setup.py')
919919
test_setup_cfg = os.path.join(test_pkg, 'setup.cfg')
920920
os.mkdir(test_pkg)
921-
with open(test_setup_py, 'w') as fp:
921+
with open(test_setup_py, 'w', encoding="utf-8") as fp:
922922
if with_dependency_links_in_setup_py:
923923
dependency_links = [os.path.join(temp_dir, 'links')]
924924
else:
@@ -932,7 +932,7 @@ def test_setup_requires_with_find_links_in_setup_cfg(
932932
"""
933933
).format(dependency_links=dependency_links)
934934
)
935-
with open(test_setup_cfg, 'w') as fp:
935+
with open(test_setup_cfg, 'w', encoding="utf-8") as fp:
936936
fp.write(
937937
DALS(
938938
"""
@@ -984,7 +984,7 @@ def test_setup_requires_with_transitive_extra_dependency(self, monkeypatch):
984984
test_pkg = os.path.join(temp_dir, 'test_pkg')
985985
test_setup_py = os.path.join(test_pkg, 'setup.py')
986986
os.mkdir(test_pkg)
987-
with open(test_setup_py, 'w') as fp:
987+
with open(test_setup_py, 'w', encoding="utf-8") as fp:
988988
fp.write(
989989
DALS(
990990
"""
@@ -1068,7 +1068,7 @@ class epcmd(build_py):
10681068
test_pkg = os.path.join(temp_dir, 'test_pkg')
10691069
test_setup_py = os.path.join(test_pkg, 'setup.py')
10701070
os.mkdir(test_pkg)
1071-
with open(test_setup_py, 'w') as fp:
1071+
with open(test_setup_py, 'w', encoding="utf-8") as fp:
10721072
fp.write(
10731073
DALS(
10741074
"""
@@ -1244,7 +1244,7 @@ def create_setup_requires_package(
12441244
)
12451245
else:
12461246
test_setup_cfg_contents = ''
1247-
with open(os.path.join(test_pkg, 'setup.cfg'), 'w') as f:
1247+
with open(os.path.join(test_pkg, 'setup.cfg'), 'w', encoding="utf-8") as f:
12481248
f.write(test_setup_cfg_contents)
12491249

12501250
# setup.py
@@ -1255,7 +1255,7 @@ def create_setup_requires_package(
12551255
setuptools.setup(**%r)
12561256
"""
12571257
)
1258-
with open(os.path.join(test_pkg, 'setup.py'), 'w') as f:
1258+
with open(os.path.join(test_pkg, 'setup.py'), 'w', encoding="utf-8") as f:
12591259
f.write(setup_py_template % test_setup_attrs)
12601260

12611261
foobar_path = os.path.join(path, '%s-%s.tar.gz' % (distname, version))

setuptools/tests/test_egg_info.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def test_egg_info_save_version_info_setup_empty(self, tmpdir_cwd, env):
9494
ei.initialize_options()
9595
ei.save_version_info(setup_cfg)
9696

97-
with open(setup_cfg, 'r') as f:
97+
with open(setup_cfg, 'r', encoding="utf-8") as f:
9898
content = f.read()
9999

100100
assert '[egg_info]' in content
@@ -139,7 +139,7 @@ def test_egg_info_save_version_info_setup_defaults(self, tmpdir_cwd, env):
139139
ei.initialize_options()
140140
ei.save_version_info(setup_cfg)
141141

142-
with open(setup_cfg, 'r') as f:
142+
with open(setup_cfg, 'r', encoding="utf-8") as f:
143143
content = f.read()
144144

145145
assert '[egg_info]' in content
@@ -251,7 +251,7 @@ def test_manifest_template_is_read(self, tmpdir_cwd, env):
251251
self._run_egg_info_command(tmpdir_cwd, env)
252252
egg_info_dir = os.path.join('.', 'foo.egg-info')
253253
sources_txt = os.path.join(egg_info_dir, 'SOURCES.txt')
254-
with open(sources_txt) as f:
254+
with open(sources_txt, encoding="utf-8") as f:
255255
assert 'docs/usage.rst' in f.read().split('\n')
256256

257257
def _setup_script_with_requires(self, requires, use_setup_cfg=False):
@@ -492,7 +492,7 @@ def test_requires(
492492
egg_info_dir = os.path.join('.', 'foo.egg-info')
493493
requires_txt = os.path.join(egg_info_dir, 'requires.txt')
494494
if os.path.exists(requires_txt):
495-
with open(requires_txt) as fp:
495+
with open(requires_txt, encoding="utf-8") as fp:
496496
install_requires = fp.read()
497497
else:
498498
install_requires = ''
@@ -538,7 +538,7 @@ def test_provides_extra(self, tmpdir_cwd, env):
538538
env=environ,
539539
)
540540
egg_info_dir = os.path.join('.', 'foo.egg-info')
541-
with open(os.path.join(egg_info_dir, 'PKG-INFO')) as pkginfo_file:
541+
with open(os.path.join(egg_info_dir, 'PKG-INFO'), encoding="utf-8") as pkginfo_file:
542542
pkg_info_lines = pkginfo_file.read().split('\n')
543543
assert 'Provides-Extra: foobar' in pkg_info_lines
544544
assert 'Metadata-Version: 2.1' in pkg_info_lines
@@ -557,7 +557,7 @@ def test_doesnt_provides_extra(self, tmpdir_cwd, env):
557557
env=environ,
558558
)
559559
egg_info_dir = os.path.join('.', 'foo.egg-info')
560-
with open(os.path.join(egg_info_dir, 'PKG-INFO')) as pkginfo_file:
560+
with open(os.path.join(egg_info_dir, 'PKG-INFO'), encoding="utf-8") as pkginfo_file:
561561
pkg_info_text = pkginfo_file.read()
562562
assert 'Provides-Extra:' not in pkg_info_text
563563

@@ -636,7 +636,7 @@ def test_setup_cfg_license_file(self, tmpdir_cwd, env, files, license_in_sources
636636
)
637637
egg_info_dir = os.path.join('.', 'foo.egg-info')
638638

639-
with open(os.path.join(egg_info_dir, 'SOURCES.txt')) as sources_file:
639+
with open(os.path.join(egg_info_dir, 'SOURCES.txt'), encoding="utf-8") as sources_file:
640640
sources_text = sources_file.read()
641641

642642
if license_in_sources:
@@ -849,7 +849,7 @@ def test_setup_cfg_license_files(
849849
)
850850
egg_info_dir = os.path.join('.', 'foo.egg-info')
851851

852-
with open(os.path.join(egg_info_dir, 'SOURCES.txt')) as sources_file:
852+
with open(os.path.join(egg_info_dir, 'SOURCES.txt'), encoding="utf-8") as sources_file:
853853
sources_lines = list(line.strip() for line in sources_file)
854854

855855
for lf in incl_licenses:
@@ -1033,7 +1033,7 @@ def test_setup_cfg_license_file_license_files(
10331033
)
10341034
egg_info_dir = os.path.join('.', 'foo.egg-info')
10351035

1036-
with open(os.path.join(egg_info_dir, 'SOURCES.txt')) as sources_file:
1036+
with open(os.path.join(egg_info_dir, 'SOURCES.txt'), encoding="utf-8") as sources_file:
10371037
sources_lines = list(line.strip() for line in sources_file)
10381038

10391039
for lf in incl_licenses:
@@ -1065,7 +1065,7 @@ def test_license_file_attr_pkg_info(self, tmpdir_cwd, env):
10651065
pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]),
10661066
)
10671067
egg_info_dir = os.path.join('.', 'foo.egg-info')
1068-
with open(os.path.join(egg_info_dir, 'PKG-INFO')) as pkginfo_file:
1068+
with open(os.path.join(egg_info_dir, 'PKG-INFO'), encoding="utf-8") as pkginfo_file:
10691069
pkg_info_lines = pkginfo_file.read().split('\n')
10701070
license_file_lines = [
10711071
line for line in pkg_info_lines if line.startswith('License-File:')
@@ -1086,7 +1086,7 @@ def test_metadata_version(self, tmpdir_cwd, env):
10861086
data_stream=1,
10871087
)
10881088
egg_info_dir = os.path.join('.', 'foo.egg-info')
1089-
with open(os.path.join(egg_info_dir, 'PKG-INFO')) as pkginfo_file:
1089+
with open(os.path.join(egg_info_dir, 'PKG-INFO'), encoding="utf-8") as pkginfo_file:
10901090
pkg_info_lines = pkginfo_file.read().split('\n')
10911091
# Update metadata version if changed
10921092
assert self._extract_mv_version(pkg_info_lines) == (2, 1)
@@ -1112,7 +1112,7 @@ def test_long_description_content_type(self, tmpdir_cwd, env):
11121112
env=environ,
11131113
)
11141114
egg_info_dir = os.path.join('.', 'foo.egg-info')
1115-
with open(os.path.join(egg_info_dir, 'PKG-INFO')) as pkginfo_file:
1115+
with open(os.path.join(egg_info_dir, 'PKG-INFO'), encoding="utf-8") as pkginfo_file:
11161116
pkg_info_lines = pkginfo_file.read().split('\n')
11171117
expected_line = 'Description-Content-Type: text/markdown'
11181118
assert expected_line in pkg_info_lines
@@ -1133,7 +1133,7 @@ def test_long_description(self, tmpdir_cwd, env):
11331133
data_stream=1,
11341134
)
11351135
egg_info_dir = os.path.join('.', 'foo.egg-info')
1136-
with open(os.path.join(egg_info_dir, 'PKG-INFO')) as pkginfo_file:
1136+
with open(os.path.join(egg_info_dir, 'PKG-INFO'), encoding="utf-8") as pkginfo_file:
11371137
pkg_info_lines = pkginfo_file.read().split('\n')
11381138
assert 'Metadata-Version: 2.1' in pkg_info_lines
11391139
assert '' == pkg_info_lines[-1] # last line should be empty
@@ -1165,7 +1165,7 @@ def test_project_urls(self, tmpdir_cwd, env):
11651165
env=environ,
11661166
)
11671167
egg_info_dir = os.path.join('.', 'foo.egg-info')
1168-
with open(os.path.join(egg_info_dir, 'PKG-INFO')) as pkginfo_file:
1168+
with open(os.path.join(egg_info_dir, 'PKG-INFO'), encoding="utf-8") as pkginfo_file:
11691169
pkg_info_lines = pkginfo_file.read().split('\n')
11701170
expected_line = 'Project-URL: Link One, https://example.com/one/'
11711171
assert expected_line in pkg_info_lines
@@ -1182,7 +1182,7 @@ def test_license(self, tmpdir_cwd, env):
11821182
data_stream=1,
11831183
)
11841184
egg_info_dir = os.path.join('.', 'foo.egg-info')
1185-
with open(os.path.join(egg_info_dir, 'PKG-INFO')) as pkginfo_file:
1185+
with open(os.path.join(egg_info_dir, 'PKG-INFO'), encoding="utf-8") as pkginfo_file:
11861186
pkg_info_lines = pkginfo_file.read().split('\n')
11871187
assert 'License: MIT' in pkg_info_lines
11881188

@@ -1197,7 +1197,7 @@ def test_license_escape(self, tmpdir_cwd, env):
11971197
data_stream=1,
11981198
)
11991199
egg_info_dir = os.path.join('.', 'foo.egg-info')
1200-
with open(os.path.join(egg_info_dir, 'PKG-INFO')) as pkginfo_file:
1200+
with open(os.path.join(egg_info_dir, 'PKG-INFO'), encoding="utf-8") as pkginfo_file:
12011201
pkg_info_lines = pkginfo_file.read().split('\n')
12021202

12031203
assert 'License: This is a long license text ' in pkg_info_lines
@@ -1216,7 +1216,7 @@ def test_python_requires_egg_info(self, tmpdir_cwd, env):
12161216
env=environ,
12171217
)
12181218
egg_info_dir = os.path.join('.', 'foo.egg-info')
1219-
with open(os.path.join(egg_info_dir, 'PKG-INFO')) as pkginfo_file:
1219+
with open(os.path.join(egg_info_dir, 'PKG-INFO'), encoding="utf-8") as pkginfo_file:
12201220
pkg_info_lines = pkginfo_file.read().split('\n')
12211221
assert 'Requires-Python: >=2.7.12' in pkg_info_lines
12221222
assert self._extract_mv_version(pkg_info_lines) >= (1, 2)
@@ -1240,7 +1240,7 @@ def test_egg_info_includes_setup_py(self, tmpdir_cwd):
12401240

12411241
assert 'setup.py' in egg_info_instance.filelist.files
12421242

1243-
with open(egg_info_instance.egg_info + "/SOURCES.txt") as f:
1243+
with open(egg_info_instance.egg_info + "/SOURCES.txt", encoding="utf-8") as f:
12441244
sources = f.read().split('\n')
12451245
assert 'setup.py' in sources
12461246

@@ -1277,7 +1277,7 @@ def test_egg_info_tag_only_once(self, tmpdir_cwd, env):
12771277
})
12781278
self._run_egg_info_command(tmpdir_cwd, env)
12791279
egg_info_dir = os.path.join('.', 'foo.egg-info')
1280-
with open(os.path.join(egg_info_dir, 'PKG-INFO')) as pkginfo_file:
1280+
with open(os.path.join(egg_info_dir, 'PKG-INFO'), encoding="utf-8") as pkginfo_file:
12811281
pkg_info_lines = pkginfo_file.read().split('\n')
12821282
assert 'Version: 0.0.0.dev0' in pkg_info_lines
12831283

setuptools/tests/test_find_packages.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ def _mkdir(self, path, parent_dir=None):
7272
def _touch(self, path, dir_=None):
7373
if dir_:
7474
path = os.path.join(dir_, path)
75-
fp = open(path, 'w')
76-
fp.close()
75+
open(path, 'wb').close()
7776
return path
7877

7978
def test_regular_package(self):

setuptools/tests/test_install_scripts.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def test_sys_executable_escaping_unix(self, tmpdir, monkeypatch):
4141
monkeypatch.setattr('sys.executable', self.unix_exe)
4242
with tmpdir.as_cwd():
4343
self._run_install_scripts(str(tmpdir))
44-
with open(str(tmpdir.join('foo')), 'r') as f:
44+
with open(str(tmpdir.join('foo')), 'r', encoding="utf-8") as f:
4545
actual = f.readline()
4646
assert actual == expected
4747

@@ -55,7 +55,7 @@ def test_sys_executable_escaping_win32(self, tmpdir, monkeypatch):
5555
monkeypatch.setattr('sys.executable', self.win32_exe)
5656
with tmpdir.as_cwd():
5757
self._run_install_scripts(str(tmpdir))
58-
with open(str(tmpdir.join('foo-script.py')), 'r') as f:
58+
with open(str(tmpdir.join('foo-script.py')), 'r', encoding="utf-8") as f:
5959
actual = f.readline()
6060
assert actual == expected
6161

@@ -69,7 +69,7 @@ def test_executable_with_spaces_escaping_unix(self, tmpdir):
6969
expected = '#!%s\n' % self.unix_spaces_exe
7070
with tmpdir.as_cwd():
7171
self._run_install_scripts(str(tmpdir), self.unix_spaces_exe)
72-
with open(str(tmpdir.join('foo')), 'r') as f:
72+
with open(str(tmpdir.join('foo')), 'r', encoding="utf-8") as f:
7373
actual = f.readline()
7474
assert actual == expected
7575

@@ -83,6 +83,6 @@ def test_executable_arg_escaping_win32(self, tmpdir):
8383
expected = '#!"%s"\n' % self.win32_exe
8484
with tmpdir.as_cwd():
8585
self._run_install_scripts(str(tmpdir), '"' + self.win32_exe + '"')
86-
with open(str(tmpdir.join('foo-script.py')), 'r') as f:
86+
with open(str(tmpdir.join('foo-script.py')), 'r', encoding="utf-8") as f:
8787
actual = f.readline()
8888
assert actual == expected

0 commit comments

Comments
 (0)