diff options
| author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2018-02-12 20:34:52 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-02-12 20:34:52 (GMT) |
| commit | 38b4dd7f83fbdce6fe970088cd89b80f074a13f6 (patch) | |
| tree | bbd619f8b48421600573f8da9e02f884660d6a1e | |
| parent | 0442599961f966a3dc7f3fe6a3c0d5765fcf2082 (diff) | |
| download | cpython-38b4dd7f83fbdce6fe970088cd89b80f074a13f6.zip cpython-38b4dd7f83fbdce6fe970088cd89b80f074a13f6.tar.gz cpython-38b4dd7f83fbdce6fe970088cd89b80f074a13f6.tar.bz2 | |
bpo-32826: Add "encoding=utf-8" to open() in idle_test/test_help_about. (GH-5639)
GUI test test_file_buttons() only looks at initial ascii-only lines,
but failed on systems where open() defaults to 'ascii' because
readline() internally reads and decodes far enough ahead to encounter
a non-ascii character in CREDITS.txt.
(cherry picked from commit f34e03ec0ea6a4cef8d966087c77e616c4a5893b)
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
| -rw-r--r-- | Lib/idlelib/idle_test/test_help_about.py | 52 | ||||
| -rw-r--r-- | Misc/NEWS.d/next/IDLE/2018-02-12-11-05-22.bpo-32826.IxNZrk.rst | 5 |
2 files changed, 32 insertions, 25 deletions
diff --git a/Lib/idlelib/idle_test/test_help_about.py b/Lib/idlelib/idle_test/test_help_about.py index 1f67aad..9c6a834 100644 --- a/Lib/idlelib/idle_test/test_help_about.py +++ b/Lib/idlelib/idle_test/test_help_about.py @@ -50,35 +50,37 @@ class LiveDialogTest(unittest.TestCase): def test_printer_buttons(self): """Test buttons whose commands use printer function.""" dialog = self.dialog - button_sources = [(dialog.py_license, license), - (dialog.py_copyright, copyright), - (dialog.py_credits, credits)] - - for button, printer in button_sources: - printer._Printer__setup() - button.invoke() - get = dialog._current_textview.viewframe.textframe.text.get - self.assertEqual(printer._Printer__lines[0], get('1.0', '1.end')) - self.assertEqual( - printer._Printer__lines[1], get('2.0', '2.end')) - dialog._current_textview.destroy() + button_sources = [(dialog.py_license, license, 'license'), + (dialog.py_copyright, copyright, 'copyright'), + (dialog.py_credits, credits, 'credits')] + + for button, printer, name in button_sources: + with self.subTest(name=name): + printer._Printer__setup() + button.invoke() + get = dialog._current_textview.viewframe.textframe.text.get + lines = printer._Printer__lines + self.assertEqual(lines[0], get('1.0', '1.end')) + self.assertEqual(lines[1], get('2.0', '2.end')) + dialog._current_textview.destroy() def test_file_buttons(self): """Test buttons that display files.""" dialog = self.dialog - button_sources = [(self.dialog.readme, 'README.txt'), - (self.dialog.idle_news, 'NEWS.txt'), - (self.dialog.idle_credits, 'CREDITS.txt')] - - for button, filename in button_sources: - button.invoke() - fn = findfile(filename, subdir='idlelib') - get = dialog._current_textview.viewframe.textframe.text.get - with open(fn) as f: - self.assertEqual(f.readline().strip(), get('1.0', '1.end')) - f.readline() - self.assertEqual(f.readline().strip(), get('3.0', '3.end')) - dialog._current_textview.destroy() + button_sources = [(self.dialog.readme, 'README.txt', 'readme'), + (self.dialog.idle_news, 'NEWS.txt', 'news'), + (self.dialog.idle_credits, 'CREDITS.txt', 'credits')] + + for button, filename, name in button_sources: + with self.subTest(name=name): + button.invoke() + fn = findfile(filename, subdir='idlelib') + get = dialog._current_textview.viewframe.textframe.text.get + with open(fn, encoding='utf-8') as f: + self.assertEqual(f.readline().strip(), get('1.0', '1.end')) + f.readline() + self.assertEqual(f.readline().strip(), get('3.0', '3.end')) + dialog._current_textview.destroy() class DefaultTitleTest(unittest.TestCase): diff --git a/Misc/NEWS.d/next/IDLE/2018-02-12-11-05-22.bpo-32826.IxNZrk.rst b/Misc/NEWS.d/next/IDLE/2018-02-12-11-05-22.bpo-32826.IxNZrk.rst new file mode 100644 index 0000000..4310ed2 --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2018-02-12-11-05-22.bpo-32826.IxNZrk.rst @@ -0,0 +1,5 @@ +Add "encoding=utf-8" to open() in IDLE's test_help_about. +GUI test test_file_buttons() only looks at initial ascii-only lines, +but failed on systems where open() defaults to 'ascii' because +readline() internally reads and decodes far enough ahead to encounter +a non-ascii character in CREDITS.txt. |
