Exemplo n.º 1
0
    def testEncodeWithEmptyContext(self) -> None:
        ctx = ResultContext()
        obj = {"k1": "v1", "k2": "v2"}
        fmt = 1 # YAML

        # This test is here for backward compatibility purposes,
        # in case someone was relying on encoding contexts this way
        data = ctx.ctx.encode(obj, fmt)
        other_data = ctx.encode(obj, fmt)
        self.assertDictEqual(obj, decode(data, format = fmt).load())
        self.assertDictEqual(obj, decode(other_data, format = fmt).load())
Exemplo n.º 2
0
    def testEncodeWithEmptyContext(self) -> None:
        ctx = ResultContext()
        obj = {"k1": "v1", "k2": "v2"}
        fmt = 1  # YAML

        data = ctx.ctx.encode(obj, fmt)
        self.assertDictEqual(obj, decode(data, format=fmt).load())
Exemplo n.º 3
0
 def __init__(self, grpc_response: ParseResponse = None) -> None:
     if grpc_response:
         if grpc_response.errors:
             raise ResponseError("\n".join(
                 [error.text for error in grpc_response.errors])
             )
         self._response = grpc_response
         self.ctx = decode(grpc_response.uast, format=0)
     else:
         self._response = None
         self.ctx = uast()
Exemplo n.º 4
0
    def testBinaryEncodeDecodePythonContext(self) -> None:
        # Binary encoding should be invertible
        # C++ memory context
        ctxC = self._parse_fixture()
        # Python memory context
        pyDict = ctxC.root.get()
        ctxPy = bblfsh.context(pyDict)
        encoded = ctxPy.encode(fmt = 0) # Binary encoding
        decoded = decode(encoded, format = 0)

        self.assertEqual(pyDict, decoded.load())
Exemplo n.º 5
0
 def testInvalidDecodeBytes(self) -> None:
     with self.assertRaises(RuntimeError):
         decode(b'', format = 0)
     with self.assertRaises(RuntimeError):
         decode(b'abcdef', format = 0)