Skip to content

Commit

Permalink
Remove Py2 special cases from tests (GH-279)
Browse files Browse the repository at this point in the history
  • Loading branch information
a-detiste authored Feb 15, 2025
1 parent c77177a commit 0d382c4
Showing 1 changed file with 7 additions and 23 deletions.
30 changes: 7 additions & 23 deletions lupa/tests/test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import, print_function

import gc
import operator
import os.path
Expand All @@ -20,7 +18,6 @@
except (ImportError, AttributeError):
IS_PYPY = False

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

try:
Expand All @@ -29,11 +26,6 @@
def _next(o):
return o.next()

unicode_type = type(b'abc'.decode('ASCII') if IS_PYTHON2 else 'abc')

if IS_PYTHON2:
unittest.TestCase.assertRaisesRegex = unittest.TestCase.assertRaisesRegexp


class SetupLuaRuntimeMixin(object):
lua_runtime_kwargs = {}
Expand Down Expand Up @@ -169,15 +161,12 @@ def test_eval_error_cleanup(self):
def test_eval_error_message_decoding(self):
try:
self.lua.eval('require "UNKNOWNöMODULEäNAME"')
except self.lupa.LuaError:
error = ('%s'.decode('ASCII') if IS_PYTHON2 else '%s') % sys.exc_info()[1]
except self.lupa.LuaError as exc:
error = str(exc)
else:
self.fail('expected error not raised')
expected_message = 'module \'UNKNOWNöMODULEäNAME\' not found'
if IS_PYTHON2:
expected_message = expected_message.decode('UTF-8')
self.assertTrue(expected_message in error,
'"%s" not found in "%s"' % (expected_message, error))
self.assertIn(expected_message, error)

def test_execute(self):
self.assertEqual(2, self.lua.execute('return 1+1'))
Expand Down Expand Up @@ -947,7 +936,7 @@ def test_lua_error_after_intercepted_python_exception(self):

def test_attribute_filter(self):
def attr_filter(obj, name, setting):
if isinstance(name, unicode_type):
if isinstance(name, str):
if not name.startswith('_'):
return name + '1'
raise AttributeError('denied')
Expand Down Expand Up @@ -1124,7 +1113,7 @@ class Y(object):
__a = 3

def attr_getter(self, obj, name):
if not isinstance(name, unicode_type):
if not isinstance(name, str):
raise AttributeError('bad type for attr_name')
if isinstance(obj, self.X):
if not name.startswith('_'):
Expand Down Expand Up @@ -1830,13 +1819,11 @@ def tearDown(self):
gc.collect()

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

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

self.assertEqual(unicode_type,
self.assertEqual(str,
type(lua.eval(self.test_string)))

self.assertEqual(self.test_string[1:-1],
Expand Down Expand Up @@ -2091,10 +2078,7 @@ def mandelbrot(i, lua_func):
# plausability checks - make sure it's not all white or all black
self.assertEqual('\0'.encode('ASCII')*(image_size//8//2),
result_bytes[:image_size//8//2])
if IS_PYTHON2:
self.assertTrue('\xFF' in result_bytes)
else:
self.assertTrue('\xFF'.encode('ISO-8859-1') in result_bytes)
self.assertTrue(b'\xFF' in result_bytes)

# if we have PIL, check that it can read the image
## try:
Expand Down

0 comments on commit 0d382c4

Please sign in to comment.