1 From 3753c940d08a681a4e41b16e282a2d7c63eef158 Mon Sep 17 00:00:00 2001
2 From: Evangelos Foutras <evangelos@foutrelis.com>
3 Date: Wed, 8 Dec 2021 04:13:16 +0200
4 Subject: [PATCH] Fix two tests to work on Python 3.10
6 Python 3.10 adds the class name to the exception; adjust two tests
7 affected by this change.
9 src/aspectlib/utils.py | 1 +
10 tests/test_aspectlib_test.py | 16 +++++++++++-----
11 2 files changed, 12 insertions(+), 5 deletions(-)
13 diff --git a/src/aspectlib/utils.py b/src/aspectlib/utils.py
14 index 9e0837e..7259187 100644
15 --- a/src/aspectlib/utils.py
16 +++ b/src/aspectlib/utils.py
17 @@ -13,6 +13,7 @@ RegexType = type(re.compile(""))
19 PY3 = sys.version_info[0] == 3
20 PY37plus = PY3 and sys.version_info[1] >= 7
21 +PY310plus = PY3 and sys.version_info[1] >= 10
22 PY2 = sys.version_info[0] == 2
23 PY26 = PY2 and sys.version_info[1] == 6
24 PYPY = platform.python_implementation() == 'PyPy'
25 diff --git a/tests/test_aspectlib_test.py b/tests/test_aspectlib_test.py
26 index 05e2c25..e86ff9d 100644
27 --- a/tests/test_aspectlib_test.py
28 +++ b/tests/test_aspectlib_test.py
29 @@ -3,7 +3,6 @@ from __future__ import print_function
30 from pytest import raises
31 from test_pkg1.test_pkg2 import test_mod
33 -from aspectlib import PY2
34 from aspectlib.test import OrderedDict
35 from aspectlib.test import Story
36 from aspectlib.test import StoryResultWrapper
37 @@ -13,7 +12,9 @@ from aspectlib.test import _Raises
38 from aspectlib.test import _Returns
39 from aspectlib.test import mock
40 from aspectlib.test import record
41 +from aspectlib.utils import PY2
42 from aspectlib.utils import PY26
43 +from aspectlib.utils import PY310plus
44 from aspectlib.utils import repr_ex
46 pytest_plugins = 'pytester',
47 @@ -414,14 +415,17 @@ def test_story_empty_play_proxy_class():
48 (('stuff_1', 'mix', "'a', 'b'", ''), _Returns("(1, 2, 'a', 'b')")),
49 (('stuff_1', 'meth', "123", ''), _Raises(repr_ex(TypeError(
50 'meth() takes exactly 1 argument (2 given)' if PY2 else
51 - 'meth() takes 1 positional argument but 2 were given'
52 + ('Stuff.' if PY310plus else '') +
53 + 'meth() takes 1 positional argument but 2 were given'
56 ((None, 'test_pkg1.test_pkg2.test_mod.Stuff', "0, 1", ''), _Binds('stuff_2')),
57 (('stuff_2', 'mix', "'a', 'b'", ''), _Returns("(0, 1, 'a', 'b')")),
58 (('stuff_2', 'mix', "3, 4", ''), _Returns("(0, 1, 3, 4)")),
59 (('stuff_2', 'meth', "123", ''), _Raises(repr_ex(TypeError(
60 'meth() takes exactly 1 argument (2 given)' if PY2 else
61 - 'meth() takes 1 positional argument but 2 were given'
62 + ('Stuff.' if PY310plus else '') +
63 + 'meth() takes 1 positional argument but 2 were given'
67 @@ -449,14 +453,16 @@ def test_story_half_play_proxy_class():
68 (('stuff_1', 'meth', '', ''), _Returns('None')),
69 (('stuff_1', 'meth', '123', ''), _Raises(repr_ex(TypeError(
70 'meth() takes exactly 1 argument (2 given)' if PY2 else
71 - 'meth() takes 1 positional argument but 2 were given'
72 + ('Stuff.' if PY310plus else '') +
73 + 'meth() takes 1 positional argument but 2 were given'
75 ((None, 'test_pkg1.test_pkg2.test_mod.Stuff', '0, 1', ''), _Binds("stuff_2")),
76 (('stuff_2', 'mix', "'a', 'b'", ''), _Returns("(0, 1, 'a', 'b')")),
77 (('stuff_2', 'mix', '3, 4', ''), _Returns('(0, 1, 3, 4)')),
78 (('stuff_2', 'meth', '123', ''), _Raises(repr_ex(TypeError(
79 'meth() takes exactly 1 argument (2 given)' if PY2 else
80 - 'meth() takes 1 positional argument but 2 were given'
81 + ('Stuff.' if PY310plus else '') +
82 + 'meth() takes 1 positional argument but 2 were given'