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
|
import unittest
from test.support import import_helper
import types
xxlimited = import_helper.import_module('xxlimited')
xxlimited_35 = import_helper.import_module('xxlimited_35')
class CommonTests:
module: types.ModuleType
def test_xxo_new(self):
xxo = self.module.Xxo()
def test_xxo_attributes(self):
xxo = self.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
def test_foo(self):
# the foo function adds 2 numbers
self.assertEqual(self.module.foo(1, 2), 3)
def test_str(self):
self.assertTrue(issubclass(self.module.Str, str))
self.assertIsNot(self.module.Str, str)
custom_string = self.module.Str("abcd")
self.assertEqual(custom_string, "abcd")
self.assertEqual(custom_string.upper(), "ABCD")
def test_new(self):
xxo = self.module.new()
self.assertEqual(xxo.demo("abc"), "abc")
class TestXXLimited(CommonTests, unittest.TestCase):
module = xxlimited
def test_xxo_demo(self):
xxo = self.module.Xxo()
other = self.module.Xxo()
self.assertEqual(xxo.demo("abc"), "abc")
self.assertEqual(xxo.demo(xxo), xxo)
self.assertEqual(xxo.demo(other), other)
self.assertEqual(xxo.demo(0), None)
def test_error(self):
with self.assertRaises(self.module.Error):
raise self.module.Error
class TestXXLimited35(CommonTests, unittest.TestCase):
module = xxlimited_35
def test_xxo_demo(self):
xxo = self.module.Xxo()
other = self.module.Xxo()
self.assertEqual(xxo.demo("abc"), "abc")
self.assertEqual(xxo.demo(0), None)
def test_roj(self):
# the roj function always fails
with self.assertRaises(SystemError):
self.module.roj(0)
def test_null(self):
null1 = self.module.Null()
null2 = self.module.Null()
self.assertNotEqual(null1, null2)
|