summaryrefslogtreecommitdiffstats
path: root/tests/test_error.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_error.py')
-rw-r--r--tests/test_error.py60
1 files changed, 31 insertions, 29 deletions
diff --git a/tests/test_error.py b/tests/test_error.py
index 82b00c24..784e2d57 100644
--- a/tests/test_error.py
+++ b/tests/test_error.py
@@ -22,32 +22,34 @@ import error
22 22
23 23
24class PickleTests(unittest.TestCase): 24class PickleTests(unittest.TestCase):
25 """Make sure all our custom exceptions can be pickled.""" 25 """Make sure all our custom exceptions can be pickled."""
26 26
27 def getExceptions(self): 27 def getExceptions(self):
28 """Return all our custom exceptions.""" 28 """Return all our custom exceptions."""
29 for name in dir(error): 29 for name in dir(error):
30 cls = getattr(error, name) 30 cls = getattr(error, name)
31 if isinstance(cls, type) and issubclass(cls, Exception): 31 if isinstance(cls, type) and issubclass(cls, Exception):
32 yield cls 32 yield cls
33 33
34 def testExceptionLookup(self): 34 def testExceptionLookup(self):
35 """Make sure our introspection logic works.""" 35 """Make sure our introspection logic works."""
36 classes = list(self.getExceptions()) 36 classes = list(self.getExceptions())
37 self.assertIn(error.HookError, classes) 37 self.assertIn(error.HookError, classes)
38 # Don't assert the exact number to avoid being a change-detector test. 38 # Don't assert the exact number to avoid being a change-detector test.
39 self.assertGreater(len(classes), 10) 39 self.assertGreater(len(classes), 10)
40 40
41 def testPickle(self): 41 def testPickle(self):
42 """Try to pickle all the exceptions.""" 42 """Try to pickle all the exceptions."""
43 for cls in self.getExceptions(): 43 for cls in self.getExceptions():
44 args = inspect.getfullargspec(cls.__init__).args[1:] 44 args = inspect.getfullargspec(cls.__init__).args[1:]
45 obj = cls(*args) 45 obj = cls(*args)
46 p = pickle.dumps(obj) 46 p = pickle.dumps(obj)
47 try: 47 try:
48 newobj = pickle.loads(p) 48 newobj = pickle.loads(p)
49 except Exception as e: # pylint: disable=broad-except 49 except Exception as e: # pylint: disable=broad-except
50 self.fail('Class %s is unable to be pickled: %s\n' 50 self.fail(
51 'Incomplete super().__init__(...) call?' % (cls, e)) 51 "Class %s is unable to be pickled: %s\n"
52 self.assertIsInstance(newobj, cls) 52 "Incomplete super().__init__(...) call?" % (cls, e)
53 self.assertEqual(str(obj), str(newobj)) 53 )
54 self.assertIsInstance(newobj, cls)
55 self.assertEqual(str(obj), str(newobj))