|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
1 | 3 | from __future__ import unicode_literals |
2 | 4 |
|
3 | 5 | try: |
@@ -57,40 +59,36 @@ def g(): |
57 | 59 |
|
58 | 60 | @unittest.skipIf(py3, "runsource() accepts only unicode in Python 3") |
59 | 61 | def test_runsource_bytes(self): |
60 | | - i = interpreter.Interp() |
61 | | - i.encoding = 'latin-1' |
| 62 | + i = interpreter.Interp(encoding='latin-1') |
62 | 63 |
|
63 | | - i.runsource(b"a = b'\xfe'") |
| 64 | + i.runsource("a = b'\xfe'".encode('latin-1'), encode=False) |
64 | 65 | self.assertIsInstance(i.locals['a'], str) |
65 | 66 | self.assertEqual(i.locals['a'], b"\xfe") |
66 | 67 |
|
67 | | - i.runsource(b"b = u'\xfe'") |
| 68 | + i.runsource("b = u'\xfe'".encode('latin-1'), encode=False) |
68 | 69 | self.assertIsInstance(i.locals['b'], unicode) |
69 | | - self.assertEqual(i.locals['b'], u"\xfe") |
| 70 | + self.assertEqual(i.locals['b'], "\xfe") |
70 | 71 |
|
71 | 72 | @unittest.skipUnless(py3, "Only a syntax error in Python 3") |
72 | 73 | @mock.patch.object(interpreter.Interp, 'showsyntaxerror') |
73 | 74 | def test_runsource_bytes_over_128_syntax_error(self): |
74 | | - i = interpreter.Interp() |
75 | | - i.encoding = 'latin-1' |
| 75 | + i = interpreter.Interp(encoding='latin-1') |
76 | 76 |
|
77 | | - i.runsource(u"a = b'\xfe'") |
| 77 | + i.runsource("a = b'\xfe'", encode=True) |
78 | 78 | i.showsyntaxerror.assert_called_with() |
79 | 79 |
|
80 | | - @unittest.skip("Is the goal of encoding to get this to work?") |
81 | | - @unittest.skipIf(py3, "bytes 128-255 only permitted in Py 2") |
| 80 | + @unittest.skipIf(py3, "encode is Python 2 only") |
82 | 81 | def test_runsource_bytes_over_128_syntax_error(self): |
83 | | - i = interpreter.Interp() |
84 | | - i.encoding = 'latin-1' |
| 82 | + i = interpreter.Interp(encoding='latin-1') |
85 | 83 |
|
86 | | - i.runsource(u"a = b'\xfe'") |
| 84 | + i.runsource("a = b'\xfe'", encode=True) |
87 | 85 | self.assertIsInstance(i.locals['a'], type(b'')) |
88 | 86 | self.assertEqual(i.locals['a'], b"\xfe") |
89 | 87 |
|
| 88 | + @unittest.skipIf(py3, "encode is Python 2 only") |
90 | 89 | def test_runsource_unicode(self): |
91 | | - i = interpreter.Interp() |
92 | | - i.encoding = 'latin-1' |
| 90 | + i = interpreter.Interp(encoding='latin-1') |
93 | 91 |
|
94 | | - i.runsource(u"a = u'\xfe'") |
| 92 | + i.runsource("a = u'\xfe'", encode=True) |
95 | 93 | self.assertIsInstance(i.locals['a'], type(u'')) |
96 | 94 | self.assertEqual(i.locals['a'], u"\xfe") |
0 commit comments