-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
Expand file tree
/
Copy pathtest_xxlimited.py
More file actions
123 lines (104 loc) · 3.75 KB
/
test_xxlimited.py
File metadata and controls
123 lines (104 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import unittest
from test.support import import_helper
xxlimited = import_helper.import_module('xxlimited')
# if import of xxlimited succeeded, the other ones should be importable.
import xxlimited_3_13
import xxlimited_35
MODULES = {
(3, 15): xxlimited,
(3, 13): xxlimited_3_13,
(3, 5): xxlimited_35,
}
def test_with_xxlimited_modules(since=None, until=None):
def _decorator(func):
def _wrapper(self, *args, **kwargs):
for version, module in MODULES.items():
if since and version < since:
continue
if until and version >= until:
continue
with self.subTest(version=version):
func(self, module, *args, **kwargs)
return _wrapper
return _decorator
class XXLimitedTests(unittest.TestCase):
@test_with_xxlimited_modules()
def test_xxo_new(self, module):
xxo = module.Xxo()
@test_with_xxlimited_modules()
def test_xxo_attributes(self, module):
xxo = module.Xxo()
with self.assertRaises(AttributeError):
xxo.foo
with self.assertRaises(AttributeError):
del xxo.foo
xxo.foo = 1234
self.assertEqual(xxo.foo, 1234)
del xxo.foo
with self.assertRaises(AttributeError):
xxo.foo
@test_with_xxlimited_modules()
def test_foo(self, module):
# the foo function adds 2 numbers
self.assertEqual(module.foo(1, 2), 3)
@test_with_xxlimited_modules()
def test_str(self, module):
self.assertIsSubclass(module.Str, str)
self.assertIsNot(module.Str, str)
custom_string = module.Str("abcd")
self.assertEqual(custom_string, "abcd")
self.assertEqual(custom_string.upper(), "ABCD")
@test_with_xxlimited_modules()
def test_new(self, module):
xxo = module.new()
self.assertEqual(xxo.demo("abc"), "abc")
@test_with_xxlimited_modules()
def test_xxo_demo(self, module):
xxo = module.Xxo()
self.assertEqual(xxo.demo("abc"), "abc")
self.assertEqual(xxo.demo(0), None)
self.assertEqual(xxo.__module__, module.__name__)
with self.assertRaises(TypeError):
module.Xxo('arg')
with self.assertRaises(TypeError):
module.Xxo(kwarg='arg')
@test_with_xxlimited_modules(since=(3, 13))
def test_xxo_demo_extra(self, module):
xxo = module.Xxo()
other = module.Xxo()
self.assertEqual(xxo.demo(xxo), xxo)
self.assertEqual(xxo.demo(other), other)
@test_with_xxlimited_modules(since=(3, 15))
def test_xxo_subclass(self, module):
class Sub(module.Xxo):
pass
sub = Sub()
sub.a = 123
self.assertEqual(sub.a, 123)
with self.assertRaisesRegex(AttributeError, "cannot set 'reserved'"):
sub.reserved = 123
@test_with_xxlimited_modules(since=(3, 13))
def test_error(self, module):
with self.assertRaises(module.Error):
raise module.Error
@test_with_xxlimited_modules(since=(3, 13))
def test_buffer(self, module):
xxo = module.Xxo()
self.assertEqual(xxo.x_exports, 0)
b1 = memoryview(xxo)
self.assertEqual(xxo.x_exports, 1)
b2 = memoryview(xxo)
self.assertEqual(xxo.x_exports, 2)
b1[0] = 1
self.assertEqual(b1[0], 1)
self.assertEqual(b2[0], 1)
@test_with_xxlimited_modules(until=(3, 5))
def test_roj(self):
# the roj function always fails
with self.assertRaises(SystemError):
self.module.roj(0)
@test_with_xxlimited_modules(until=(3, 5))
def test_null(self):
null1 = self.module.Null()
null2 = self.module.Null()
self.assertNotEqual(null1, null2)