Skip to content

Commit 0d382c4

Browse files
authored
Remove Py2 special cases from tests (GH-279)
1 parent c77177a commit 0d382c4

File tree

1 file changed

+7
-23
lines changed

1 file changed

+7
-23
lines changed

lupa/tests/test.py

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# -*- coding: utf-8 -*-
22

3-
from __future__ import absolute_import, print_function
4-
53
import gc
64
import operator
75
import os.path
@@ -20,7 +18,6 @@
2018
except (ImportError, AttributeError):
2119
IS_PYPY = False
2220

23-
IS_PYTHON2 = sys.version_info[0] < 3
2421
not_in_pypy = unittest.skipIf(IS_PYPY, "test not run in PyPy")
2522

2623
try:
@@ -29,11 +26,6 @@
2926
def _next(o):
3027
return o.next()
3128

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-
3729

3830
class SetupLuaRuntimeMixin(object):
3931
lua_runtime_kwargs = {}
@@ -169,15 +161,12 @@ def test_eval_error_cleanup(self):
169161
def test_eval_error_message_decoding(self):
170162
try:
171163
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)
174166
else:
175167
self.fail('expected error not raised')
176168
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)
181170

182171
def test_execute(self):
183172
self.assertEqual(2, self.lua.execute('return 1+1'))
@@ -947,7 +936,7 @@ def test_lua_error_after_intercepted_python_exception(self):
947936

948937
def test_attribute_filter(self):
949938
def attr_filter(obj, name, setting):
950-
if isinstance(name, unicode_type):
939+
if isinstance(name, str):
951940
if not name.startswith('_'):
952941
return name + '1'
953942
raise AttributeError('denied')
@@ -1124,7 +1113,7 @@ class Y(object):
11241113
__a = 3
11251114

11261115
def attr_getter(self, obj, name):
1127-
if not isinstance(name, unicode_type):
1116+
if not isinstance(name, str):
11281117
raise AttributeError('bad type for attr_name')
11291118
if isinstance(obj, self.X):
11301119
if not name.startswith('_'):
@@ -1830,13 +1819,11 @@ def tearDown(self):
18301819
gc.collect()
18311820

18321821
test_string = '"abcüöä"'
1833-
if IS_PYTHON2:
1834-
test_string = test_string.decode('UTF-8')
18351822

18361823
def _encoding_test(self, encoding, expected_length):
18371824
lua = self.lupa.LuaRuntime(encoding)
18381825

1839-
self.assertEqual(unicode_type,
1826+
self.assertEqual(str,
18401827
type(lua.eval(self.test_string)))
18411828

18421829
self.assertEqual(self.test_string[1:-1],
@@ -2091,10 +2078,7 @@ def mandelbrot(i, lua_func):
20912078
# plausability checks - make sure it's not all white or all black
20922079
self.assertEqual('\0'.encode('ASCII')*(image_size//8//2),
20932080
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)
20982082

20992083
# if we have PIL, check that it can read the image
21002084
## try:

0 commit comments

Comments
 (0)