Petr Viktorin | c168b50 | 2020-12-08 17:36:53 +0100 | [diff] [blame^] | 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.assertTrue(issubclass(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 | |
| 62 | class TestXXLimited35(CommonTests, unittest.TestCase): |
| 63 | module = xxlimited_35 |
| 64 | |
| 65 | def test_xxo_demo(self): |
| 66 | xxo = self.module.Xxo() |
| 67 | other = self.module.Xxo() |
| 68 | self.assertEqual(xxo.demo("abc"), "abc") |
| 69 | self.assertEqual(xxo.demo(0), None) |
| 70 | |
| 71 | def test_roj(self): |
| 72 | # the roj function always fails |
| 73 | with self.assertRaises(SystemError): |
| 74 | self.module.roj(0) |
| 75 | |
| 76 | def test_null(self): |
| 77 | null1 = self.module.Null() |
| 78 | null2 = self.module.Null() |
| 79 | self.assertNotEqual(null1, null2) |