Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove IS_PYTHON2 from tests too #279

Merged
merged 3 commits into from
Feb 15, 2025
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 5 additions & 20 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 @@ -170,12 +162,10 @@ 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]
error = str(sys.exc_info()[1])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exc_info is already always a str

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's an exception instance. But looking at it again, I noticed that we can avoid calling sys.exc_info all together just to get at the current exception that we're handling.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy this goes well. Some other projects want to keep their cargo-culted compat.py forever.
There's always opportunity to learn new tricks.

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

Expand Down Expand Up @@ -947,7 +937,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 +1114,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 +1820,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 +2079,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
Loading