mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Fix EncodingWarning in test_tools. (GH-28846)
This commit is contained in:
parent
3d1ca867ed
commit
a1c3c9e824
7 changed files with 29 additions and 25 deletions
|
@ -37,9 +37,9 @@ class PindentTests(unittest.TestCase):
|
|||
self.maxDiff = None
|
||||
with os_helper.temp_dir() as directory:
|
||||
data_path = os.path.join(directory, '_test.py')
|
||||
with open(self.script) as f:
|
||||
with open(self.script, encoding='utf-8') as f:
|
||||
closed = f.read()
|
||||
with open(data_path, 'w') as f:
|
||||
with open(data_path, 'w', encoding='utf-8') as f:
|
||||
f.write(closed)
|
||||
|
||||
rc, out, err = assert_python_ok(self.script, '-d', data_path)
|
||||
|
@ -47,9 +47,9 @@ class PindentTests(unittest.TestCase):
|
|||
self.assertEqual(err, b'')
|
||||
backup = data_path + '~'
|
||||
self.assertTrue(os.path.exists(backup))
|
||||
with open(backup) as f:
|
||||
with open(backup, encoding='utf-8') as f:
|
||||
self.assertEqual(f.read(), closed)
|
||||
with open(data_path) as f:
|
||||
with open(data_path, encoding='utf-8') as f:
|
||||
clean = f.read()
|
||||
compile(clean, '_test.py', 'exec')
|
||||
self.assertEqual(self.pindent(clean, '-c'), closed)
|
||||
|
@ -58,20 +58,20 @@ class PindentTests(unittest.TestCase):
|
|||
rc, out, err = assert_python_ok(self.script, '-c', data_path)
|
||||
self.assertEqual(out, b'')
|
||||
self.assertEqual(err, b'')
|
||||
with open(backup) as f:
|
||||
with open(backup, encoding='utf-8') as f:
|
||||
self.assertEqual(f.read(), clean)
|
||||
with open(data_path) as f:
|
||||
with open(data_path, encoding='utf-8') as f:
|
||||
self.assertEqual(f.read(), closed)
|
||||
|
||||
broken = self.lstriplines(closed)
|
||||
with open(data_path, 'w') as f:
|
||||
with open(data_path, 'w', encoding='utf-8') as f:
|
||||
f.write(broken)
|
||||
rc, out, err = assert_python_ok(self.script, '-r', data_path)
|
||||
self.assertEqual(out, b'')
|
||||
self.assertEqual(err, b'')
|
||||
with open(backup) as f:
|
||||
with open(backup, encoding='utf-8') as f:
|
||||
self.assertEqual(f.read(), broken)
|
||||
with open(data_path) as f:
|
||||
with open(data_path, encoding='utf-8') as f:
|
||||
indented = f.read()
|
||||
compile(indented, '_test.py', 'exec')
|
||||
self.assertEqual(self.pindent(broken, '-r'), indented)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue