Exemplo n.º 1
0
 def test_evaluation_expression2(self):
     script = dedent("""
     Match(short_description, ?hr_service);
     """)
     exe = engine.compile_norm(script)
     cmd = exe.stack.pop()
     self.assertEqual(cmd.type_name, engine.TypeName('Match', None))
     self.assertEqual(cmd.args, engine.ListExpr(
         [engine.ArgumentExpr(engine.BaseExpr('variable', 'short_description'), None),
          engine.ArgumentExpr(None, engine.Projection(None, 'hr_service'))]))
Exemplo n.º 2
0
 def test_evaluation_expression5(self):
     script = dedent("""
     Match(short_description, ['a', 'b', 'c']);
     """)
     exe = engine.compile_norm(script)
     cmd = exe.stack.pop()
     self.assertEqual(cmd.type_name, engine.TypeName('Match', None))
     self.assertEqual(cmd.args, engine.ListExpr(
         [engine.ArgumentExpr(engine.BaseExpr('variable', 'short_description'), None),
          engine.ArgumentExpr(engine.ListExpr([engine.BaseExpr('constant', engine.Constant('string', 'a')),
                                               engine.BaseExpr('constant', engine.Constant('string', 'b')),
                                               engine.BaseExpr('constant', engine.Constant('string', 'c'))]),
                              None)]))
     self.assertEqual(cmd.projection, None)
Exemplo n.º 3
0
 def test_aggregation_function_expression(self):
     script = dedent("""
     Company(name ~ 'google')?*.Group(by="founders");
     """)
     exe = engine.compile_norm(script)
     cmd = exe.stack.pop()
     google = engine.BaseExpr('constant', engine.Constant('string', 'google'))
     condition = engine.ConditionExpr('name', '~', google)
     assignment = engine.AssignmentExpr('by', engine.BaseExpr('constant', engine.Constant('string', 'founders')))
     self.assertEqual(cmd.qexpr, engine.EvaluationExpr(engine.TypeName('Company', None), None,
                                                       engine.ListExpr([engine.ArgumentExpr(condition, None)]),
                                                       engine.Projection(1000000, None)))
     self.assertEqual(cmd.eexpr, engine.EvaluationExpr(engine.TypeName('Group', None), None,
                                                       engine.ListExpr([engine.ArgumentExpr(assignment, None)]),
                                                       None))
Exemplo n.º 4
0
 def test_assignment_expression(self):
     script = dedent("""
     a = Company('google')?*;
     """)
     exe = engine.compile_norm(script)
     cmd = exe.stack.pop()
     google = engine.BaseExpr('constant', engine.Constant('string', 'google'))
     self.assertEqual(cmd.variable_name, 'a')
     self.assertEqual(cmd.expr, engine.EvaluationExpr(engine.TypeName('Company', None), None,
                                                      engine.ListExpr([engine.ArgumentExpr(google, None)]),
                                                      engine.Projection(1000000, None)))
Exemplo n.º 5
0
    def test_combined_evaluation_expression(self):
        script = dedent("""
        Company(name ~ 'google')?comp & Develop(comp, 'AI');
        """)
        exe = engine.compile_norm(script)
        cmd = exe.stack.pop()
        google = engine.BaseExpr('constant', engine.Constant('string', 'google'))
        ai = engine.BaseExpr('constant', engine.Constant('string', 'AI'))
        comp = engine.BaseExpr('variable', value='comp')
        condition = engine.ConditionExpr('name', '~', google)
        expr1 = engine.EvaluationExpr(engine.TypeName('Company', None), None,
                                      engine.ListExpr([engine.ArgumentExpr(condition, None)]),
                                      engine.Projection(None, 'comp'))
        expr2 = engine.EvaluationExpr(engine.TypeName('Develop', None), None,
                                      engine.ListExpr([engine.ArgumentExpr(comp, None),
                                                       engine.ArgumentExpr(ai, None)]),
                                      None)

        self.assertEqual(cmd.op, '&')
        self.assertEqual(cmd.expr1, expr1)
        self.assertEqual(cmd.expr2, expr2)
Exemplo n.º 6
0
 def test_property_access_expression(self):
     script = dedent("""
     Company(name ~ 'google').founders;
     """)
     exe = engine.compile_norm(script)
     cmd = exe.stack.pop()
     google = engine.BaseExpr('constant', engine.Constant('string', 'google'))
     condition = engine.ConditionExpr('name', '~', google)
     self.assertEqual(cmd.expr, engine.EvaluationExpr(engine.TypeName('Company', None), None,
                                                      engine.ListExpr([engine.ArgumentExpr(condition, None)]),
                                                      None))
     self.assertEqual(cmd.property, 'founders')
Exemplo n.º 7
0
 def test_combined_condition_expression(self):
     script = dedent("""
     Company((name ~ 'google') & !(name ~ 'microsoft'));
     """)
     exe = engine.compile_norm(script)
     cmd = exe.stack.pop()
     google = engine.BaseExpr('constant', engine.Constant('string', 'google'))
     microsoft = engine.BaseExpr('constant', engine.Constant('string', 'microsoft'))
     condition1 = engine.ConditionExpr('name', '~', google)
     condition2 = engine.ConditionExpr('name', '~', microsoft)
     condition = engine.ConditionCombinedExpr('&', condition1, engine.ConditionCombinedExpr('!', condition2, None))
     self.assertEqual(cmd.type_name, engine.TypeName('Company', None))
     self.assertEqual(cmd.args, engine.ListExpr([engine.ArgumentExpr(condition, None)]))