8000 bpo-43651: PEP 597: Fix EncodingWarning in some tests by methane · Pull Request #25189 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-43651: PEP 597: Fix EncodingWarning in some tests #25189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Apr 6, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
8000
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix test_linecache
  • Loading branch information
methane committed Apr 5, 2021
commit af0a0bd2636a620b81f17101e8a8047c1f41e792
12 changes: 6 additions & 6 deletions Lib/test/test_linecache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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"])
Expand All @@ -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
Expand All @@ -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)
Expand Down
0