Beispiel #1
0
 def test_binary_rebind(self):
     result = TP.parseString('$x + 20 -> $y')
     self.assertIsInstance(result, Transforms.Transform)
     self.assertEqual(len(result.components), 1)
     self.assertEqual(result.components[0].op, Transforms.TROP.ADD)
     self.assertEqual(result.components[0].source.value, 'x')
     self.assertEqual(result.components[0].val, 20)
     self.assertIsNone(result.components[0].bind)
     self.assertEqual(result.components[0].rebind.value, 'y')
Beispiel #2
0
 def test_ternary_operator_rebind(self):
     result = TP.parseString('$x ~= /blah/ $awef -> $q')
     self.assertIsInstance(result, Transforms.Transform)
     self.assertEqual(len(result.components), 1)
     self.assertEqual(result.components[0].op, Transforms.TROP.REGEX)
     self.assertEqual(result.components[0].source.value, 'x')
     self.assertEqual(result.components[0].val, 'blah')
     self.assertEqual(result.components[0].rebind.value, 'q')
     self.assertEqual(result.components[0].bind.value, 'awef')
Beispiel #3
0
 def test_unary_operator(self):
     result = TP.parseString('-$x')
     self.assertIsInstance(result, Transforms.Transform)
     self.assertEqual(len(result.components), 1)
     self.assertEqual(result.components[0].op, Transforms.TROP.NEG)
     self.assertEqual(result.components[0].source.value, "x")
     self.assertIsNone(result.components[0].val)
     self.assertIsNone(result.components[0].bind)
     self.assertIsNone(result.components[0].rebind)
Beispiel #4
0
    def test_run_transform(self):
        stub_ctx = pyRule.Contexts.initial(None)
        stub_ctx[0]['a'] = 2
        stub_ctx[0]['b'] = 4

        stub_transform = TP.parseString('$a + 20, $b * 2')

        result = self.e._run_transform(stub_ctx[0], stub_transform)
        self.assertIsInstance(result, dict)
        self.assertEqual(result['a'], 22)
        self.assertEqual(result['b'], 8)
Beispiel #5
0
    def test_run_binary_transform(self):
        stub_ctx = pyRule.Contexts.initial(None)
        stub_ctx[0]['a'] = 2
        stub_ctx[0]['b'] = -2
        stub_ctx[0]['c'] = 2.53

        stub_transform = TP.parseString('$a + 20, $b - 20, $c + $a')
        result = self.e._run_transform(stub_ctx[0], stub_transform)
        self.assertIsInstance(result, dict)
        self.assertEqual(result['a'], 22)
        self.assertEqual(result['b'], -22)
        self.assertEqual(result['c'], 24.53)
Beispiel #6
0
    def test_run_unary_transform(self):
        stub_ctx = pyRule.Contexts.initial(None)
        stub_ctx[0]['a'] = 2
        stub_ctx[0]['b'] = -2
        stub_ctx[0]['c'] = 2.53

        stub_transform = TP.parseString('-$a, -$b, _$c')
        result = self.e._run_transform(stub_ctx[0], stub_transform)
        self.assertIsInstance(result, dict)
        self.assertEqual(result['a'], -2)
        self.assertEqual(result['b'], 2)
        self.assertEqual(result['c'], 2)
Beispiel #7
0
    def test_run_transform_rebind(self):
        stub_ctx = pyRule.Contexts.initial(None)
        stub_ctx[0]['a'] = 2
        stub_ctx[0]['b'] = 8

        stub_transform = TP.parseString('$a + 20 -> $q, $b * $a -> $w')
        result = self.e._run_transform(stub_ctx[0], stub_transform)
        self.assertIsInstance(result, dict)
        self.assertEqual(result['a'], 2)
        self.assertEqual(result['b'], 8)
        self.assertEqual(result['q'], 22)
        self.assertEqual(result['w'], 16)
Beispiel #8
0
 def test_fact_str_equal(self):
     transforms = [
         "$x + 20", "$x + 20, $y + 5", "$xc - 10", "$x * 100",
         "$x + 20 -> $y", "$Blah + $bloo -> $BLEE", "-$x", "_$x",
         "-$x -> $y", "_$x -> $y", "$x ~= /blah/ $a",
         "$x ~= /aw+/ $b -> $blah", "$x + 2d5", "select 0 - 2",
         "select _ - _", "select $x - $y"
     ]
     parsed = [TP.parseString(x) for x in transforms]
     zipped = zip(transforms, parsed)
     for t, p in zipped:
         self.assertEqual(t, str(p))
Beispiel #9
0
    def test_run_ternary_regex_transform(self):
        stub_ctx = pyRule.Contexts.initial(None)
        stub_ctx[0]['a'] = "blah"
        stub_ctx[0]['b'] = "aaablah"
        stub_ctx[0]['c'] = "awefblahawef"
        stub_ctx[0]['d'] = 'AAAA'

        stub_transform = TP.parseString(
            '$a ~= /blah/ bloo, $b ~= /aaa\\w+/ $d, $c ~= /awef(\\w+)awef/ $d')
        result = self.e._run_transform(stub_ctx[0], stub_transform)
        self.assertIsInstance(result, dict)
        self.assertEqual(result['a'], 'bloo')
        self.assertEqual(result['b'], 'AAAA')
        self.assertEqual(result['c'], 'AAAA')
Beispiel #10
0
    def test_run_unary_format(self):
        stub_ctx = pyRule.Contexts.initial(None)
        stub_ctx[0]['a'] = "AAA"
        stub_ctx[0]['b'] = "BBB"
        stub_ctx[0]['c'] = "CCC"
        stub_ctx[0]['x'] = "{a}"
        stub_ctx[0]['y'] = "{a} blah {b}"
        stub_ctx[0]['z'] = "{c} {b} {a}"

        stub_transform = TP.parseString('~{} $x, ~{} $y, ~{} $z')
        result = self.e._run_transform(stub_ctx[0], stub_transform)
        self.assertIsInstance(result, dict)
        self.assertEqual(result['x'], 'AAA')
        self.assertEqual(result['y'], 'AAA blah BBB')
        self.assertEqual(result['z'], 'CCC BBB AAA')
Beispiel #11
0
    def test_run_binary_transform_rebind(self):
        stub_ctx = pyRule.Contexts.initial(None)
        stub_ctx[0]['a'] = 2
        stub_ctx[0]['b'] = -2
        stub_ctx[0]['c'] = 2.53

        stub_transform = TP.parseString(
            '$a + 20 -> $x, $b - 20 -> $y, $c + $a -> $z')
        result = self.e._run_transform(stub_ctx[0], stub_transform)
        self.assertIsInstance(result, dict)
        self.assertEqual(result['a'], 2)
        self.assertEqual(result['b'], -2)
        self.assertEqual(result['c'], 2.53)
        self.assertEqual(result['x'], 22)
        self.assertEqual(result['y'], -22)
        self.assertTrue(isclose(result['z'], 4.53))
Beispiel #12
0
 def test_basic_transform(self):
     result = TP.parseString('$x + 20, $y + 5')
     self.assertIsInstance(result, Transforms.Transform)
     self.assertEqual(len(result.components), 2)
Beispiel #13
0
 def test_unary_round(self):
     result = TP.parseString('_$x')
     self.assertEqual(result.components[0].op, Transforms.TROP.ROUND)
Beispiel #14
0
 def test_binary_rand_operator(self):
     result = TP.parseString('$x <-> $y')
     self.assertEqual(len(result.components), 1)
     self.assertEqual(result.components[0].op, Transforms.TROP.RAND)