def test_optional_type(self) -> None: self.assertIsNone(to_python_struct(python_types.Simple, None)) self.assertIsNone( to_python_struct(python_types.Simple, py3_types.Nested().optionalSimple)) with self.assertRaises(AttributeError): # make sure pyre complains # pyre-ignore[16]: Optional type has no attribute `intField`. to_python_struct(python_types.Simple, py3_types.Nested().optionalSimple).intField
def test_should_return_self(self) -> None: simple = python_types.Simple() self.assertIs( simple, to_python_struct( python_types.Simple, simple, ), )
def test_union_with_mismatching_field(self) -> None: po = to_python_struct( python_types.Potahto, py_deprecated_types.Potayto(po=42, ), ) self.assertEqual(po.type, python_types.Potahto.Type.po) self.assertEqual(po.value, 42) tah = to_python_struct( python_types.Potahto, py_deprecated_types.Potayto(tay="tay", ), ) self.assertEqual(tah.type, python_types.Potahto.Type.EMPTY) to = to_python_struct( python_types.Potahto, py_deprecated_types.Potayto(to=True, ), ) self.assertEqual(to.type, python_types.Potahto.Type.to) self.assertEqual(to.value, True)
def test_struct_with_mismatching_field(self) -> None: tomayto = py_deprecated_types.Tomayto( to=42, mayto="blah", ) tomahto = to_python_struct( python_types.Tomahto, tomayto, ) self.assertEqual(tomahto.to, 42) self.assertEqual(tomahto.mahto, "mahto")