Ejemplo n.º 1
0
    def testCallWithFcnDef(self):
        x = EngineConfig("test", Method.MAP, AvroInt(), AvroString(), [], [Call("sort", [Ref("array"), FcnDef([{"x": AvroInt()}, {"y": AvroString()}], AvroNull(), [LiteralNull()])])], [], {}, None, None, {}, {}, None, None, None, {}, {})
        y = jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"sort":["array",{"params": [{"x": "int"}, {"y": "string"}], "ret": "null", "do": [null]}]}]
}''')
        self.assertEqual(
        EngineConfig(
        "test",
        Method.MAP,
        AvroInt(),
        AvroString(),
        [],
        [Call("sort", [Ref("array"), FcnDef([{"x": AvroInt()}, {"y": AvroString()}], AvroNull(), [LiteralNull()])])],
        [],
        {},
        None,
        None,
        {},
        {},
        None,
        None,
        None,
        {},
        {}),
        jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"sort":["array",{"params": [{"x": "int"}, {"y": "string"}], "ret": "null", "do": [null]}]}]
}'''))
Ejemplo n.º 2
0
    def testCallWithFcnDef(self):
        x = EngineConfig("test", Method.MAP, AvroInt(), AvroString(), [], [
            Call("sort", [
                Ref("array"),
                FcnDef([{
                    "x": AvroInt()
                }, {
                    "y": AvroString()
                }], AvroNull(), [LiteralNull()])
            ])
        ], [], {}, None, None, {}, {}, None, None, None, {}, {})
        y = jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"sort":["array",{"params": [{"x": "int"}, {"y": "string"}], "ret": "null", "do": [null]}]}]
}''')
        self.assertEqual(
            EngineConfig("test", Method.MAP, AvroInt(), AvroString(), [], [
                Call("sort", [
                    Ref("array"),
                    FcnDef([{
                        "x": AvroInt()
                    }, {
                        "y": AvroString()
                    }], AvroNull(), [LiteralNull()])
                ])
            ], [], {}, None, None, {}, {}, None, None, None, {}, {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"sort":["array",{"params": [{"x": "int"}, {"y": "string"}], "ret": "null", "do": [null]}]}]
}'''))
Ejemplo n.º 3
0
    def testCellSet(self):
        self.assertEqual(
        EngineConfig(
        "test",
        Method.MAP,
        AvroInt(),
        AvroString(),
        [],
        [CellTo("c", [], LiteralDouble(2.2))],
        [],
        {},
        None,
        None,
        {},
        {},
        None,
        None,
        None,
        {},
        {}),
        jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"cell":"c","to":2.2}]
}'''))
        self.assertEqual(
        EngineConfig(
        "test",
        Method.MAP,
        AvroInt(),
        AvroString(),
        [],
        [CellTo("c", [Ref("a"), LiteralInt(1), LiteralString("b")], LiteralDouble(2.2))],
        [],
        {},
        None,
        None,
        {},
        {},
        None,
        None,
        None,
        {},
        {}),
        jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"cell":"c","path":["a",1,{"string":"b"}],"to":2.2}]
}'''))
Ejemplo n.º 4
0
    def testDoUntil(self):
        self.assertEqual(
          EngineConfig(
          "test",
          Method.MAP,
          AvroInt(),
          AvroString(),
          [],
          [DoUntil([Call("+", [LiteralInt(2), LiteralInt(2)])], LiteralBoolean(True))],
          [],
          {},
          None,
          None,
          {},
          {},
          None,
          None,
          None,
          {},
          {}),
          jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"do":[{"+":[2,2]}],"until":true}]
}'''))
Ejemplo n.º 5
0
 def engineConfig(self):
     if self._engineConfig is None:
         try:
             self._engineConfig = jsonToAst(self.obj)
         except (AvroException, SchemaParseException, PFAException) as err:
             raise InspectorError(str(err))
     return self._engineConfig
Ejemplo n.º 6
0
    def testBase64(self):
        self.assertEqual(
        EngineConfig(
        "test",
        Method.MAP,
        AvroInt(),
        AvroString(),
        [],
        [LiteralBase64("hello".encode("utf-8"))],
        [],
        {},
        None,
        None,
        {},
        {},
        None,
        None,
        None,
        {},
        {}),
        jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"base64": "aGVsbG8="}]
}'''))
Ejemplo n.º 7
0
    def testCallWithFcn(self):
        self.assertEqual(
            EngineConfig(
            "test",
            Method.MAP,
            AvroInt(),
            AvroString(),
            [],
            [Call("sort", [Ref("array"), FcnRef("byname")])],
            [],
            {},
            None,
            None,
            {},
            {},
            None,
            None,
            None,
            {},
            {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"sort":["array",{"fcn": "byname"}]}]
}'''))
Ejemplo n.º 8
0
    def testString(self):
        self.assertEqual(
        EngineConfig(
        "test",
        Method.MAP,
        AvroInt(),
        AvroString(),
        [],
        [LiteralString("hello")],
        [],
        {},
        None,
        None,
        {},
        {},
        None,
        None,
        None,
        {},
        {}),
        jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"string": "hello"}]
}'''))
Ejemplo n.º 9
0
    def testForeach(self):
        self.assertEqual(
          EngineConfig(
          "test",
          Method.MAP,
          AvroInt(),
          AvroString(),
          [],
          [Foreach("x", Literal(AvroArray(AvroInt()), '''[1, 2, 3]'''), [Ref("x")], False)],
          [],
          {},
          None,
          None,
          {},
          {},
          None,
          None,
          None,
          {},
          {}),
          jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"foreach":"x","in":{"type":{"type":"array","items":"int"},"value":[1,2,3]},"do":["x"],"seq":false}]
}'''))
Ejemplo n.º 10
0
    def testPoolGet(self):
        self.assertEqual(
        EngineConfig(
        "test",
        Method.MAP,
        AvroInt(),
        AvroString(),
        [],
        [PoolGet("p", [Ref("a"), LiteralInt(1), LiteralString("b")])],
        [],
        {},
        None,
        None,
        {},
        {},
        None,
        None,
        None,
        {},
        {}),
        jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"pool":"p","path":["a",1,{"string":"b"}]}]
}'''))
Ejemplo n.º 11
0
    def testSet(self):
        self.assertEqual(
        EngineConfig(
        "test",
        Method.MAP,
        AvroInt(),
        AvroString(),
        [],
        [SetVar({"x": LiteralInt(3), "y": LiteralInt(4)})],
        [],
        {},
        None,
        None,
        {},
        {},
        None,
        None,
        None,
        {},
        {}),
        jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"set":{"x":3,"y":4}}]
}'''))
Ejemplo n.º 12
0
    def testIf(self):
        self.assertEqual(
        EngineConfig(
        "test",
        Method.MAP,
        AvroInt(),
        AvroString(),
        [],
        [If(LiteralBoolean(True), [Ref("x")], None), If(LiteralBoolean(True), [Ref("x")], [Ref("y")])],
        [],
        {},
        None,
        None,
        {},
        {},
        None,
        None,
        None,
        {},
        {}),
        jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"if":true,"then":["x"]}, {"if":true,"then":["x"],"else":["y"]}]
}'''))
Ejemplo n.º 13
0
    def testLiteral(self):
        self.assertEqual(
        EngineConfig(
        "test",
        Method.MAP,
        AvroInt(),
        AvroString(),
        [],
        [Literal(AvroRecord([AvroField("one", AvroInt()), AvroField("two", AvroDouble()), AvroField("three", AvroString())], "SimpleRecord"), '''{"one": 1, "two": 2.2, "three": "THREE"}''')],
        [],
        {},
        None,
        None,
        {},
        {},
        None,
        None,
        None,
        {},
        {}),
        jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"type":{"type":"record","name":"SimpleRecord","fields":[{"name":"one","type":"int"},{"name":"two","type":"double"},{"name":"three","type":"string"}]},"value":{"one":1,"two":2.2,"three":"THREE"}}]
}'''))
Ejemplo n.º 14
0
    def testForkeyval(self):
        self.assertEqual(
          EngineConfig(
          "test",
          Method.MAP,
          AvroInt(),
          AvroString(),
          [],
          [Forkeyval("k", "v", Literal(AvroMap(AvroInt()), '''{"one": 1, "two": 2, "three": 3}'''), [Ref("k")])],
          [],
          {},
          None,
          None,
          {},
          {},
          None,
          None,
          None,
          {},
          {}),
          jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"forkey":"k","forval":"v","in":{"type":{"type":"map","values":"int"},"value":{"one":1,"two":2,"three":3}},"do":["k"]}]
}'''))
Ejemplo n.º 15
0
    def testFor(self):
        self.assertEqual(
          EngineConfig(
          "test",
          Method.MAP,
          AvroInt(),
          AvroString(),
          [],
          [For({"i": LiteralInt(0)}, Call("<", [Ref("i"), LiteralInt(10)]), {"i": Call("+", [Ref("i"), LiteralInt(1)])}, [Ref("i")], False)],
          [],
          {},
          None,
          None,
          {},
          {},
          None,
          None,
          None,
          {},
          {}),
          jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"for":{"i":0},"while":{"<":["i",10]},"step":{"i":{"+":["i",1]}},"do":["i"]}]
}'''))
Ejemplo n.º 16
0
 def engineConfig(self):
     if self._engineConfig is None:
         try:
             self._engineConfig = jsonToAst(self.obj)
         except (AvroException, SchemaParseException, PFAException) as err:
             raise InspectorError(str(err))
     return self._engineConfig
Ejemplo n.º 17
0
    def testFloat(self):
      self.assertEqual(
      EngineConfig(
      "test",
      Method.MAP,
      AvroInt(),
      AvroString(),
      [],
      [LiteralFloat(2.5)],
      [],
      {},
      None,
      None,
      {},
      {},
      None,
      None,
      None,
      {},
      {}),
      jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"float": 2.5}]
}'''))
Ejemplo n.º 18
0
    def testError(self):
        self.assertEqual(
          EngineConfig(
          "test",
          Method.MAP,
          AvroInt(),
          AvroString(),
          [],
          [Error("hello", None), Error("hello", -3)],
          [],
          {},
          None,
          None,
          {},
          {},
          None,
          None,
          None,
          {},
          {}),
          jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"error":"hello"}, {"error":"hello","code":-3}]
}'''))
Ejemplo n.º 19
0
    def testDouble(self):
        self.assertEqual(
        EngineConfig(
        "test",
        Method.MAP,
        AvroInt(),
        AvroString(),
        [],
        [LiteralDouble(2.2)],
        [],
        {},
        None,
        None,
        {},
        {},
        None,
        None,
        None,
        {},
        {}),
        jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [2.2]
}'''))
Ejemplo n.º 20
0
    def testDo(self):
        self.assertEqual(
        EngineConfig(
        "test",
        Method.MAP,
        AvroInt(),
        AvroString(),
        [],
        [Do([Ref("x"), Ref("y"), Ref("z")])],
        [],
        {},
        None,
        None,
        {},
        {},
        None,
        None,
        None,
        {},
        {}),
        jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"do":["x","y","z"]}]
}'''))
Ejemplo n.º 21
0
    def testLog(self):
        self.assertEqual(
          EngineConfig(
          "test",
          Method.MAP,
          AvroInt(),
          AvroString(),
          [],
          [Log([LiteralString("hello")], None),
           Log([LiteralString("hello")], "DEBUG"),
           Log([Call("+", [LiteralInt(2), LiteralInt(2)])], None)],
          [],
          {},
          None,
          None,
          {},
          {},
          None,
          None,
          None,
          {},
          {}),
          jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"log":[{"string":"hello"}]},
             {"log":[{"string":"hello"}],"namespace":"DEBUG"},
             {"log":[{"+":[2,2]}]}]
}'''))
Ejemplo n.º 22
0
    def testDefineFunction(self):
        self.assertEqual(
            EngineConfig(
            "test",
            Method.MAP,
            AvroInt(),
            AvroString(),
            [],
            [Call("+", [LiteralInt(2), LiteralInt(2)])],
            [],
            {"f": FcnDef([{"x": AvroInt()}, {"y": AvroString()}], AvroNull(), [LiteralNull()])},
            None,
            None,
            {},
            {},
            None,
            None,
            None,
            {},
            {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"+": [2, 2]}],
  "fcns": {"f": {"params":[{"x":"int"},{"y":"string"}],"ret":"null","do":[null]}}
}'''))
Ejemplo n.º 23
0
    def testCell(self):
        self.assertEqual(
            EngineConfig(
            "test",
            Method.MAP,
            AvroInt(),
            AvroString(),
            [],
            [Call("+", [LiteralInt(2), LiteralInt(2)])],
            [],
            {},
            None,
            None,
            {"private": Cell(AvroArray(AvroString()), "[]", False, False, CellPoolSource.EMBEDDED)},
            {},
            None,
            None,
            None,
            {},
            {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"+": [2, 2]}],
  "cells":{"private":{"type":{"type": "array", "items": "string"},"init":[],"shared":false,"rollback":false}}
}'''))
Ejemplo n.º 24
0
    def testBoolean(self):
        self.assertEqual(
        EngineConfig(
        "test",
        Method.MAP,
        AvroInt(),
        AvroString(),
        [],
        [LiteralBoolean(True), LiteralBoolean(False)],
        [],
        {},
        None,
        None,
        {},
        {},
        None,
        None,
        None,
        {},
        {}),
        jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [true, false]
}'''))
Ejemplo n.º 25
0
    def testCast(self):
        self.assertEqual(
          EngineConfig(
          "test",
          Method.MAP,
          AvroInt(),
          AvroString(),
          [],
          [CastBlock(LiteralInt(3), [CastCase(AvroString(), "x", [Ref("x")]), CastCase(AvroInt(), "x", [Ref("x")])], True)],
          [],
          {},
          None,
          None,
          {},
          {},
          None,
          None,
          None,
          {},
          {}),
          jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"cast":{"int":3},"cases":[{"as":"string","named":"x","do":["x"]},{"as":"int","named":"x","do":["x"]}],"partial":true}]
}'''))
Ejemplo n.º 26
0
    def testCallFunction(self):
        self.assertEqual(
            EngineConfig(
            "test",
            Method.MAP,
            AvroInt(),
            AvroString(),
            [],
            [Call("+", [LiteralInt(2), LiteralInt(2)])],
            [],
            {},
            None,
            None,
            {},
            {},
            None,
            None,
            None,
            {},
            {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"+": [2, 2]}]
}'''))
Ejemplo n.º 27
0
    def testNewRecord(self):
        self.assertEqual(
        EngineConfig(
        "test",
        Method.MAP,
        AvroInt(),
        AvroString(),
        [],
        [NewObject({"one": LiteralInt(1), "two": LiteralDouble(2.2), "three": LiteralString("THREE")},
                       AvroRecord([AvroField("one", AvroInt()), AvroField("two", AvroDouble()), AvroField("three", AvroString())], "SimpleRecord"), AvroTypeBuilder())],
        [],
        {},
        None,
        None,
        {},
        {},
        None,
        None,
        None,
        {},
        {}),
        jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"new":{"one":{"int":1},"two":2.2,"three":{"string":"THREE"}},"type":{"type":"record","name":"SimpleRecord","fields":[{"name":"one","type":"int"},{"name":"two","type":"double"},{"name":"three","type":"string"}]}}]
}'''))
Ejemplo n.º 28
0
    def testNewArray(self):
        self.assertEqual(
        EngineConfig(
        "test",
        Method.MAP,
        AvroInt(),
        AvroString(),
        [],
        [NewArray([LiteralInt(1), LiteralInt(2), LiteralInt(3)], AvroArray(AvroInt()), AvroTypeBuilder())],
        [],
        {},
        None,
        None,
        {},
        {},
        None,
        None,
        None,
        {},
        {}),
        jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"new":[1,2,3],"type":{"type":"array","items":"int"}}]
}'''))
Ejemplo n.º 29
0
    def testLong(self):
        self.assertEqual(
        EngineConfig(
        "test",
        Method.MAP,
        AvroLong(),
        AvroString(),
        [],
        [LiteralLong(2)],
        [],
        {},
        None,
        None,
        {},
        {},
        None,
        None,
        None,
        {},
        {}),
        jsonToAst('''{
  "name": "test",
  "input": "long",
  "output": "string",
  "action": [{"long": 2}]
}'''))
Ejemplo n.º 30
0
    def testFloat(self):
        self.assertEqual(
            EngineConfig("test", Method.MAP, AvroInt(), AvroString(), [],
                         [LiteralFloat(2.5)], [], {}, None, None, {}, {}, None,
                         None, None, {}, {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"float": 2.5}]
}'''))
Ejemplo n.º 31
0
    def testDoc(self):
        self.assertEqual(
            EngineConfig("test", Method.MAP, AvroInt(), AvroString(), [],
                         [Doc("hello")], [], {}, None, None, {}, {}, None,
                         None, None, {}, {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"doc":"hello"}]
}'''))
Ejemplo n.º 32
0
    def testDo(self):
        self.assertEqual(
            EngineConfig("test", Method.MAP, AvroInt(), AvroString(), [],
                         [Do([Ref("x"), Ref("y"), Ref("z")])], [], {}, None,
                         None, {}, {}, None, None, None, {}, {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"do":["x","y","z"]}]
}'''))
Ejemplo n.º 33
0
    def testLong(self):
        self.assertEqual(
            EngineConfig("test", Method.MAP, AvroLong(), AvroString(), [],
                         [LiteralLong(2)], [], {}, None, None, {}, {}, None,
                         None, None, {}, {}),
            jsonToAst('''{
  "name": "test",
  "input": "long",
  "output": "string",
  "action": [{"long": 2}]
}'''))
Ejemplo n.º 34
0
    def testDouble(self):
        self.assertEqual(
            EngineConfig("test", Method.MAP, AvroInt(), AvroString(), [],
                         [LiteralDouble(2.2)], [], {}, None, None, {}, {},
                         None, None, None, {}, {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [2.2]
}'''))
Ejemplo n.º 35
0
    def testIf(self):
        self.assertEqual(
            EngineConfig("test", Method.MAP, AvroInt(), AvroString(), [], [
                If(LiteralBoolean(True), [Ref("x")], None),
                If(LiteralBoolean(True), [Ref("x")], [Ref("y")])
            ], [], {}, None, None, {}, {}, None, None, None, {}, {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"if":true,"then":["x"]}, {"if":true,"then":["x"],"else":["y"]}]
}'''))
Ejemplo n.º 36
0
    def testWhile(self):
        self.assertEqual(
            EngineConfig("test", Method.MAP, AvroInt(), AvroString(), [], [
                While(LiteralBoolean(True),
                      [Call("+", [LiteralInt(2), LiteralInt(2)])])
            ], [], {}, None, None, {}, {}, None, None, None, {}, {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"while":true,"do":[{"+":[2,2]}]}]
}'''))
Ejemplo n.º 37
0
    def testForeach(self):
        self.assertEqual(
            EngineConfig("test", Method.MAP, AvroInt(), AvroString(), [], [
                Foreach("x", Literal(AvroArray(AvroInt()), '''[1, 2, 3]'''),
                        [Ref("x")], False)
            ], [], {}, None, None, {}, {}, None, None, None, {}, {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"foreach":"x","in":{"type":{"type":"array","items":"int"},"value":[1,2,3]},"do":["x"],"seq":false}]
}'''))
Ejemplo n.º 38
0
    def testCallWithFcn(self):
        self.assertEqual(
            EngineConfig(
                "test", Method.MAP, AvroInt(), AvroString(), [],
                [Call("sort", [Ref("array"), FcnRef("byname")])], [], {}, None,
                None, {}, {}, None, None, None, {}, {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"sort":["array",{"fcn": "byname"}]}]
}'''))
Ejemplo n.º 39
0
    def testBase64(self):
        self.assertEqual(
            EngineConfig(
                "test", Method.MAP, AvroInt(), AvroString(), [],
                [LiteralBase64(bytesToString("hello".encode("utf-8")))], [],
                {}, None, None, {}, {}, None, None, None, {}, {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"base64": "aGVsbG8="}]
}'''))
Ejemplo n.º 40
0
    def testError(self):
        self.assertEqual(
            EngineConfig("test", Method.MAP, AvroInt(), AvroString(), [],
                         [Error("hello", None),
                          Error("hello", -3)], [], {}, None, None, {}, {},
                         None, None, None, {}, {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"error":"hello"}, {"error":"hello","code":-3}]
}'''))
Ejemplo n.º 41
0
    def testBoolean(self):
        self.assertEqual(
            EngineConfig("test", Method.MAP, AvroInt(), AvroString(), [],
                         [LiteralBoolean(True),
                          LiteralBoolean(False)], [], {}, None, None, {}, {},
                         None, None, None, {}, {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [true, false]
}'''))
Ejemplo n.º 42
0
    def testCallFunction(self):
        self.assertEqual(
            EngineConfig(
                "test", Method.MAP, AvroInt(), AvroString(), [],
                [Call("+", [LiteralInt(2), LiteralInt(2)])], [], {}, None,
                None, {}, {}, None, None, None, {}, {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"+": [2, 2]}]
}'''))
Ejemplo n.º 43
0
    def testAttrSet(self):
        self.assertEqual(
            EngineConfig("test", Method.MAP, AvroInt(), AvroString(), [], [
                AttrTo(Ref("c"),
                       [Ref("a"), LiteralInt(1),
                        LiteralString("b")], LiteralDouble(2.2), None)
            ], [], {}, None, None, {}, {}, None, None, None, {}, {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"attr":"c","path":["a",1,{"string":"b"}],"to":2.2}]
}'''))
Ejemplo n.º 44
0
    def testNewArray(self):
        self.assertEqual(
            EngineConfig("test", Method.MAP, AvroInt(), AvroString(), [], [
                NewArray([LiteralInt(1),
                          LiteralInt(2),
                          LiteralInt(3)], AvroArray(AvroInt()),
                         AvroTypeBuilder())
            ], [], {}, None, None, {}, {}, None, None, None, {}, {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"new":[1,2,3],"type":{"type":"array","items":"int"}}]
}'''))
Ejemplo n.º 45
0
    def testSet(self):
        self.assertEqual(
            EngineConfig("test", Method.MAP, AvroInt(), AvroString(), [],
                         [SetVar({
                             "x": LiteralInt(3),
                             "y": LiteralInt(4)
                         })], [], {}, None, None, {}, {}, None, None, None, {},
                         {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"set":{"x":3,"y":4}}]
}'''))
Ejemplo n.º 46
0
    def testPoolGet(self):
        self.assertEqual(
            EngineConfig(
                "test", Method.MAP, AvroInt(), AvroString(), [],
                [PoolGet("p", [Ref("a"),
                               LiteralInt(1),
                               LiteralString("b")])], [], {}, None, None, {},
                {}, None, None, None, {}, {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"pool":"p","path":["a",1,{"string":"b"}]}]
}'''))
Ejemplo n.º 47
0
    def testCast(self):
        self.assertEqual(
            EngineConfig("test", Method.MAP, AvroInt(), AvroString(), [], [
                CastBlock(LiteralInt(3), [
                    CastCase(AvroString(), "x", [Ref("x")]),
                    CastCase(AvroInt(), "x", [Ref("x")])
                ], True)
            ], [], {}, None, None, {}, {}, None, None, None, {}, {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"cast":{"int":3},"cases":[{"as":"string","named":"x","do":["x"]},{"as":"int","named":"x","do":["x"]}],"partial":true}]
}'''))
Ejemplo n.º 48
0
    def testFor(self):
        self.assertEqual(
            EngineConfig("test", Method.MAP, AvroInt(), AvroString(), [], [
                For({"i": LiteralInt(0)}, Call(
                    "<", [Ref("i"), LiteralInt(10)]),
                    {"i": Call("+", [Ref("i"), LiteralInt(1)])}, [Ref("i")],
                    False)
            ], [], {}, None, None, {}, {}, None, None, None, {}, {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"for":{"i":0},"while":{"<":["i",10]},"step":{"i":{"+":["i",1]}},"do":["i"]}]
}'''))
Ejemplo n.º 49
0
    def testForkeyval(self):
        self.assertEqual(
            EngineConfig("test", Method.MAP, AvroInt(), AvroString(), [], [
                Forkeyval(
                    "k", "v",
                    Literal(AvroMap(AvroInt()),
                            '''{"one": 1, "two": 2, "three": 3}'''),
                    [Ref("k")])
            ], [], {}, None, None, {}, {}, None, None, None, {}, {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"forkey":"k","forval":"v","in":{"type":{"type":"map","values":"int"},"value":{"one":1,"two":2,"three":3}},"do":["k"]}]
}'''))
Ejemplo n.º 50
0
    def testLog(self):
        self.assertEqual(
            EngineConfig("test", Method.MAP, AvroInt(), AvroString(), [], [
                Log([LiteralString("hello")], None),
                Log([LiteralString("hello")], "DEBUG"),
                Log([Call("+", [LiteralInt(2), LiteralInt(2)])], None)
            ], [], {}, None, None, {}, {}, None, None, None, {}, {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"log":[{"string":"hello"}]},
             {"log":[{"string":"hello"}],"namespace":"DEBUG"},
             {"log":[{"+":[2,2]}]}]
}'''))
Ejemplo n.º 51
0
    def testCell(self):
        self.assertEqual(
            EngineConfig(
                "test", Method.MAP, AvroInt(), AvroString(), [],
                [Call("+", [LiteralInt(2), LiteralInt(2)])], [], {}, None,
                None, {
                    "private":
                    Cell(AvroArray(AvroString()), "[]", False, False,
                         CellPoolSource.EMBEDDED)
                }, {}, None, None, None, {}, {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"+": [2, 2]}],
  "cells":{"private":{"type":{"type": "array", "items": "string"},"init":[],"shared":false,"rollback":false}}
}'''))
Ejemplo n.º 52
0
    def testLiteral(self):
        self.assertEqual(
            EngineConfig("test", Method.MAP, AvroInt(), AvroString(), [], [
                Literal(
                    AvroRecord([
                        AvroField("one", AvroInt()),
                        AvroField("two", AvroDouble()),
                        AvroField("three", AvroString())
                    ], "SimpleRecord"),
                    '''{"one": 1, "two": 2.2, "three": "THREE"}''')
            ], [], {}, None, None, {}, {}, None, None, None, {}, {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"type":{"type":"record","name":"SimpleRecord","fields":[{"name":"one","type":"int"},{"name":"two","type":"double"},{"name":"three","type":"string"}]},"value":{"one":1,"two":2.2,"three":"THREE"}}]
}'''))
Ejemplo n.º 53
0
    def testDefineFunction(self):
        self.assertEqual(
            EngineConfig(
                "test", Method.MAP, AvroInt(), AvroString(), [],
                [Call("+", [LiteralInt(2), LiteralInt(2)])], [], {
                    "f":
                    FcnDef([{
                        "x": AvroInt()
                    }, {
                        "y": AvroString()
                    }], AvroNull(), [LiteralNull()])
                }, None, None, {}, {}, None, None, None, {}, {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"+": [2, 2]}],
  "fcns": {"f": {"params":[{"x":"int"},{"y":"string"}],"ret":"null","do":[null]}}
}'''))
Ejemplo n.º 54
0
    def testNewRecord(self):
        self.assertEqual(
            EngineConfig("test", Method.MAP, AvroInt(), AvroString(), [], [
                NewObject(
                    {
                        "one": LiteralInt(1),
                        "two": LiteralDouble(2.2),
                        "three": LiteralString("THREE")
                    },
                    AvroRecord([
                        AvroField("one", AvroInt()),
                        AvroField("two", AvroDouble()),
                        AvroField("three", AvroString())
                    ], "SimpleRecord"), AvroTypeBuilder())
            ], [], {}, None, None, {}, {}, None, None, None, {}, {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"new":{"one":{"int":1},"two":2.2,"three":{"string":"THREE"}},"type":{"type":"record","name":"SimpleRecord","fields":[{"name":"one","type":"int"},{"name":"two","type":"double"},{"name":"three","type":"string"}]}}]
}'''))
Ejemplo n.º 55
0
    def testEngineConfig(self):
        self.assertEqual(
            EngineConfig(
                "test", Method.MAP, AvroInt(), AvroString(), [],
                [Call("+", [LiteralInt(2), LiteralInt(2)])], [], {}, None,
                None, {}, {}, None, None, None, {}, {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": {"+": [2, 2]}
}'''))

        self.assertEqual(
            EngineConfig(
                "test", Method.EMIT, AvroInt(), AvroString(), [],
                [Call("+", [LiteralInt(2), LiteralInt(2)])], [], {}, None,
                None, {}, {}, None, None, None, {}, {}),
            jsonToAst('''{
  "name": "test",
  "method": "emit",
  "input": "int",
  "output": "string",
  "action": [{"+": [2, 2]}]
}'''))

        self.assertEqual(
            EngineConfig(
                "test", Method.MAP, AvroInt(), AvroString(),
                [Call("+", [LiteralInt(2), LiteralInt(2)])],
                [Call("+", [LiteralInt(2), LiteralInt(2)])],
                [Call("+", [LiteralInt(2), LiteralInt(2)])], {}, None, None,
                {}, {}, None, None, None, {}, {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "begin": [{"+": [2, 2]}],
  "action": [{"+": [2, 2]}],
  "end": [{"+": [2, 2]}]
}'''))

        self.assertEqual(
            EngineConfig(
                "test", Method.MAP, AvroInt(), AvroString(), [],
                [Call("+", [LiteralInt(2), LiteralInt(2)])], [], {
                    "f":
                    FcnDef([{
                        "x": AvroInt()
                    }, {
                        "y": AvroString()
                    }], AvroNull(), [LiteralNull()])
                }, None, None, {}, {}, None, None, None, {}, {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"+": [2, 2]}],
  "fcns": {"f": {"params":[{"x":"int"},{"y":"string"}],"ret":"null","do":[null]}}
}'''))

        self.assertEqual(
            EngineConfig(
                "test", Method.MAP, AvroInt(), AvroString(), [],
                [Call("+", [LiteralInt(2), LiteralInt(2)])], [], {}, None,
                None, {
                    "private":
                    Cell(AvroInt(), "0", False, False, CellPoolSource.EMBEDDED)
                }, {
                    "private":
                    Pool(AvroInt(), {}, False, False, CellPoolSource.EMBEDDED)
                }, None, None, None, {}, {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"+": [2, 2]}],
  "cells":{"private":{"type":"int","init":0,"shared":false,"rollback":false}},
  "pools":{"private":{"type":"int","init":{},"shared":false,"rollback":false}}
}'''))

        self.assertEqual(
            EngineConfig(
                "test", Method.MAP, AvroInt(), AvroString(), [],
                [Call("+", [LiteralInt(2), LiteralInt(2)])], [], {}, None,
                None, {}, {}, 12345, "hello", None, {"internal": "data"},
                {"param": json.loads("3")}),
            jsonToAst('''{
  "name": "test",
  "method": "map",
  "input": "int",
  "output": "string",
  "action": [{"+": [2, 2]}],
  "randseed":12345,
  "doc":"hello",
  "metadata":{"internal":"data"},
  "options":{"param":3}
}'''))

        self.assertEqual(
            EngineConfig(
                "test", Method.MAP, AvroInt(), AvroString(),
                [Call("+", [LiteralInt(2), LiteralInt(2)])],
                [Call("+", [LiteralInt(2), LiteralInt(2)])],
                [Call("+", [LiteralInt(2), LiteralInt(2)])], {
                    "f":
                    FcnDef([{
                        "x": AvroInt()
                    }, {
                        "y": AvroString()
                    }], AvroNull(), [LiteralNull()])
                }, None, None, {
                    "private":
                    Cell(AvroInt(), "0", False, False, CellPoolSource.EMBEDDED)
                }, {
                    "private":
                    Pool(AvroInt(), {}, False, False, CellPoolSource.EMBEDDED)
                }, 12345, "hello", None, {"internal": "data"},
                {"param": json.loads("3")}),
            jsonToAst('''{
  "name": "test",
  "method": "map",
  "input": "int",
  "output": "string",
  "begin": [{"+": [2, 2]}],
  "action": [{"+": [2, 2]}],
  "end": [{"+": [2, 2]}],
  "fcns": {"f": {"params":[{"x":"int"},{"y":"string"}],"ret":"null","do":[null]}},
  "cells":{"private":{"type":"int","init":0,"shared":false,"rollback":false}},
  "pools":{"private":{"type":"int","init":{},"shared":false,"rollback":false}},
  "randseed":12345,
  "doc":"hello",
  "metadata":{"internal":"data"},
  "options":{"param":3}
}'''))
Ejemplo n.º 56
0
    def testEngineConfig(self):
        self.assertEqual(
            EngineConfig(
            "test",
            Method.MAP,
            AvroInt(),
            AvroString(),
            [],
            [Call("+", [LiteralInt(2), LiteralInt(2)])],
            [],
            {},
            None,
            None,
            {},
            {},
            None,
            None,
            None,
            {},
            {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": {"+": [2, 2]}
}'''))

        self.assertEqual(
            EngineConfig(
            "test",
            Method.EMIT,
            AvroInt(),
            AvroString(),
            [],
            [Call("+", [LiteralInt(2), LiteralInt(2)])],
            [],
            {},
            None,
            None,
            {},
            {},
            None,
            None,
            None,
            {},
            {}),
            jsonToAst('''{
  "name": "test",
  "method": "emit",
  "input": "int",
  "output": "string",
  "action": [{"+": [2, 2]}]
}'''))

        self.assertEqual(
            EngineConfig(
            "test",
            Method.MAP,
            AvroInt(),
            AvroString(),
            [Call("+", [LiteralInt(2), LiteralInt(2)])],
            [Call("+", [LiteralInt(2), LiteralInt(2)])],
            [Call("+", [LiteralInt(2), LiteralInt(2)])],
            {},
            None,
            None,
            {},
            {},
            None,
            None,
            None,
            {},
            {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "begin": [{"+": [2, 2]}],
  "action": [{"+": [2, 2]}],
  "end": [{"+": [2, 2]}]
}'''))

        self.assertEqual(
            EngineConfig(
            "test",
            Method.MAP,
            AvroInt(),
            AvroString(),
            [],
            [Call("+", [LiteralInt(2), LiteralInt(2)])],
            [],
            {"f": FcnDef([{"x": AvroInt()}, {"y": AvroString()}], AvroNull(), [LiteralNull()])},
            None,
            None,
            {},
            {},
            None,
            None,
            None,
            {},
            {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"+": [2, 2]}],
  "fcns": {"f": {"params":[{"x":"int"},{"y":"string"}],"ret":"null","do":[null]}}
}'''))

        self.assertEqual(
            EngineConfig(
            "test",
            Method.MAP,
            AvroInt(),
            AvroString(),
            [],
            [Call("+", [LiteralInt(2), LiteralInt(2)])],
            [],
            {},
            None,
            None,
            {"private": Cell(AvroInt(), "0", False, False, CellPoolSource.EMBEDDED)},
            {"private": Pool(AvroInt(), {}, False, False, CellPoolSource.EMBEDDED)},
            None,
            None,
            None,
            {},
            {}),
            jsonToAst('''{
  "name": "test",
  "input": "int",
  "output": "string",
  "action": [{"+": [2, 2]}],
  "cells":{"private":{"type":"int","init":0,"shared":false,"rollback":false}},
  "pools":{"private":{"type":"int","init":{},"shared":false,"rollback":false}}
}'''))

        self.assertEqual(
            EngineConfig(
            "test",
            Method.MAP,
            AvroInt(),
            AvroString(),
            [],
            [Call("+", [LiteralInt(2), LiteralInt(2)])],
            [],
            {},
            None,
            None,
            {},
            {},
            12345,
            "hello",
            None,
            {"internal": "data"},
            {"param": json.loads("3")}),
            jsonToAst('''{
  "name": "test",
  "method": "map",
  "input": "int",
  "output": "string",
  "action": [{"+": [2, 2]}],
  "randseed":12345,
  "doc":"hello",
  "metadata":{"internal":"data"},
  "options":{"param":3}
}'''))

        self.assertEqual(
            EngineConfig(
            "test",
            Method.MAP,
            AvroInt(),
            AvroString(),
            [Call("+", [LiteralInt(2), LiteralInt(2)])],
            [Call("+", [LiteralInt(2), LiteralInt(2)])],
            [Call("+", [LiteralInt(2), LiteralInt(2)])],
            {"f": FcnDef([{"x": AvroInt()}, {"y": AvroString()}], AvroNull(), [LiteralNull()])},
            None,
            None,
            {"private": Cell(AvroInt(), "0", False, False, CellPoolSource.EMBEDDED)},
            {"private": Pool(AvroInt(), {}, False, False, CellPoolSource.EMBEDDED)},
            12345,
            "hello",
            None,
            {"internal": "data"},
            {"param": json.loads("3")}),
            jsonToAst('''{
  "name": "test",
  "method": "map",
  "input": "int",
  "output": "string",
  "begin": [{"+": [2, 2]}],
  "action": [{"+": [2, 2]}],
  "end": [{"+": [2, 2]}],
  "fcns": {"f": {"params":[{"x":"int"},{"y":"string"}],"ret":"null","do":[null]}},
  "cells":{"private":{"type":"int","init":0,"shared":false,"rollback":false}},
  "pools":{"private":{"type":"int","init":{},"shared":false,"rollback":false}},
  "randseed":12345,
  "doc":"hello",
  "metadata":{"internal":"data"},
  "options":{"param":3}
}'''))