Beispiel #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")
Beispiel #2
0
 def test_optional_defaults(self) -> None:
     converted = to_py3_struct(
         types.OptionalDefaultsStruct,
         ttypes.OptionalDefaultsStruct(),
     )
     # pyre-fixme[6]: Expected `HasIsSet[Variable[thrift.py3.types._T]]` for 1st
     #  param but got `OptionalDefaultsStruct`.
     self.assertFalse(Struct.isset(converted).sillyString)
     # pyre-fixme[6]: Expected `HasIsSet[Variable[thrift.py3.types._T]]` for 1st
     #  param but got `OptionalDefaultsStruct`.
     self.assertFalse(Struct.isset(converted).sillyColor)
Beispiel #3
0
    async def test_journal_stream_changes_since(self) -> None:
        """
        Verify that the streamChangesSince API reports all the changed
        files/directories across update.
        """

        with self.get_thrift_client_legacy() as client:
            before = client.getCurrentJournalPosition(self.mount_path_bytes)

        self.repo.update(self.commit1)

        self.repo.write_file("hello.txt", "hola\n")
        self.repo.write_file("bar.txt", "bar\n")

        added = set()
        removed = set()
        modified = set()

        async with self.get_thrift_client() as client:
            params = StreamChangesSinceParams(
                mountPoint=self.mount_path_bytes,
                fromPosition=to_py3_struct(JournalPosition_py3, before),
            )
            result, changes = await client.streamChangesSince(params)
            async for change in changes:
                path = change.name.decode()
                if path.startswith(".hg"):
                    continue

                status = change.status
                if status == ScmFileStatus.ADDED:
                    added.add(path)
                elif status == ScmFileStatus.MODIFIED:
                    modified.add(path)
                else:
                    self.assertEqual(status, ScmFileStatus.REMOVED)
                    removed.add(path)

        # Files not in commits:
        self.assertIn("hello.txt", modified)
        self.assertIn("bar.txt", added)

        # Files in commits:
        self.assertIn("foo/bar.txt", removed)

        # The directory is also removed.
        self.assertIn("foo", removed)

        self.assertNotEqual(
            before, to_py_struct(JournalPosition_py, result.toPosition))
Beispiel #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)
 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)
Beispiel #6
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)
Beispiel #7
0
 def test_union_with_containers(self) -> None:
     union_with_list = to_py3_struct(types.Union,
                                     ttypes.Union(intList=[1, 2, 3]))
     self.assertEqual(union_with_list.type, types.Union.Type.intList)
     self.assertEqual(union_with_list.value, [1, 2, 3])
Beispiel #8
0
 def test_union_with_py3_name_annotation(self) -> None:
     # pyre-fixme[28]: Unexpected keyword argument `name`.
     simple_union = to_py3_struct(types.Union, ttypes.Union(name="myname"))
     self.assertEqual(simple_union.type, types.Union.Type.name_)
     self.assertEqual(simple_union.value, "myname")
Beispiel #9
0
 def test_simple_union(self) -> None:
     simple_union = to_py3_struct(types.Union, ttypes.Union(intField=42))
     self.assertEqual(simple_union.type, types.Union.Type.intField)
     self.assertEqual(simple_union.value, 42)
Beispiel #10
0
 def test_union_with_py3_name_annotation(self) -> None:
     simple_union = to_py3_struct(types.Union, ttypes.Union(name="myname"))
     self.assertEqual(simple_union.type, types.Union.Type.name_)
     self.assertEqual(simple_union.value, "myname")