From db0deaffeec3c2755273714297ae5b89c33b0cea Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Wed, 31 Mar 2021 17:03:48 +0900 Subject: [PATCH 1/2] bpo-43651: Fix EncodingWarning in test_file and test_file_eintr --- Lib/test/test_file.py | 2 +- Lib/test/test_file_eintr.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_file.py b/Lib/test/test_file.py index 149767591d9eb5..c0f11b31ab0e31 100644 --- a/Lib/test/test_file.py +++ b/Lib/test/test_file.py @@ -52,7 +52,7 @@ def testReadinto_text(self): # verify readinto refuses text files a = array('b', b'x'*10) self.f.close() - self.f = self.open(TESTFN, 'r') + self.f = self.open(TESTFN, 'r', encoding="ascii") if hasattr(self.f, "readinto"): self.assertRaises(TypeError, self.f.readinto, a) diff --git a/Lib/test/test_file_eintr.py b/Lib/test/test_file_eintr.py index f1efd266ffb62b..7c023f90c8721c 100644 --- a/Lib/test/test_file_eintr.py +++ b/Lib/test/test_file_eintr.py @@ -213,7 +213,7 @@ class TestTextIOSignalInterrupt(TestFileIOSignalInterrupt): def _generate_infile_setup_code(self): """Returns the infile = ... line of code to make a TextIOWrapper.""" return ('import %s as io ;' - 'infile = io.open(sys.stdin.fileno(), "rt", newline=None) ;' + 'infile = io.open(sys.stdin.fileno(), "rt", encoding="ascii", newline=None) ;' 'assert isinstance(infile, io.TextIOWrapper)' % self.modname) From 77acede29fb63446c383c94fd40473ee489e561b Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Wed, 31 Mar 2021 20:22:02 +0900 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Victor Stinner --- Lib/test/test_file.py | 2 +- Lib/test/test_file_eintr.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_file.py b/Lib/test/test_file.py index c0f11b31ab0e31..fbfba64759a1e4 100644 --- a/Lib/test/test_file.py +++ b/Lib/test/test_file.py @@ -52,7 +52,7 @@ def testReadinto_text(self): # verify readinto refuses text files a = array('b', b'x'*10) self.f.close() - self.f = self.open(TESTFN, 'r', encoding="ascii") + self.f = self.open(TESTFN, encoding="utf-8") if hasattr(self.f, "readinto"): self.assertRaises(TypeError, self.f.readinto, a) diff --git a/Lib/test/test_file_eintr.py b/Lib/test/test_file_eintr.py index 7c023f90c8721c..01408d838a83cc 100644 --- a/Lib/test/test_file_eintr.py +++ b/Lib/test/test_file_eintr.py @@ -213,7 +213,7 @@ class TestTextIOSignalInterrupt(TestFileIOSignalInterrupt): def _generate_infile_setup_code(self): """Returns the infile = ... line of code to make a TextIOWrapper.""" return ('import %s as io ;' - 'infile = io.open(sys.stdin.fileno(), "rt", encoding="ascii", newline=None) ;' + 'infile = io.open(sys.stdin.fileno(), encoding="utf-8", newline=None) ;' 'assert isinstance(infile, io.TextIOWrapper)' % self.modname)