示例#1
0
 def test_str(self) -> None:
     x = UnusedError()
     self.assertEqual(str(x), "")
     x2 = UnusedError(message="hello")
     self.assertEqual(str(x2), "hello")
     y = SimpleError()
     self.assertEqual(str(y), "Color.red")
     y2 = SimpleError(color=Color.red)
     self.assertEqual(str(y2), "Color.red")
示例#2
0
 def test_exception(self) -> None:
     x = SimpleError(color=Color.red)
     self.assertTrue(inspectable(x))
     self.assertTrue(inspectable(SimpleError))
     r = inspect(x)
     self.assertEqual(r.name, "SimpleError")
     self.assertEqual(r.kind, StructType.EXCEPTION)
     self.assertEqual(r.annotations, {})
示例#3
0
    def test_raise(self) -> None:
        with self.assertRaises(SimpleError):
            raise SimpleError()

        with self.assertRaises(Error):
            raise SimpleError(Color.red)

        with self.assertRaises(Exception):
            raise SimpleError()

        with self.assertRaises(BaseException):
            raise SimpleError()

        x = SimpleError(Color.blue)

        self.assertIsInstance(x, BaseException)
        self.assertIsInstance(x, Exception)
        self.assertIsInstance(x, Error)
        self.assertIsInstance(x, SimpleError)