source: utilitiespy/test/exception/ExceptionContainerTest.py@ 1409

Last change on this file since 1409 was 1409, checked in by wouter, 4 days ago

extend ExceptionContainer with fromException

File size: 2.0 KB
Line 
1import unittest
2from _ctypes import ArgumentError
3from tudelft.utilities.exception.ExceptionContainer import ExceptionContainer
4import json
5
6
7trace1: str = "Traceback (most recent call last):\n File '<stdin>', line 1, in <module>\nAttributeError: dsds"
8trace2:str='"Traceback (most recent call last):\n File "/tmp/PythonVenvs/failingtest100targz/lib/python3.8/site-packages/testcode/failingTest.py", line 33, in test\n runTests(FailingTest)\n File "/tmp/PythonVenvs/failingtest100targz/lib/python3.8/site-packages/unitpy/Runner.py", line 77, in runTests\n getRunWith(clazz)(clazz).run()\n File "/tmp/PythonVenvs/failingtest100targz/lib/python3.8/site-packages/unitpy/Runner.py", line 85, in run\n self._runall([])\n File "/tmp/PythonVenvs/failingtest100targz/lib/python3.8/site-packages/unitpy/Runner.py", line 50, in _runall\n m()\n File "/tmp/PythonVenvs/failingtest100targz/lib/python3.8/site-packages/testcode/failingTest.py", line 23, in failedtest\n raise AssertionError("this is wrong")\nAssertionError: this is wrong"'
9
10
11class ExceptionContainerTest(unittest.TestCase):
12
13 def testSmoke(self):
14 c=ExceptionContainer.create(trace1)
15 print(str(c))
16
17 def testType(self):
18 c=ExceptionContainer.create(trace1)
19 self.assertEqual("AttributeError",c.getClassName())
20
21 def testMessage(self):
22 c=ExceptionContainer.create(trace1)
23 self.assertEqual(" dsds",c.getMessage())
24
25 def testLargerMessage(self):
26 c=ExceptionContainer.create(trace2)
27 print("warning: below looks like a message from else but it's the contained trace2")
28 print(str(c))
29
30 def testToJson(self):
31 c=ExceptionContainer.create(trace1)
32 print(json.dumps(c.toJson()))
33
34 def testFromException(self):
35 e:Exception = ArgumentError("bad content")
36 e.__cause__=ZeroDivisionError("inner exc mesg")
37 con2:ExceptionContainer = ExceptionContainer.fromException(e);
38 self.assertEqual("ArgumentError", con2.getClassName());
39 self.assertIsNotNone(con2.getCause())
Note: See TracBrowser for help on using the repository browser.