def test_build_with_wrong_type_field(self) -> None: easy_builder = easy_Builder() with self.assertRaises(TypeError): easy_builder.val = "123" # type: ignore easy_builder = easy_Builder() easy_builder.val_list = [ "123", 456, ] # OK now as builder doesn't check list element types with self.assertRaises(TypeError): easy_builder() # caught at build step value_or_error_builder = ValueOrError_Builder() value_or_error_builder.error = ( "wrong!") # OK now as builder takes any type for struct field with self.assertRaises(TypeError): value_or_error_builder() # caught at build step
def test_build_with_wrong_type_field(self) -> None: easy_builder = easy_Builder() with self.assertRaises(TypeError): # pyre-fixme[8]: Attribute has type `Optional[int]`; used as `str`. easy_builder.val = "123" easy_builder = easy_Builder() easy_builder.val_list = [ "123", 456, ] # OK now as builder doesn't check list element types with self.assertRaises(TypeError): easy_builder() # caught at build step value_or_error_builder = ValueOrError_Builder() value_or_error_builder.error = ( "wrong!" # OK now as builder takes any type for struct field ) with self.assertRaises(TypeError): value_or_error_builder() # caught at build step
def test_defaults(self) -> None: easy_builder = easy_Builder() self.assertIsNone(easy_builder.val) self.assertIsNone(easy_builder.val_list) self.assertIsNone(easy_builder.name) self.assertIsNone(easy_builder.an_int) file_builder = File_Builder() self.assertIsNone(file_builder.name) self.assertIsNone(file_builder.permissions) self.assertIsNone(file_builder.type) numerical_builder = numerical_Builder() self.assertIsNone(numerical_builder.int_val) self.assertIsNone(numerical_builder.float_val) self.assertIsNone(numerical_builder.int_list) self.assertIsNone(numerical_builder.float_list) self.assertIsNone(numerical_builder.i64_val)
def test_build_with_builder_fields(self) -> None: easy_builder = easy_Builder() integers_builder = Integers_Builder() digits_builder = Digits_Builder() digits_builder.data = [ _types.Integers.fromValue(123), _types.Integers.fromValue(456), ] integers_builder.digits = digits_builder easy_builder.an_int = integers_builder easy_obj = easy_builder() self.assertIsInstance(easy_obj, _types.easy) an_int_value = easy_obj.an_int.value self.assertIsInstance(an_int_value, _types.Digits) self.assertEqual(len(an_int_value.data), 2) v1, v2 = an_int_value.data self.assertEqual(v1.value, 123) self.assertEqual(v2.value, 456)
def test_build(self) -> None: easy_builder = easy_Builder() easy_builder.val = 42 easy_builder.val_list = [123, 456] easy_builder.name = "foo" easy_builder.an_int = _types.Integers.fromValue(123) easy_obj = easy_builder() self.assertIsInstance(easy_obj, _types.easy) self.assertEqual(easy_obj.val, 42) self.assertEqual(easy_obj.val_list, [123, 456]) self.assertEqual(easy_obj.name, "foo") self.assertEqual(easy_obj.an_int.value, 123) error_builder = HardError_Builder() error_builder.errortext = "oh no!" error_builder.code = 404 error_obj = error_builder() self.assertIsInstance(error_obj, _types.HardError) self.assertEqual(error_obj.errortext, "oh no!") self.assertEqual(error_obj.code, 404)