mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
bpo-43651: PEP 597: Fix EncodingWarning in some tests (GH-25145)
* test_asyncio * test_bz2 * test_math * test_cmath * test_cmd_line * test_cmd_line_script * test_compile * test_contextlib * test_profile * ctypes/test/test_find * test_multiprocessing * test_configparser * test_csv * test_dbm_dumb * test_decimal * test_difflib * os.fdopen() calls io.text_encoding() to emit EncodingWarning for right place.
This commit is contained in:
parent
dc6d3e1e4c
commit
35715d1e72
19 changed files with 78 additions and 75 deletions
|
@ -714,31 +714,31 @@ boolean {0[0]} NO
|
|||
file1 = support.findfile("cfgparser.1")
|
||||
# check when we pass a mix of readable and non-readable files:
|
||||
cf = self.newconfig()
|
||||
parsed_files = cf.read([file1, "nonexistent-file"])
|
||||
parsed_files = cf.read([file1, "nonexistent-file"], encoding="utf-8")
|
||||
self.assertEqual(parsed_files, [file1])
|
||||
self.assertEqual(cf.get("Foo Bar", "foo"), "newbar")
|
||||
# check when we pass only a filename:
|
||||
cf = self.newconfig()
|
||||
parsed_files = cf.read(file1)
|
||||
parsed_files = cf.read(file1, encoding="utf-8")
|
||||
self.assertEqual(parsed_files, [file1])
|
||||
self.assertEqual(cf.get("Foo Bar", "foo"), "newbar")
|
||||
# check when we pass only a Path object:
|
||||
cf = self.newconfig()
|
||||
parsed_files = cf.read(pathlib.Path(file1))
|
||||
parsed_files = cf.read(pathlib.Path(file1), encoding="utf-8")
|
||||
self.assertEqual(parsed_files, [file1])
|
||||
self.assertEqual(cf.get("Foo Bar", "foo"), "newbar")
|
||||
# check when we passed both a filename and a Path object:
|
||||
cf = self.newconfig()
|
||||
parsed_files = cf.read([pathlib.Path(file1), file1])
|
||||
parsed_files = cf.read([pathlib.Path(file1), file1], encoding="utf-8")
|
||||
self.assertEqual(parsed_files, [file1, file1])
|
||||
self.assertEqual(cf.get("Foo Bar", "foo"), "newbar")
|
||||
# check when we pass only missing files:
|
||||
cf = self.newconfig()
|
||||
parsed_files = cf.read(["nonexistent-file"])
|
||||
parsed_files = cf.read(["nonexistent-file"], encoding="utf-8")
|
||||
self.assertEqual(parsed_files, [])
|
||||
# check when we pass no files:
|
||||
cf = self.newconfig()
|
||||
parsed_files = cf.read([])
|
||||
parsed_files = cf.read([], encoding="utf-8")
|
||||
self.assertEqual(parsed_files, [])
|
||||
|
||||
def test_read_returns_file_list_with_bytestring_path(self):
|
||||
|
@ -747,15 +747,15 @@ boolean {0[0]} NO
|
|||
file1_bytestring = support.findfile("cfgparser.1").encode()
|
||||
# check when passing an existing bytestring path
|
||||
cf = self.newconfig()
|
||||
parsed_files = cf.read(file1_bytestring)
|
||||
parsed_files = cf.read(file1_bytestring, encoding="utf-8")
|
||||
self.assertEqual(parsed_files, [file1_bytestring])
|
||||
# check when passing an non-existing bytestring path
|
||||
cf = self.newconfig()
|
||||
parsed_files = cf.read(b'nonexistent-file')
|
||||
parsed_files = cf.read(b'nonexistent-file', encoding="utf-8")
|
||||
self.assertEqual(parsed_files, [])
|
||||
# check when passing both an existing and non-existing bytestring path
|
||||
cf = self.newconfig()
|
||||
parsed_files = cf.read([file1_bytestring, b'nonexistent-file'])
|
||||
parsed_files = cf.read([file1_bytestring, b'nonexistent-file'], encoding="utf-8")
|
||||
self.assertEqual(parsed_files, [file1_bytestring])
|
||||
|
||||
# shared by subclasses
|
||||
|
@ -1064,7 +1064,7 @@ class MultilineValuesTestCase(BasicTestCase, unittest.TestCase):
|
|||
cf.add_section(s)
|
||||
for j in range(10):
|
||||
cf.set(s, 'lovely_spam{}'.format(j), self.wonderful_spam)
|
||||
with open(os_helper.TESTFN, 'w') as f:
|
||||
with open(os_helper.TESTFN, 'w', encoding="utf-8") as f:
|
||||
cf.write(f)
|
||||
|
||||
def tearDown(self):
|
||||
|
@ -1074,7 +1074,7 @@ class MultilineValuesTestCase(BasicTestCase, unittest.TestCase):
|
|||
# We're reading from file because this is where the code changed
|
||||
# during performance updates in Python 3.2
|
||||
cf_from_file = self.newconfig()
|
||||
with open(os_helper.TESTFN) as f:
|
||||
with open(os_helper.TESTFN, encoding="utf-8") as f:
|
||||
cf_from_file.read_file(f)
|
||||
self.assertEqual(cf_from_file.get('section8', 'lovely_spam4'),
|
||||
self.wonderful_spam.replace('\t\n', '\n'))
|
||||
|
@ -1473,7 +1473,7 @@ class CopyTestCase(BasicTestCase, unittest.TestCase):
|
|||
class FakeFile:
|
||||
def __init__(self):
|
||||
file_path = support.findfile("cfgparser.1")
|
||||
with open(file_path) as f:
|
||||
with open(file_path, encoding="utf-8") as f:
|
||||
self.lines = f.readlines()
|
||||
self.lines.reverse()
|
||||
|
||||
|
@ -1500,7 +1500,7 @@ class ReadFileTestCase(unittest.TestCase):
|
|||
pass # unfortunately we can't test bytes on this path
|
||||
for file_path in file_paths:
|
||||
parser = configparser.ConfigParser()
|
||||
with open(file_path) as f:
|
||||
with open(file_path, encoding="utf-8") as f:
|
||||
parser.read_file(f)
|
||||
self.assertIn("Foo Bar", parser)
|
||||
self.assertIn("foo", parser["Foo Bar"])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue