Exemplo n.º 1
0
 def test_creation_required_from_python(self) -> None:
     msg = "ack!"
     code = 22
     with self.assertRaises(TypeError):
         HardError(msg)  # type: ignore
     x = HardError(msg, code)  # type: ignore
     y = HardError(msg, code=code)  # type: ignore
     self.assertEqual(x, y)
     self.assertEqual(x.args, y.args)
     self.assertEqual(x.errortext, y.errortext)
     self.assertEqual(x.code, y.code)
     self.assertEqual(str(x), str(y))
Exemplo n.º 2
0
 def test_creation_required_from_python(self) -> None:
     msg = "ack!"
     code = 22
     # pyre-fixme[19]: Expected 0 positional arguments.
     w = HardError(msg)
     self.assertEqual(w.code, 0)
     # pyre-fixme[19]: Expected 0 positional arguments.
     x = HardError(msg, code)
     # pyre-fixme[19]: Expected 0 positional arguments.
     y = HardError(msg, code=code)
     self.assertEqual(x, y)
     self.assertEqual(x.args, y.args)
     self.assertEqual(x.errortext, y.errortext)
     self.assertEqual(x.code, y.code)
     self.assertEqual(str(x), str(y))
Exemplo n.º 3
0
 def test_exception_message_annotation(self) -> None:
     x = UnusedError(message="something broke")
     self.assertEqual(x.message, str(x))
     y = HardError("WAT!", 22)  # type: ignore
     self.assertEqual(y.errortext, str(y))
     z = UnfriendlyError("WAT!", 22)  # type: ignore
     self.assertNotEqual(z.errortext, str(z))
     self.assertNotEqual(str(y), str(z))
Exemplo n.º 4
0
 def test_exception_message_annotation(self) -> None:
     x = UnusedError(message="something broke")
     self.assertEqual(x.message, str(x))
     # pyre-fixme[19]: Expected 0 positional arguments.
     y = HardError("WAT!", 22)
     self.assertEqual(y.errortext, str(y))
     # pyre-fixme[19]: Expected 0 positional arguments.
     z = UnfriendlyError("WAT!", 22)
     self.assertNotEqual(z.errortext, str(z))
     self.assertNotEqual(str(y), str(z))
Exemplo n.º 5
0
 def test_creation_required_from_c(self) -> None:
     msg = "ack!"
     code = 22
     x = simulate_HardError(msg, code)
     self.assertIsInstance(x, HardError)
     self.assertIn(msg, str(x))
     self.assertIn(msg, x.args)
     self.assertIn(code, x.args)
     self.assertEqual(code, x.code)
     self.assertEqual(msg, x.errortext)
     self.assertEqual(x, HardError(*x.args))  # type: ignore
Exemplo n.º 6
0
 def test_creation_required_from_c(self) -> None:
     msg = "ack!"
     code = 22
     x = simulate_HardError(msg, code)
     self.assertIsInstance(x, HardError)
     self.assertIn(msg, str(x))
     self.assertIn(msg, x.args)
     self.assertIn(code, x.args)
     self.assertEqual(code, x.code)
     self.assertEqual(msg, x.errortext)
     # pyre-fixme[20]: Argument `code` expected.
     self.assertEqual(x, HardError(*x.args))
Exemplo n.º 7
0
    def test_metadata_exceptions(self) -> None:
        meta = gen_metadata(testing.metadata)
        errorName = "testing.HardError"
        self.assertIsNotNone(meta)
        hardError = meta.exceptions[errorName]
        hardErrorClass = gen_metadata(HardError)
        hardErrorClassInstance = gen_metadata(HardError(code=1))

        self.assertEqual(hardError.name, errorName)
        self.assertEqual(hardErrorClass.name, errorName)
        self.assertEqual(hardErrorClassInstance.name, errorName)
        self.assertEqual(len(hardError.fields), 2)

        field = hardError.fields[1]
        _, fieldClass, *rest = hardErrorClass.fields
        _, fieldInstance, *rest = hardErrorClassInstance.fields
        self.assertEqual(field.name, "code")
        self.assertEqual(fieldClass.name, "code")
        self.assertEqual(fieldInstance.name, "code")
        self.assertEqual(field.is_optional, False)
        self.assertEqual(field.type.value, ThriftPrimitiveType.THRIFT_I32_TYPE)
Exemplo n.º 8
0
 def test_serialize_deserialize(self) -> None:
     err = HardError(errortext="err", code=2)
     serialized = serialize_iobuf(err)
     deserialized = deserialize(HardError, serialized)
     self.assertIsNot(err, deserialized)
     self.assertEqual(err, deserialized)