Skip to content

Commit 3caea9a

Browse files
methanened-deily
andauthored
bpo-43651: PEP 597: Fix EncodingWarning in some tests (GH-25171)
* Fix test_float * Fix _osx_support * Fix test_fstring * Fix test_gc * Fix test_gzip * Fix test_hashlib * Fix unrelated whitespace issue Co-authored-by: Ned Deily <[email protected]>
1 parent f8775e4 commit 3caea9a

File tree

6 files changed

+14
-14
lines changed

6 files changed

+14
-14
lines changed

Lib/_osx_support.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def _get_system_version():
9696
if _SYSTEM_VERSION is None:
9797
_SYSTEM_VERSION = ''
9898
try:
99-
f = open('/System/Library/CoreServices/SystemVersion.plist')
99+
f = open('/System/Library/CoreServices/SystemVersion.plist', encoding="utf-8")
100100
except OSError:
101101
# We're on a plain darwin box, fall back to the default
102102
# behaviour.
@@ -156,9 +156,9 @@ def _default_sysroot(cc):
156156

157157
if _cache_default_sysroot is not None:
158158
return _cache_default_sysroot
159-
159+
160160
contents = _read_output('%s -c -E -v - </dev/null' % (cc,), True)
161-
in_incdirs = False
161+
in_incdirs = False
162162
for line in contents.splitlines():
163163
if line.startswith("#include <...>"):
164164
in_incdirs = True

Lib/test/test_float.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ def test_format(self):
729729

730730
@support.requires_IEEE_754
731731
def test_format_testfile(self):
732-
with open(format_testfile) as testfile:
732+
with open(format_testfile, encoding="utf-8") as testfile:
733733
for line in testfile:
734734
if line.startswith('--'):
735735
continue
@@ -769,7 +769,7 @@ def test_issue35560(self):
769769
class ReprTestCase(unittest.TestCase):
770770
def test_repr(self):
771771
with open(os.path.join(os.path.split(__file__)[0],
772-
'floating_points.txt')) as floats_file:
772+
'floating_points.txt'), encoding="utf-8") as floats_file:
773773
for line in floats_file:
774774
line = line.strip()
775775
if not line or line.startswith('#'):

Lib/test/test_fstring.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ def test_filename_in_syntaxerror(self):
11101110
# see issue 38964
11111111
with temp_cwd() as cwd:
11121112
file_path = os.path.join(cwd, 't.py')
1113-
with open(file_path, 'w') as f:
1113+
with open(file_path, 'w', encoding="utf-8") as f:
11141114
f.write('f"{a b}"') # This generates a SyntaxError
11151115
_, _, stderr = assert_python_failure(file_path,
11161116
PYTHONIOENCODING='ascii')

Lib/test/test_gc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ def __del__(self):
750750
a.link = a
751751
raise SystemExit(0)"""
752752
self.addCleanup(unlink, TESTFN)
753-
with open(TESTFN, 'w') as script:
753+
with open(TESTFN, 'w', encoding="utf-8") as script:
754754
script.write(code)
755755
rc, out, err = assert_python_ok(TESTFN)
756756
self.assertEqual(out.strip(), b'__del__ called')

Lib/test/test_gzip.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -660,14 +660,14 @@ def test_implicit_binary_modes(self):
660660
def test_text_modes(self):
661661
uncompressed = data1.decode("ascii") * 50
662662
uncompressed_raw = uncompressed.replace("\n", os.linesep)
663-
with gzip.open(self.filename, "wt") as f:
663+
with gzip.open(self.filename, "wt", encoding="ascii") as f:
664664
f.write(uncompressed)
665665
with open(self.filename, "rb") as f:
666666
file_data = gzip.decompress(f.read()).decode("ascii")
667667
self.assertEqual(file_data, uncompressed_raw)
668-
with gzip.open(self.filename, "rt") as f:
668+
with gzip.open(self.filename, "rt", encoding="ascii") as f:
669669
self.assertEqual(f.read(), uncompressed)
670-
with gzip.open(self.filename, "at") as f:
670+
with gzip.open(self.filename, "at", encoding="ascii") as f:
671671
f.write(uncompressed)
672672
with open(self.filename, "rb") as f:
673673
file_data = gzip.decompress(f.read()).decode("ascii")
@@ -681,7 +681,7 @@ def test_fileobj(self):
681681
self.assertEqual(f.read(), uncompressed_bytes)
682682
with gzip.open(io.BytesIO(compressed), "rb") as f:
683683
self.assertEqual(f.read(), uncompressed_bytes)
684-
with gzip.open(io.BytesIO(compressed), "rt") as f:
684+
with gzip.open(io.BytesIO(compressed), "rt", encoding="ascii") as f:
685685
self.assertEqual(f.read(), uncompressed_str)
686686

687687
def test_bad_params(self):
@@ -722,9 +722,9 @@ def test_encoding_error_handler(self):
722722
def test_newline(self):
723723
# Test with explicit newline (universal newline mode disabled).
724724
uncompressed = data1.decode("ascii") * 50
725-
with gzip.open(self.filename, "wt", newline="\n") as f:
725+
with gzip.open(self.filename, "wt", encoding="ascii", newline="\n") as f:
726726
f.write(uncompressed)
727-
with gzip.open(self.filename, "rt", newline="\r") as f:
727+
with gzip.open(self.filename, "rt", encoding="ascii", newline="\r") as f:
728728
self.assertEqual(f.readlines(), [uncompressed])
729729

730730

Lib/test/test_hashlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def hexstr(s):
8282
def read_vectors(hash_name):
8383
url = URL.format(hash_name)
8484
try:
85-
testdata = support.open_urlresource(url)
85+
testdata = support.open_urlresource(url, encoding="utf-8")
8686
except (OSError, HTTPException):
8787
raise unittest.SkipTest("Could not retrieve {}".format(url))
8888
with testdata:

0 commit comments

Comments
 (0)