|
1 | 1 | # -*- coding: utf-8 -*-
|
2 | 2 |
|
3 |
| -from __future__ import absolute_import, print_function |
4 |
| - |
5 | 3 | import gc
|
6 | 4 | import operator
|
7 | 5 | import os.path
|
|
20 | 18 | except (ImportError, AttributeError):
|
21 | 19 | IS_PYPY = False
|
22 | 20 |
|
23 |
| -IS_PYTHON2 = sys.version_info[0] < 3 |
24 | 21 | not_in_pypy = unittest.skipIf(IS_PYPY, "test not run in PyPy")
|
25 | 22 |
|
26 | 23 | try:
|
|
29 | 26 | def _next(o):
|
30 | 27 | return o.next()
|
31 | 28 |
|
32 |
| -unicode_type = type(b'abc'.decode('ASCII') if IS_PYTHON2 else 'abc') |
33 |
| - |
34 |
| -if IS_PYTHON2: |
35 |
| - unittest.TestCase.assertRaisesRegex = unittest.TestCase.assertRaisesRegexp |
36 |
| - |
37 | 29 |
|
38 | 30 | class SetupLuaRuntimeMixin(object):
|
39 | 31 | lua_runtime_kwargs = {}
|
@@ -169,15 +161,12 @@ def test_eval_error_cleanup(self):
|
169 | 161 | def test_eval_error_message_decoding(self):
|
170 | 162 | try:
|
171 | 163 | self.lua.eval('require "UNKNOWNöMODULEäNAME"')
|
172 |
| - except self.lupa.LuaError: |
173 |
| - error = ('%s'.decode('ASCII') if IS_PYTHON2 else '%s') % sys.exc_info()[1] |
| 164 | + except self.lupa.LuaError as exc: |
| 165 | + error = str(exc) |
174 | 166 | else:
|
175 | 167 | self.fail('expected error not raised')
|
176 | 168 | expected_message = 'module \'UNKNOWNöMODULEäNAME\' not found'
|
177 |
| - if IS_PYTHON2: |
178 |
| - expected_message = expected_message.decode('UTF-8') |
179 |
| - self.assertTrue(expected_message in error, |
180 |
| - '"%s" not found in "%s"' % (expected_message, error)) |
| 169 | + self.assertIn(expected_message, error) |
181 | 170 |
|
182 | 171 | def test_execute(self):
|
183 | 172 | self.assertEqual(2, self.lua.execute('return 1+1'))
|
@@ -947,7 +936,7 @@ def test_lua_error_after_intercepted_python_exception(self):
|
947 | 936 |
|
948 | 937 | def test_attribute_filter(self):
|
949 | 938 | def attr_filter(obj, name, setting):
|
950 |
| - if isinstance(name, unicode_type): |
| 939 | + if isinstance(name, str): |
951 | 940 | if not name.startswith('_'):
|
952 | 941 | return name + '1'
|
953 | 942 | raise AttributeError('denied')
|
@@ -1124,7 +1113,7 @@ class Y(object):
|
1124 | 1113 | __a = 3
|
1125 | 1114 |
|
1126 | 1115 | def attr_getter(self, obj, name):
|
1127 |
| - if not isinstance(name, unicode_type): |
| 1116 | + if not isinstance(name, str): |
1128 | 1117 | raise AttributeError('bad type for attr_name')
|
1129 | 1118 | if isinstance(obj, self.X):
|
1130 | 1119 | if not name.startswith('_'):
|
@@ -1830,13 +1819,11 @@ def tearDown(self):
|
1830 | 1819 | gc.collect()
|
1831 | 1820 |
|
1832 | 1821 | test_string = '"abcüöä"'
|
1833 |
| - if IS_PYTHON2: |
1834 |
| - test_string = test_string.decode('UTF-8') |
1835 | 1822 |
|
1836 | 1823 | def _encoding_test(self, encoding, expected_length):
|
1837 | 1824 | lua = self.lupa.LuaRuntime(encoding)
|
1838 | 1825 |
|
1839 |
| - self.assertEqual(unicode_type, |
| 1826 | + self.assertEqual(str, |
1840 | 1827 | type(lua.eval(self.test_string)))
|
1841 | 1828 |
|
1842 | 1829 | self.assertEqual(self.test_string[1:-1],
|
@@ -2091,10 +2078,7 @@ def mandelbrot(i, lua_func):
|
2091 | 2078 | # plausability checks - make sure it's not all white or all black
|
2092 | 2079 | self.assertEqual('\0'.encode('ASCII')*(image_size//8//2),
|
2093 | 2080 | result_bytes[:image_size//8//2])
|
2094 |
| - if IS_PYTHON2: |
2095 |
| - self.assertTrue('\xFF' in result_bytes) |
2096 |
| - else: |
2097 |
| - self.assertTrue('\xFF'.encode('ISO-8859-1') in result_bytes) |
| 2081 | + self.assertTrue(b'\xFF' in result_bytes) |
2098 | 2082 |
|
2099 | 2083 | # if we have PIL, check that it can read the image
|
2100 | 2084 | ## try:
|
|
0 commit comments