Ejemplo n.º 1
0
 def test_simple(self) -> None:
     simple = to_py3_struct(
         types.Simple,
         # pyre-fixme[28]: Unexpected keyword argument `name`.
         ttypes.Simple(
             intField=42,
             strField="simple",
             intList=[1, 2, 3],
             strSet={"hello", "world"},
             strToIntMap={
                 "one": 1,
                 "two": 2
             },
             color=ttypes.Color.GREEN,
             name="myname",
         ),
     )
     self.assertEqual(simple.intField, 42)
     self.assertEqual(simple.strField, "simple")
     self.assertEqual(simple.intList, [1, 2, 3])
     self.assertEqual(simple.strSet, {"hello", "world"})
     self.assertEqual(simple.strToIntMap, {"one": 1, "two": 2})
     self.assertEqual(simple.color, types.Color.GREEN)
     # pyre-fixme[16]: `Simple` has no attribute `name_`.
     self.assertEqual(simple.name_, "myname")
Ejemplo n.º 2
0
 def test_should_return_self(self) -> None:
     simple = py_deprecated_types.Simple()
     self.assertIs(
         simple,
         to_py_struct(
             py_deprecated_types.Simple,
             simple,
         ),
     )
Ejemplo n.º 3
0
 def test_complex_union(self) -> None:
     complex_union = py_deprecated_types.Union(
         simpleField=py_deprecated_types.Simple(
             intField=42,
             strField="simple",
             intList=[1, 2, 3],
             strSet={"hello", "world"},
             strToIntMap={
                 "one": 1,
                 "two": 2
             },
             color=py_deprecated_types.Color.NONE,
         ))._to_python()
     self.assertEqual(complex_union.type, python_types.Union.Type.simple_)
     self.assertEqual(complex_union.simple_.intField, 42)
Ejemplo n.º 4
0
 def test_complex_union(self) -> None:
     complex_union = to_py3_struct(
         types.Union,
         ttypes.Union(simpleField=ttypes.Simple(
             intField=42,
             strField="simple",
             intList=[1, 2, 3],
             strSet={"hello", "world"},
             strToIntMap={
                 "one": 1,
                 "two": 2
             },
             color=ttypes.Color.NONE,
         )),
     )
     self.assertEqual(complex_union.type, types.Union.Type.simpleField)
     self.assertEqual(complex_union.simpleField.intField, 42)
Ejemplo n.º 5
0
 def test_simple(self) -> None:
     simple = py_deprecated_types.Simple(
         intField=42,
         strField="simple",
         intList=[1, 2, 3],
         strSet={"hello", "world"},
         strToIntMap={
             "one": 1,
             "two": 2
         },
         color=py_deprecated_types.Color.GREEN,
         name="myname",
     )._to_python()
     self.assertEqual(simple.intField, 42)
     self.assertEqual(simple.strField, "simple")
     self.assertEqual(simple.intList, [1, 2, 3])
     self.assertEqual(simple.strSet, {"hello", "world"})
     self.assertEqual(simple.strToIntMap, {"one": 1, "two": 2})
     self.assertEqual(simple.color, python_types.Color.GREEN)
     self.assertEqual(simple.name_, "myname")
Ejemplo n.º 6
0
 def test_simple(self) -> None:
     simple = to_py3_struct(
         types.Simple,
         ttypes.Simple(
             intField=42,
             strField="simple",
             intList=[1, 2, 3],
             strSet={"hello", "world"},
             strToIntMap={
                 "one": 1,
                 "two": 2
             },
             color=ttypes.Color.GREEN,
         ),
     )
     self.assertEqual(simple.intField, 42)
     self.assertEqual(simple.strField, "simple")
     self.assertEqual(simple.intList, [1, 2, 3])
     self.assertEqual(simple.strSet, {"hello", "world"})
     self.assertEqual(simple.strToIntMap, {"one": 1, "two": 2})
     self.assertEqual(simple.color, types.Color.GREEN)
Ejemplo n.º 7
0
 def test_nested(self) -> None:
     nested = py_deprecated_types.Nested(
         simpleField=py_deprecated_types.Simple(
             intField=42,
             strField="simple",
             intList=[1, 2, 3],
             strSet={"hello", "world"},
             strToIntMap={
                 "one": 1,
                 "two": 2
             },
             color=py_deprecated_types.Color.NONE,
             name="myname",
         ),
         simpleList=[
             py_deprecated_types.Simple(
                 intField=200,
                 strField="face",
                 intList=[4, 5, 6],
                 strSet={"keep", "calm"},
                 strToIntMap={
                     "three": 3,
                     "four": 4
                 },
                 color=py_deprecated_types.Color.RED,
                 name="myname",
             ),
             py_deprecated_types.Simple(
                 intField=404,
                 strField="b00k",
                 intList=[7, 8, 9],
                 strSet={"carry", "on"},
                 strToIntMap={
                     "five": 5,
                     "six": 6
                 },
                 color=py_deprecated_types.Color.GREEN,
                 name="myname",
             ),
         ],
         colorToSimpleMap={
             py_deprecated_types.Color.BLUE:
             py_deprecated_types.Simple(
                 intField=500,
                 strField="internal",
                 intList=[10],
                 strSet={"server", "error"},
                 strToIntMap={
                     "seven": 7,
                     "eight": 8,
                     "nine": 9
                 },
                 color=py_deprecated_types.Color.BLUE,
                 name="myname",
             )
         },
     )._to_python()
     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[python_types.Color.BLUE].color,
         python_types.Color.BLUE,
     )
Ejemplo n.º 8
0
 def test_nested(self) -> None:
     nested = to_py3_struct(
         types.Nested,
         ttypes.Nested(
             # pyre-fixme[28]: Unexpected keyword argument `name`.
             simpleField=ttypes.Simple(
                 intField=42,
                 strField="simple",
                 intList=[1, 2, 3],
                 strSet={"hello", "world"},
                 strToIntMap={
                     "one": 1,
                     "two": 2
                 },
                 color=ttypes.Color.NONE,
                 name="myname",
             ),
             simpleList=[
                 # pyre-fixme[28]: Unexpected keyword argument `name`.
                 ttypes.Simple(
                     intField=200,
                     strField="face",
                     intList=[4, 5, 6],
                     strSet={"keep", "calm"},
                     strToIntMap={
                         "three": 3,
                         "four": 4
                     },
                     color=ttypes.Color.RED,
                     name="myname",
                 ),
                 # pyre-fixme[28]: Unexpected keyword argument `name`.
                 ttypes.Simple(
                     intField=404,
                     strField="b00k",
                     intList=[7, 8, 9],
                     strSet={"carry", "on"},
                     strToIntMap={
                         "five": 5,
                         "six": 6
                     },
                     color=ttypes.Color.GREEN,
                     name="myname",
                 ),
             ],
             colorToSimpleMap={
                 # pyre-fixme[28]: Unexpected keyword argument `name`.
                 ttypes.Color.BLUE:
                 ttypes.Simple(
                     intField=500,
                     strField="internal",
                     intList=[10],
                     strSet={"server", "error"},
                     strToIntMap={
                         "seven": 7,
                         "eight": 8,
                         "nine": 9
                     },
                     color=ttypes.Color.BLUE,
                     name="myname",
                 )
             },
         ),
     )
     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[types.Color.BLUE].color,
                      types.Color.BLUE)