Exemple #1
0
    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
Exemple #2
0
 def test_nested(self) -> None:
     nested = py3_types.Nested(
         simpleField=py3_types.Simple(
             intField=42,
             strField="simple",
             intList=[1, 2, 3],
             strSet={"hello", "world"},
             strToIntMap={"one": 1, "two": 2},
             color=py3_types.Color.NONE,
         ),
         simpleList=[
             py3_types.Simple(
                 intField=200,
                 strField="face",
                 intList=[4, 5, 6],
                 strSet={"keep", "calm"},
                 strToIntMap={"three": 3, "four": 4},
                 color=py3_types.Color.RED,
             ),
             py3_types.Simple(
                 intField=404,
                 strField="b00k",
                 intList=[7, 8, 9],
                 strSet={"carry", "on"},
                 strToIntMap={"five": 5, "six": 6},
                 color=py3_types.Color.GREEN,
             ),
         ],
         colorToSimpleMap={
             py3_types.Color.BLUE: py3_types.Simple(
                 intField=500,
                 strField="internal",
                 intList=[10],
                 strSet={"server", "error"},
                 strToIntMap={"seven": 7, "eight": 8, "nine": 9},
                 color=py3_types.Color.BLUE,
             )
         },
     )._to_py_deprecated()
     self.assertEqual(nested.simpleField.intField, 42)
     self.assertEqual(nested.simpleList[0].intList, [4, 5, 6])
     self.assertEqual(nested.simpleList[1].strSet, {"carry", "on"})
     self.assertEqual(
         nested.colorToSimpleMap[py_deprecated_types.Color.BLUE].color,
         py_deprecated_types.Color.BLUE,
     )