bpo-43651: PEP 597: Fix EncodingWarning in some tests (GH-25189)
* Fix _sitebuiltins
* Fix test_inspect
* Fix test_interpreters
* Fix test_io
* Fix test_iter
* Fix test_json
* Fix test_linecache
* Fix test_lltrace
* Fix test_logging
* Fix logging
diff --git a/Lib/test/test_linecache.py b/Lib/test/test_linecache.py
index cfc6ba8..59e00da 100644
--- a/Lib/test/test_linecache.py
+++ b/Lib/test/test_linecache.py
@@ -116,7 +116,7 @@ def test_getline(self):
# Check module loading
for entry in MODULES:
filename = os.path.join(MODULE_PATH, entry) + '.py'
- with open(filename) as file:
+ with open(filename, encoding='utf-8') as file:
for index, line in enumerate(file):
self.assertEqual(line, getline(filename, index + 1))
@@ -126,7 +126,7 @@ def test_getline(self):
def test_no_ending_newline(self):
self.addCleanup(os_helper.unlink, os_helper.TESTFN)
- with open(os_helper.TESTFN, "w") as fp:
+ with open(os_helper.TESTFN, "w", encoding='utf-8') as fp:
fp.write(SOURCE_3)
lines = linecache.getlines(os_helper.TESTFN)
self.assertEqual(lines, ["\n", "def f():\n", " return 3\n"])
@@ -153,18 +153,18 @@ def test_checkcache(self):
# Create a source file and cache its contents
source_name = os_helper.TESTFN + '.py'
self.addCleanup(os_helper.unlink, source_name)
- with open(source_name, 'w') as source:
+ with open(source_name, 'w', encoding='utf-8') as source:
source.write(SOURCE_1)
getline(source_name, 1)
# Keep a copy of the old contents
source_list = []
- with open(source_name) as source:
+ with open(source_name, encoding='utf-8') as source:
for index, line in enumerate(source):
self.assertEqual(line, getline(source_name, index + 1))
source_list.append(line)
- with open(source_name, 'w') as source:
+ with open(source_name, 'w', encoding='utf-8') as source:
source.write(SOURCE_2)
# Try to update a bogus cache entry
@@ -176,7 +176,7 @@ def test_checkcache(self):
# Update the cache and check whether it matches the new source file
linecache.checkcache(source_name)
- with open(source_name) as source:
+ with open(source_name, encoding='utf-8') as source:
for index, line in enumerate(source):
self.assertEqual(line, getline(source_name, index + 1))
source_list.append(line)