Commit c55bec14 authored by Petr Viktorin's avatar Petr Viktorin Committed by Jason Madden

Amend tests for Python 3.11: No more U file mode, no more inspect.getargspec()

parent 3fe70aca
......@@ -383,6 +383,7 @@ class TestCase(TestCaseMetaClass("NewBase",
return error
def assertMonkeyPatchedFuncSignatures(self, mod_name, func_names=(), exclude=()):
# If inspect.getfullargspec is not available,
# We use inspect.getargspec because it's the only thing available
# in Python 2.7, but it is deprecated
# pylint:disable=deprecated-method,too-many-locals
......@@ -409,9 +410,13 @@ class TestCase(TestCaseMetaClass("NewBase",
try:
with warnings.catch_warnings():
warnings.simplefilter("ignore")
gevent_sig = inspect.getargspec(gevent_func)
sig = inspect.getargspec(func)
try:
getfullargspec = inspect.getfullargspec
except AttributeError:
warnings.simplefilter("ignore")
getfullargspec = inspect.getargspec
gevent_sig = getfullargspec(gevent_func)
sig = getfullargspec(func)
except TypeError:
if funcs_given:
raise
......@@ -420,10 +425,10 @@ class TestCase(TestCaseMetaClass("NewBase",
# Python 3 can check a lot more than Python 2 can.
continue
self.assertEqual(sig.args, gevent_sig.args, func_name)
# The next three might not actually matter?
# The next two might not actually matter?
self.assertEqual(sig.varargs, gevent_sig.varargs, func_name)
self.assertEqual(sig.keywords, gevent_sig.keywords, func_name)
self.assertEqual(sig.defaults, gevent_sig.defaults, func_name)
# Should deal with others: https://docs.python.org/3/library/inspect.html#inspect.getfullargspec
def assertEqualFlakyRaceCondition(self, a, b):
try:
......
......@@ -200,6 +200,8 @@ class TestFileObjectBlock(CleanupMixin,
@skipUnlessWorksWithRegularFiles
def test_rbU_produces_bytes_readline(self):
if sys.version_info > (3, 11):
self.skipTest("U file mode was removed in 3.11")
# Including U in rb still produces bytes.
# Note that the universal newline behaviour is
# essentially ignored in explicit bytes mode.
......@@ -213,6 +215,8 @@ class TestFileObjectBlock(CleanupMixin,
@skipUnlessWorksWithRegularFiles
def test_rU_produces_native(self):
if sys.version_info > (3, 11):
self.skipTest("U file mode was removed in 3.11")
gevent_data = self.__check_native_matches(
b'line1\nline2\r\nline3\rlastline\n\n',
'rU',
......@@ -362,9 +366,15 @@ class ConcurrentFileObjectMixin(object):
try:
with warnings.catch_warnings():
warnings.simplefilter('ignore', DeprecationWarning)
# U is deprecated in Python 3, shows up on FileObjectThread
fobj = self._makeOne(r, 'rU')
if sys.version_info > (3, 11):
# U is removed in Python 3.11
mode = 'r'
self.skipTest("U file mode was removed in 3.11")
else:
# U is deprecated in Python 3, shows up on FileObjectThread
warnings.simplefilter('ignore', DeprecationWarning)
mode = 'rU'
fobj = self._makeOne(r, mode)
result = fobj.read()
fobj.close()
self.assertEqual('line1\nline2\nline3\nline4\nline5\nline6', result)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment