Example #1
0
    def test_union_with_mismatching_field(self) -> None:
        po = to_py_struct(
            py_deprecated_types.Potahto,
            python_types.Potayto(
                po=42,
            ),
        )
        self.assertEqual(po.getType(), py_deprecated_types.Potahto.PO)
        self.assertEqual(po.get_po(), 42)

        tah = to_py_struct(
            py_deprecated_types.Potahto,
            python_types.Potayto(
                tay="tay",
            ),
        )
        self.assertEqual(tah.getType(), py_deprecated_types.Potahto.__EMPTY__)

        to = to_py_struct(
            py_deprecated_types.Potahto,
            python_types.Potayto(
                to=True,
            ),
        )
        self.assertEqual(to.getType(), py_deprecated_types.Potahto.TO)
        self.assertEqual(to.get_to(), True)
Example #2
0
    def test_optional_type(self) -> None:
        self.assertIsNone(
            to_py_struct(
                py_deprecated_types.Simple, python_types.Nested().optionalSimple
            )
        )

        with self.assertRaises(AttributeError):
            # make sure pyre complains
            # pyre-ignore[16]: Optional type has no attribute `intField`.
            to_py_struct(
                py_deprecated_types.Simple, python_types.Nested().optionalSimple
            ).intField
Example #3
0
 def test_should_return_self(self) -> None:
     simple = py_deprecated_types.Simple()
     self.assertIs(
         simple,
         to_py_struct(
             py_deprecated_types.Simple,
             simple,
         ),
     )
Example #4
0
 def test_struct_with_mismatching_field(self) -> None:
     tomayto = python_types.Tomayto(
         to=42,
         mayto="blah",
     )
     tomahto = to_py_struct(
         py_deprecated_types.Tomahto,
         tomayto,
     )
     self.assertEqual(tomahto.to, 42)
     self.assertIsNone(tomahto.mahto)
Example #5
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))
Example #6
0
 def test_complex_union(self) -> None:
     complex_union = to_py_struct(
         ttypes.Union,
         types.Union(simpleField=types.Simple(
             intField=42,
             strField="simple",
             intList=[1, 2, 3],
             strSet={"hello", "world"},
             strToIntMap={
                 "one": 1,
                 "two": 2
             },
             color=types.Color.NONE,
         )),
     )
     self.assertEqual(complex_union.get_simpleField().intField, 42)
Example #7
0
 def test_simple(self) -> None:
     simple = to_py_struct(
         ttypes.Simple,
         types.Simple(
             intField=42,
             strField="simple",
             intList=[1, 2, 3],
             strSet={"hello", "world"},
             strToIntMap={
                 "one": 1,
                 "two": 2
             },
             color=types.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, ttypes.Color.GREEN)
 def test_nested(self) -> None:
     nested = to_py_struct(
         ttypes.Nested,
         types.Nested(
             simpleField=types.Simple(
                 intField=42,
                 strField="simple",
                 intList=[1, 2, 3],
                 strSet={"hello", "world"},
                 strToIntMap={
                     "one": 1,
                     "two": 2
                 },
                 color=types.Color.NONE,
             ),
             simpleList=[
                 types.Simple(
                     intField=200,
                     strField="face",
                     intList=[4, 5, 6],
                     strSet={"keep", "calm"},
                     strToIntMap={
                         "three": 3,
                         "four": 4
                     },
                     color=types.Color.RED,
                 ),
                 types.Simple(
                     intField=404,
                     strField="b00k",
                     intList=[7, 8, 9],
                     strSet={"carry", "on"},
                     strToIntMap={
                         "five": 5,
                         "six": 6
                     },
                     color=types.Color.GREEN,
                 ),
             ],
             colorToSimpleMap={
                 types.Color.BLUE:
                 types.Simple(
                     intField=500,
                     strField="internal",
                     intList=[10],
                     strSet={"server", "error"},
                     strToIntMap={
                         "seven": 7,
                         "eight": 8,
                         "nine": 9
                     },
                     color=types.Color.BLUE,
                 )
             },
         ),
     )
     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[ttypes.Color.BLUE].color,
                      ttypes.Color.BLUE)
 def test_union_with_containers(self) -> None:
     union_with_list = to_py_struct(ttypes.Union,
                                    types.Union(intList=[1, 2, 3]))
     self.assertEqual(union_with_list.get_intList(), [1, 2, 3])
 def test_simple_union(self) -> None:
     simple_union = to_py_struct(ttypes.Union, types.Union(intField=42))
     self.assertEqual(simple_union.get_intField(), 42)
Example #11
0
 def test_none(self) -> None:
     self.assertIsNone(to_py_struct(py_deprecated_types.Simple, None))