summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/idle_test/test_run.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-10-08 11:32:25 (GMT)
committerGitHub <noreply@github.com>2019-10-08 11:32:25 (GMT)
commitb690a2759e62d9ee0b6ea1b20e8f7e4b2cdbf8bb (patch)
treeef8fa0a711cb3780ac5bb33147bea57378322c62 /Lib/idlelib/idle_test/test_run.py
parentd05b000c6bcd39dba4f4b2656e45954802649562 (diff)
downloadcpython-b690a2759e62d9ee0b6ea1b20e8f7e4b2cdbf8bb.zip
cpython-b690a2759e62d9ee0b6ea1b20e8f7e4b2cdbf8bb.tar.gz
cpython-b690a2759e62d9ee0b6ea1b20e8f7e4b2cdbf8bb.tar.bz2
bpo-36698: IDLE no longer fails when write non-encodable characters to stderr. (GH-16583)
It now escapes them with a backslash, as the regular Python interpreter. Added the "errors" field to the standard streams.
Diffstat (limited to 'Lib/idlelib/idle_test/test_run.py')
-rw-r--r--Lib/idlelib/idle_test/test_run.py60
1 files changed, 40 insertions, 20 deletions
diff --git a/Lib/idlelib/idle_test/test_run.py b/Lib/idlelib/idle_test/test_run.py
index cad0b4d..9995dbe 100644
--- a/Lib/idlelib/idle_test/test_run.py
+++ b/Lib/idlelib/idle_test/test_run.py
@@ -36,7 +36,7 @@ class RunTest(unittest.TestCase):
self.assertIn('UnhashableException: ex1', tb[10])
-# PseudoFile tests.
+# StdioFile tests.
class S(str):
def __str__(self):
@@ -68,14 +68,14 @@ class MockShell:
self.lines = list(lines)[::-1]
-class PseudeInputFilesTest(unittest.TestCase):
+class StdInputFilesTest(unittest.TestCase):
def test_misc(self):
shell = MockShell()
- f = run.PseudoInputFile(shell, 'stdin', 'utf-8')
+ f = run.StdInputFile(shell, 'stdin')
self.assertIsInstance(f, io.TextIOBase)
self.assertEqual(f.encoding, 'utf-8')
- self.assertIsNone(f.errors)
+ self.assertEqual(f.errors, 'strict')
self.assertIsNone(f.newlines)
self.assertEqual(f.name, '<stdin>')
self.assertFalse(f.closed)
@@ -86,7 +86,7 @@ class PseudeInputFilesTest(unittest.TestCase):
def test_unsupported(self):
shell = MockShell()
- f = run.PseudoInputFile(shell, 'stdin', 'utf-8')
+ f = run.StdInputFile(shell, 'stdin')
self.assertRaises(OSError, f.fileno)
self.assertRaises(OSError, f.tell)
self.assertRaises(OSError, f.seek, 0)
@@ -95,7 +95,7 @@ class PseudeInputFilesTest(unittest.TestCase):
def test_read(self):
shell = MockShell()
- f = run.PseudoInputFile(shell, 'stdin', 'utf-8')
+ f = run.StdInputFile(shell, 'stdin')
shell.push(['one\n', 'two\n', ''])
self.assertEqual(f.read(), 'one\ntwo\n')
shell.push(['one\n', 'two\n', ''])
@@ -115,7 +115,7 @@ class PseudeInputFilesTest(unittest.TestCase):
def test_readline(self):
shell = MockShell()
- f = run.PseudoInputFile(shell, 'stdin', 'utf-8')
+ f = run.StdInputFile(shell, 'stdin')
shell.push(['one\n', 'two\n', 'three\n', 'four\n'])
self.assertEqual(f.readline(), 'one\n')
self.assertEqual(f.readline(-1), 'two\n')
@@ -140,7 +140,7 @@ class PseudeInputFilesTest(unittest.TestCase):
def test_readlines(self):
shell = MockShell()
- f = run.PseudoInputFile(shell, 'stdin', 'utf-8')
+ f = run.StdInputFile(shell, 'stdin')
shell.push(['one\n', 'two\n', ''])
self.assertEqual(f.readlines(), ['one\n', 'two\n'])
shell.push(['one\n', 'two\n', ''])
@@ -161,7 +161,7 @@ class PseudeInputFilesTest(unittest.TestCase):
def test_close(self):
shell = MockShell()
- f = run.PseudoInputFile(shell, 'stdin', 'utf-8')
+ f = run.StdInputFile(shell, 'stdin')
shell.push(['one\n', 'two\n', ''])
self.assertFalse(f.closed)
self.assertEqual(f.readline(), 'one\n')
@@ -171,14 +171,14 @@ class PseudeInputFilesTest(unittest.TestCase):
self.assertRaises(TypeError, f.close, 1)
-class PseudeOutputFilesTest(unittest.TestCase):
+class StdOutputFilesTest(unittest.TestCase):
def test_misc(self):
shell = MockShell()
- f = run.PseudoOutputFile(shell, 'stdout', 'utf-8')
+ f = run.StdOutputFile(shell, 'stdout')
self.assertIsInstance(f, io.TextIOBase)
self.assertEqual(f.encoding, 'utf-8')
- self.assertIsNone(f.errors)
+ self.assertEqual(f.errors, 'strict')
self.assertIsNone(f.newlines)
self.assertEqual(f.name, '<stdout>')
self.assertFalse(f.closed)
@@ -189,7 +189,7 @@ class PseudeOutputFilesTest(unittest.TestCase):
def test_unsupported(self):
shell = MockShell()
- f = run.PseudoOutputFile(shell, 'stdout', 'utf-8')
+ f = run.StdOutputFile(shell, 'stdout')
self.assertRaises(OSError, f.fileno)
self.assertRaises(OSError, f.tell)
self.assertRaises(OSError, f.seek, 0)
@@ -198,16 +198,36 @@ class PseudeOutputFilesTest(unittest.TestCase):
def test_write(self):
shell = MockShell()
- f = run.PseudoOutputFile(shell, 'stdout', 'utf-8')
+ f = run.StdOutputFile(shell, 'stdout')
f.write('test')
self.assertEqual(shell.written, [('test', 'stdout')])
shell.reset()
- f.write('t\xe8st')
- self.assertEqual(shell.written, [('t\xe8st', 'stdout')])
+ f.write('t\xe8\u015b\U0001d599')
+ self.assertEqual(shell.written, [('t\xe8\u015b\U0001d599', 'stdout')])
shell.reset()
- f.write(S('t\xe8st'))
- self.assertEqual(shell.written, [('t\xe8st', 'stdout')])
+ f.write(S('t\xe8\u015b\U0001d599'))
+ self.assertEqual(shell.written, [('t\xe8\u015b\U0001d599', 'stdout')])
+ self.assertEqual(type(shell.written[0][0]), str)
+ shell.reset()
+
+ self.assertRaises(TypeError, f.write)
+ self.assertEqual(shell.written, [])
+ self.assertRaises(TypeError, f.write, b'test')
+ self.assertRaises(TypeError, f.write, 123)
+ self.assertEqual(shell.written, [])
+ self.assertRaises(TypeError, f.write, 'test', 'spam')
+ self.assertEqual(shell.written, [])
+
+ def test_write_stderr_nonencodable(self):
+ shell = MockShell()
+ f = run.StdOutputFile(shell, 'stderr', 'iso-8859-15', 'backslashreplace')
+ f.write('t\xe8\u015b\U0001d599\xa4')
+ self.assertEqual(shell.written, [('t\xe8\\u015b\\U0001d599\\xa4', 'stderr')])
+ shell.reset()
+
+ f.write(S('t\xe8\u015b\U0001d599\xa4'))
+ self.assertEqual(shell.written, [('t\xe8\\u015b\\U0001d599\\xa4', 'stderr')])
self.assertEqual(type(shell.written[0][0]), str)
shell.reset()
@@ -221,7 +241,7 @@ class PseudeOutputFilesTest(unittest.TestCase):
def test_writelines(self):
shell = MockShell()
- f = run.PseudoOutputFile(shell, 'stdout', 'utf-8')
+ f = run.StdOutputFile(shell, 'stdout')
f.writelines([])
self.assertEqual(shell.written, [])
shell.reset()
@@ -251,7 +271,7 @@ class PseudeOutputFilesTest(unittest.TestCase):
def test_close(self):
shell = MockShell()
- f = run.PseudoOutputFile(shell, 'stdout', 'utf-8')
+ f = run.StdOutputFile(shell, 'stdout')
self.assertFalse(f.closed)
f.write('test')
f.close()