Skip to content

Commit 65f3fd0

Browse files
committed
Run tests for all the xxlimited* modules
1 parent 8147b92 commit 65f3fd0

File tree

1 file changed

+60
-41
lines changed

1 file changed

+60
-41
lines changed

Lib/test/test_xxlimited.py

Lines changed: 60 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,38 @@
33
import types
44

55
xxlimited = import_helper.import_module('xxlimited')
6-
xxlimited_35 = import_helper.import_module('xxlimited_35')
76

8-
9-
class CommonTests:
10-
module: types.ModuleType
11-
12-
def test_xxo_new(self):
13-
xxo = self.module.Xxo()
14-
15-
def test_xxo_attributes(self):
16-
xxo = self.module.Xxo()
7+
# if import of xxlimited succeeded, the other ones should be importable.
8+
import xxlimited_3_13
9+
import xxlimited_35
10+
11+
MODULES = {
12+
(3, 15): xxlimited,
13+
(3, 13): xxlimited_3_13,
14+
(3, 5): xxlimited_35,
15+
}
16+
17+
def test_with_xxlimited_modules(since=None, until=None):
18+
def _decorator(func):
19+
def _wrapper(self, *args, **kwargs):
20+
for version, module in MODULES.items():
21+
if since and version < since:
22+
continue
23+
if until and version >= until:
24+
continue
25+
with self.subTest(version=version):
26+
func(self, module, *args, **kwargs)
27+
return _wrapper
28+
return _decorator
29+
30+
class XXLimitedTests(unittest.TestCase):
31+
@test_with_xxlimited_modules()
32+
def test_xxo_new(self, module):
33+
xxo = module.Xxo()
34+
35+
@test_with_xxlimited_modules()
36+
def test_xxo_attributes(self, module):
37+
xxo = module.Xxo()
1738
with self.assertRaises(AttributeError):
1839
xxo.foo
1940
with self.assertRaises(AttributeError):
@@ -26,40 +47,46 @@ def test_xxo_attributes(self):
2647
with self.assertRaises(AttributeError):
2748
xxo.foo
2849

29-
def test_foo(self):
50+
@test_with_xxlimited_modules()
51+
def test_foo(self, module):
3052
# the foo function adds 2 numbers
31-
self.assertEqual(self.module.foo(1, 2), 3)
53+
self.assertEqual(module.foo(1, 2), 3)
3254

33-
def test_str(self):
34-
self.assertIsSubclass(self.module.Str, str)
35-
self.assertIsNot(self.module.Str, str)
55+
@test_with_xxlimited_modules()
56+
def test_str(self, module):
57+
self.assertIsSubclass(module.Str, str)
58+
self.assertIsNot(module.Str, str)
3659

37-
custom_string = self.module.Str("abcd")
60+
custom_string = module.Str("abcd")
3861
self.assertEqual(custom_string, "abcd")
3962
self.assertEqual(custom_string.upper(), "ABCD")
4063

41-
def test_new(self):
42-
xxo = self.module.new()
64+
@test_with_xxlimited_modules()
65+
def test_new(self, module):
66+
xxo = module.new()
4367
self.assertEqual(xxo.demo("abc"), "abc")
4468

45-
46-
class TestXXLimited(CommonTests, unittest.TestCase):
47-
module = xxlimited
48-
49-
def test_xxo_demo(self):
50-
xxo = self.module.Xxo()
51-
other = self.module.Xxo()
69+
@test_with_xxlimited_modules()
70+
def test_xxo_demo(self, module):
71+
xxo = module.Xxo()
5272
self.assertEqual(xxo.demo("abc"), "abc")
73+
self.assertEqual(xxo.demo(0), None)
74+
75+
@test_with_xxlimited_modules(since=(3, 13))
76+
def test_xxo_demo_extra(self, module):
77+
xxo = module.Xxo()
78+
other = module.Xxo()
5379
self.assertEqual(xxo.demo(xxo), xxo)
5480
self.assertEqual(xxo.demo(other), other)
55-
self.assertEqual(xxo.demo(0), None)
5681

57-
def test_error(self):
58-
with self.assertRaises(self.module.Error):
59-
raise self.module.Error
82+
@test_with_xxlimited_modules(since=(3, 13))
83+
def test_error(self, module):
84+
with self.assertRaises(module.Error):
85+
raise module.Error
6086

61-
def test_buffer(self):
62-
xxo = self.module.Xxo()
87+
@test_with_xxlimited_modules(since=(3, 13))
88+
def test_buffer(self, module):
89+
xxo = module.Xxo()
6390
self.assertEqual(xxo.x_exports, 0)
6491
b1 = memoryview(xxo)
6592
self.assertEqual(xxo.x_exports, 1)
@@ -69,21 +96,13 @@ def test_buffer(self):
6996
self.assertEqual(b1[0], 1)
7097
self.assertEqual(b2[0], 1)
7198

72-
73-
class TestXXLimited35(CommonTests, unittest.TestCase):
74-
module = xxlimited_35
75-
76-
def test_xxo_demo(self):
77-
xxo = self.module.Xxo()
78-
other = self.module.Xxo()
79-
self.assertEqual(xxo.demo("abc"), "abc")
80-
self.assertEqual(xxo.demo(0), None)
81-
99+
@test_with_xxlimited_modules(until=(3, 5))
82100
def test_roj(self):
83101
# the roj function always fails
84102
with self.assertRaises(SystemError):
85103
self.module.roj(0)
86104

105+
@test_with_xxlimited_modules(until=(3, 5))
87106
def test_null(self):
88107
null1 = self.module.Null()
89108
null2 = self.module.Null()

0 commit comments

Comments
 (0)