| 1 |
import unittest |
| 2 |
from test.support import import_helper |
| 3 |
import types |
| 4 |
|
| 5 |
xxlimited = import_helper.import_module('xxlimited') |
| 6 |
xxlimited_35 = import_helper.import_module('xxlimited_35') |
| 7 |
|
| 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() |
| 17 |
with self.assertRaises(AttributeError): |
| 18 |
xxo.foo |
| 19 |
with self.assertRaises(AttributeError): |
| 20 |
del xxo.foo |
| 21 |
|
| 22 |
xxo.foo = 1234 |
| 23 |
self.assertEqual(xxo.foo, 1234) |
| 24 |
|
| 25 |
del xxo.foo |
| 26 |
with self.assertRaises(AttributeError): |
| 27 |
xxo.foo |
| 28 |
|
| 29 |
def test_foo(self): |
| 30 |
# the foo function adds 2 numbers |
| 31 |
self.assertEqual(self.module.foo(1, 2), 3) |
| 32 |
|
| 33 |
def test_str(self): |
| 34 |
self.assertIsSubclass(self.module.Str, str) |
| 35 |
self.assertIsNot(self.module.Str, str) |
| 36 |
|
| 37 |
custom_string = self.module.Str("abcd") |
| 38 |
self.assertEqual(custom_string, "abcd") |
| 39 |
self.assertEqual(custom_string.upper(), "ABCD") |
| 40 |
|
| 41 |
def test_new(self): |
| 42 |
xxo = self.module.new() |
| 43 |
self.assertEqual(xxo.demo("abc"), "abc") |
| 44 |
|
| 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() |
| 52 |
self.assertEqual(xxo.demo("abc"), "abc") |
| 53 |
self.assertEqual(xxo.demo(xxo), xxo) |
| 54 |
self.assertEqual(xxo.demo(other), other) |
| 55 |
self.assertEqual(xxo.demo(0), None) |
| 56 |
|
| 57 |
def test_error(self): |
| 58 |
with self.assertRaises(self.module.Error): |
| 59 |
raise self.module.Error |
| 60 |
|
| 61 |
def test_buffer(self): |
| 62 |
xxo = self.module.Xxo() |
| 63 |
self.assertEqual(xxo.x_exports, 0) |
| 64 |
b1 = memoryview(xxo) |
| 65 |
self.assertEqual(xxo.x_exports, 1) |
| 66 |
b2 = memoryview(xxo) |
| 67 |
self.assertEqual(xxo.x_exports, 2) |
| 68 |
b1[0] = 1 |
| 69 |
self.assertEqual(b1[0], 1) |
| 70 |
self.assertEqual(b2[0], 1) |
| 71 |
|
| 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 |
|
| 82 |
def test_roj(self): |
| 83 |
# the roj function always fails |
| 84 |
with self.assertRaises(SystemError): |
| 85 |
self.module.roj(0) |
| 86 |
|
| 87 |
def test_null(self): |
| 88 |
null1 = self.module.Null() |
| 89 |
null2 = self.module.Null() |
| 90 |
self.assertNotEqual(null1, null2) |