Exemplo n.º 1
0
    def test_can_nest_one_statement_into_another_via_unbound(self):

        class Outer(Statement):

            def build(self):
                g = self.gremlin
                i = Inner()

                g.unbound('outer', i)

        class Inner(Statement):

            def build(self):
                g = self.gremlin
                g.inner_statement

        g = Gremlin()
        o = Outer()

        g.apply_statement(o)

        string = str(g)
        params = g.bound_params
        expected = 'g.outer(g.inner_statement)'

        self.assertTrue(string == expected)
        self.assertTrue(len(params) == 0)
Exemplo n.º 2
0
    def test_can_apply_two_statements_with_args(self):
        one = 'one'
        two = 'two'

        class First(Statement):
            def build(self):
                g = self.gremlin

                g.first(one)

        class Second(Statement):
            def build(self):
                g = self.gremlin

                g.second(two)

        f = First()
        s = Second()
        g = Gremlin()

        g.apply_statement(f).apply_statement(s)

        string = str(g)
        params = g.bound_params
        arg_1 = get_dict_key(params, one)
        arg_2 = get_dict_key(params, two)
        expected = 'g.first(%s).second(%s)' % (arg_1, arg_2)

        self.assertTrue(string == expected)
Exemplo n.º 3
0
 def test_can_apply_two_statements_with_args(self):
     one = 'one'
     two = 'two'
     
     class First(Statement):
         def build(self):
             g = self.gremlin
             
             g.first(one)
     
     class Second(Statement):
         def build(self):
             g = self.gremlin
             
             g.second(two)
     
     f = First()
     s = Second()
     g = Gremlin()
     
     g.apply_statement(f).apply_statement(s)
     
     string   = str(g)
     params   = g.bound_params
     arg_1    = get_dict_key(params, one)
     arg_2    = get_dict_key(params, two)
     expected = 'g.first(%s).second(%s)' % (arg_1, arg_2)
     
     self.assertTrue(string == expected)
Exemplo n.º 4
0
    def test_can_add_function_where_no_params_are_bound(self):
        g = Gremlin()

        g.unbound('func', 'val1', 'val2')

        expected = 'g.func(val1, val2)'

        self.assertTrue(str(g) == expected)
        self.assertTrue(len(g.bound_params) == 0)
Exemplo n.º 5
0
    def test_can_add_an_index_with_single_value(self):
        g = Gremlin()

        g.func()[1]

        s = str(g)
        expected = 'g.func()[1]'

        self.assertTrue(s == expected)
Exemplo n.º 6
0
    def test_can_add_an_index_with_range(self):
        g = Gremlin()

        g.func()[1:2]

        s = str(g)
        expected = 'g.func()[1..2]'

        self.assertTrue(s == expected)
Exemplo n.º 7
0
 def test_can_add_function_where_no_params_are_bound(self):
     g = Gremlin()
     
     g.unbound('func', 'val1', 'val2')
     
     expected = 'g.func(val1, val2)'
     
     self.assertTrue(str(g) == expected)
     self.assertTrue(len(g.bound_params) == 0)
Exemplo n.º 8
0
 def test_can_add_an_index_with_single_value(self):
     g = Gremlin()
     
     g.func()[1]
     
     s = str(g)
     expected = 'g.func()[1]'
     
     self.assertTrue(s == expected)
Exemplo n.º 9
0
 def test_can_add_an_index_with_range(self):
     g = Gremlin()
     
     g.func()[1:2]
     
     s = str(g)
     expected = 'g.func()[1..2]'
     
     self.assertTrue(s == expected)
Exemplo n.º 10
0
 def test_can_add_return_variable(self):
     g = Gremlin()
     v = 'ret_var'
     
     g.set_ret_variable(v).function()
     
     expected = '%s = g.function()' % v
     script = str(g)
     
     self.assertEquals(expected, script)
Exemplo n.º 11
0
 def test_can_add_and_remove_return_variable(self):
     g = Gremlin()
     v = 'ret_var'
     
     g.set_ret_variable(v).function().set_ret_variable(None)
     
     expected = 'g.function()'
     script = str(g)
     
     self.assertEquals(expected, script)
Exemplo n.º 12
0
    def test_can_add_and_remove_return_variable(self):
        g = Gremlin()
        v = 'ret_var'

        g.set_ret_variable(v).function().set_ret_variable(None)

        expected = 'g.function()'
        script = str(g)

        self.assertEquals(expected, script)
Exemplo n.º 13
0
    def test_can_add_return_variable(self):
        g = Gremlin()
        v = 'ret_var'

        g.set_ret_variable(v).function()

        expected = '%s = g.function()' % v
        script = str(g)

        self.assertEquals(expected, script)
Exemplo n.º 14
0
    def test_can_add_function_with_arg_before_attribute(self):
        g = Gremlin()
        
        g.function('val').a
        
        string      = str(g)
        bind, value = g.bound_params.copy().popitem()
        expected    = 'g.function(%s).a' % bind

        self.assertTrue(string == expected)
        self.assertTrue(len(g.bound_params) == 1)
Exemplo n.º 15
0
    def test_can_add_function_with_arg_before_attribute(self):
        g = Gremlin()

        g.function('val').a

        string = str(g)
        bind, value = g.bound_params.copy().popitem()
        expected = 'g.function(%s).a' % bind

        self.assertTrue(string == expected)
        self.assertTrue(len(g.bound_params) == 1)
Exemplo n.º 16
0
    def test_can_add_function_with_closure(self):
        g = Gremlin()

        g.condition('x').close('body')

        s = str(g)
        params = g.bound_params
        x = get_dict_key(params, 'x')
        expected = 'g.condition(%s){body}' % x

        self.assertTrue(s == expected)
        self.assertTrue(len(params) == 1)
Exemplo n.º 17
0
    def test_can_add_function_where_no_params_are_bound_and_func_with_bound_params(self):
        g = Gremlin()
        
        g.unbound('func', 'val1', 'val2').isbound('hello')
        
        s        = str(g)
        params   = g.bound_params
        hello    = get_dict_key(params, 'hello')
        expected = 'g.func(val1, val2).isbound(%s)' % hello

        self.assertTrue(str(g) == expected)
        self.assertTrue(len(g.bound_params) == 1)
Exemplo n.º 18
0
 def test_can_add_function_with_closure(self):
     g = Gremlin()
     
     g.condition('x').close('body')
     
     s        = str(g)
     params   = g.bound_params
     x        = get_dict_key(params, 'x')
     expected = 'g.condition(%s){body}' % x
     
     self.assertTrue(s == expected)
     self.assertTrue(len(params) == 1)
Exemplo n.º 19
0
 def test_can_nest_gremlin(self):
     g = Gremlin()
     n = Gremlin()
     
     g.nest(n.nested())
     
     expected = 'g.nest(g.nested())'
     string   = str(g)
     params   = g.bound_params
     
     self.assertTrue(expected == string)
     self.assertTrue(len(params) == 0)
Exemplo n.º 20
0
    def test_can_add_an_index_after_closure(self):
        g = Gremlin()

        g.condition('x').close('body')[12:44]

        s = str(g)
        params = g.bound_params
        x = get_dict_key(params, 'x')
        expected = 'g.condition(%s){body}[12..44]' % x

        self.assertTrue(s == expected)
        self.assertTrue(len(params) == 1)
Exemplo n.º 21
0
    def test_can_add_raw_after_function(self):
        g = Gremlin()
        r = '--raw-text--'

        g.func().raw(r)

        s = str(g)
        params = g.bound_params
        expected = 'g.func()%s' % r

        self.assertTrue(s == expected)
        self.assertTrue(len(params) == 0)
Exemplo n.º 22
0
 def test_can_add_raw_after_function(self):
     g = Gremlin()
     r = '--raw-text--'
     
     g.func().raw(r)
     
     s        = str(g)
     params   = g.bound_params
     expected = 'g.func()%s' % r
     
     self.assertTrue(s == expected)
     self.assertTrue(len(params) == 0)
Exemplo n.º 23
0
    def test_can_add_functon_manually_bind_two_args(self):
        g      = Gremlin()
        bound  = g.bind_param('arg')
        bound2 = g.bind_param('arg2')
        
        g.function(bound[0], bound2[0])
        
        string   = str(g)
        expected = 'g.function(%s, %s)' % (bound[0], bound2[0])

        self.assertTrue(string == expected)
        self.assertTrue(len(g.bound_params) == 2)
Exemplo n.º 24
0
 def test_can_add_raw_drop_graph_variable(self):
     g = Gremlin()
     r = '--raw-text--'
     
     g.raw(r).set_graph_variable('')
     
     s        = str(g)
     params   = g.bound_params
     expected = '%s' % r
     
     self.assertTrue(s == expected)
     self.assertTrue(len(params) == 0)
Exemplo n.º 25
0
    def test_can_add_raw_drop_graph_variable(self):
        g = Gremlin()
        r = '--raw-text--'

        g.raw(r).set_graph_variable('')

        s = str(g)
        params = g.bound_params
        expected = '%s' % r

        self.assertTrue(s == expected)
        self.assertTrue(len(params) == 0)
Exemplo n.º 26
0
 def test_can_add_an_index_after_closure(self):
     g = Gremlin()
     
     g.condition('x').close('body')[12:44]
     
     s        = str(g)
     params   = g.bound_params
     x        = get_dict_key(params, 'x')
     expected = 'g.condition(%s){body}[12..44]' % x
     
     self.assertTrue(s == expected)
     self.assertTrue(len(params) == 1)
Exemplo n.º 27
0
    def test_can_nest_double_nest_gremlin(self):
        g = Gremlin()
        n = Gremlin()
        d = Gremlin()

        g.nest(n.nested(d.deep()))

        expected = 'g.nest(g.nested(g.deep()))'
        string = str(g)
        params = g.bound_params

        self.assertTrue(expected == string)
        self.assertTrue(len(params) == 0)
Exemplo n.º 28
0
    def test_can_add_a_reserved_word_as_apart_of_the_query_as_function_with_args(self):
        g = Gremlin();
        init = Function(g, '__init__', ['arg'])

        g.add_token(init)
        
        s        = str(g)
        params   = g.bound_params
        arg      = get_dict_key(params, 'arg')
        expected = 'g.__init__(%s)' % arg
        
        self.assertTrue(s == expected)
        self.assertTrue(len(params) == 1)
Exemplo n.º 29
0
    def test_can_add_raw_after_closure(self):
        g = Gremlin()
        r = '--raw-text--'
        c = '[[[]]]'

        g.func().close(c).raw(r)

        s = str(g)
        params = g.bound_params
        expected = 'g.func(){%s}%s' % (c, r)

        self.assertTrue(s == expected)
        self.assertTrue(len(params) == 0)
Exemplo n.º 30
0
    def test_can_add_function_where_no_params_are_bound_and_func_with_bound_params(
            self):
        g = Gremlin()

        g.unbound('func', 'val1', 'val2').isbound('hello')

        s = str(g)
        params = g.bound_params
        hello = get_dict_key(params, 'hello')
        expected = 'g.func(val1, val2).isbound(%s)' % hello

        self.assertTrue(str(g) == expected)
        self.assertTrue(len(g.bound_params) == 1)
Exemplo n.º 31
0
    def test_can_add_a_reserved_word_as_apart_of_the_query_as_function_without_args(self):
        g = Gremlin();
        unbound = ['arg', '2']
        init = UnboudFunction(g, '__init__', unbound)

        g.add_token(init)
        
        s        = str(g)
        params   = g.bound_params
        expected = 'g.__init__(%s, %s)' % (unbound[0], unbound[1])

        self.assertTrue(s == expected)
        self.assertTrue(len(params) == 0)
Exemplo n.º 32
0
 def test_can_add_raw_after_closure(self):
     g = Gremlin()
     r = '--raw-text--'
     c = '[[[]]]'
     
     g.func().close(c).raw(r)
     
     s        = str(g)
     params   = g.bound_params
     expected = 'g.func(){%s}%s' % (c, r)
     
     self.assertTrue(s == expected)
     self.assertTrue(len(params) == 0)
Exemplo n.º 33
0
    def test_can_add_functon_manually_bind_one_arg(self):
        g = Gremlin()
        bound = g.bind_param('arg')

        g.function(bound[0])

        string = str(g)
        bind, value = g.bound_params.copy().popitem()
        expected = 'g.function(%s)' % bind

        self.assertTrue(string == expected)
        self.assertTrue(bind == bound[0])
        self.assertTrue(value == bound[1])
        self.assertTrue(len(g.bound_params) == 1)
Exemplo n.º 34
0
    def test_can_add_a_reserved_word_as_apart_of_the_query_as_function_without_args(
            self):
        g = Gremlin()
        unbound = ['arg', '2']
        init = UnboudFunction(g, '__init__', unbound)

        g.add_token(init)

        s = str(g)
        params = g.bound_params
        expected = 'g.__init__(%s, %s)' % (unbound[0], unbound[1])

        self.assertTrue(s == expected)
        self.assertTrue(len(params) == 0)
Exemplo n.º 35
0
 def test_can_add_raw_between_functions(self):
     g = Gremlin()
     r = '--raw-text--'
     a = 'arg'
     
     g.func().raw(r).func2(a)
     
     s        = str(g)
     params   = g.bound_params
     arg      = get_dict_key(params, a)
     expected = 'g.func()%sfunc2(%s)' % (r, arg)
     
     self.assertTrue(s == expected)
     self.assertTrue(len(params) == 1)
Exemplo n.º 36
0
    def test_can_add_raw_between_functions(self):
        g = Gremlin()
        r = '--raw-text--'
        a = 'arg'

        g.func().raw(r).func2(a)

        s = str(g)
        params = g.bound_params
        arg = get_dict_key(params, a)
        expected = 'g.func()%sfunc2(%s)' % (r, arg)

        self.assertTrue(s == expected)
        self.assertTrue(len(params) == 1)
Exemplo n.º 37
0
    def test_can_add_a_reserved_word_as_apart_of_the_query_as_function_without_args_after_other_calls(self):
        g = Gremlin();
        unbound = ['arg', '2']
        arg = 'some_arg'
        init = UnboudFunction(g, '__init__', unbound)
        
        g.someFunc(arg).add_token(init)
        
        s        = str(g)
        params   = g.bound_params
        expected = 'g.someFunc(%s).__init__(%s, %s)' % (get_dict_key(params, arg), unbound[0], unbound[1])

        self.assertTrue(s == expected)
        self.assertTrue(len(params) == 1)
Exemplo n.º 38
0
    def test_can_add_functon_manually_bind_one_arg(self):
        g     = Gremlin()
        bound = g.bind_param('arg')
        
        g.function(bound[0])
        
        string      = str(g)
        bind, value = g.bound_params.copy().popitem()
        expected    = 'g.function(%s)' % bind

        self.assertTrue(string == expected)
        self.assertTrue(bind == bound[0])
        self.assertTrue(value == bound[1])
        self.assertTrue(len(g.bound_params) == 1)
Exemplo n.º 39
0
    def test_can_add_a_reserved_word_as_apart_of_the_query_as_function_with_args(
            self):
        g = Gremlin()
        init = Function(g, '__init__', ['arg'])

        g.add_token(init)

        s = str(g)
        params = g.bound_params
        arg = get_dict_key(params, 'arg')
        expected = 'g.__init__(%s)' % arg

        self.assertTrue(s == expected)
        self.assertTrue(len(params) == 1)
Exemplo n.º 40
0
    def __init__(self, mapper):
        self.mapper = mapper
        self.gremlin = Gremlin(self.mapper.gremlin.gv)
        self.queries = []
        self.fields = []

        self.reset()
Exemplo n.º 41
0
 def test_can_apply_statement(self):
     class statement(Statement):
         def build(self):
             g = self.gremlin
             
             g.random().statement()
             
     s = statement()
     g = Gremlin()
     
     g.apply_statement(s)
     
     string   = str(g)
     expected = 'g.random().statement()'
     
     self.assertTrue(string == expected)
Exemplo n.º 42
0
    def test_can_apply_statement(self):
        class statement(Statement):
            def build(self):
                g = self.gremlin

                g.random().statement()

        s = statement()
        g = Gremlin()

        g.apply_statement(s)

        string = str(g)
        expected = 'g.random().statement()'

        self.assertTrue(string == expected)
Exemplo n.º 43
0
    def test_can_add_unbound_functon_two_args(self):
        g = Gremlin().unbound('function', 'arg', 'two')
        string = str(g)
        expected = 'g.function(arg, two)'

        self.assertEquals(string, expected)
        self.assertEquals(len(g.bound_params), 0)
Exemplo n.º 44
0
 def setUp(self):
     super().setUp()
     self.request = TestRequest()
     self.mapper = Mapper(request=self.request)
     self.query = Query(mapper=self.mapper)
     self.gremlin = Gremlin()
     self.ioloop = asyncio.get_event_loop()
Exemplo n.º 45
0
Arquivo: mapper.py Projeto: sns/Gizmo
    def __init__(self, gremlin=None, mapper=None):
        if gremlin is None:
            gremlin = Gremlin()

        self.gremlin = gremlin
        self.mapper = mapper
        self.reset()
Exemplo n.º 46
0
    def test_can_add_a_reserved_word_as_apart_of_the_query_as_function_without_args_after_other_calls(
            self):
        g = Gremlin()
        unbound = ['arg', '2']
        arg = 'some_arg'
        init = UnboudFunction(g, '__init__', unbound)

        g.someFunc(arg).add_token(init)

        s = str(g)
        params = g.bound_params
        expected = 'g.someFunc(%s).__init__(%s, %s)' % (get_dict_key(
            params, arg), unbound[0], unbound[1])

        self.assertTrue(s == expected)
        self.assertTrue(len(params) == 1)
Exemplo n.º 47
0
    def test_can_add_a_reserved_word_as_apart_of_the_query_as_function_with_args_after_other_calls(self):
        g = Gremlin();
        args = ['arg', 'LOOK', 'AT']
        init = Function(g, '__init__', [args[0]])

        g.look(args[1]).at(args[2]).close('--this--').add_token(init)
        
        s        = str(g)
        params   = g.bound_params
        arg      = get_dict_key(params, args[0])
        look     = get_dict_key(params, args[1])
        at       = get_dict_key(params, args[2])
        expected = 'g.look(%s).at(%s){--this--}.__init__(%s)' % (look, at, arg)

        self.assertTrue(s == expected)
        self.assertTrue(len(params) == 3)
Exemplo n.º 48
0
Arquivo: mapper.py Projeto: sns/Gizmo
    def __init__(self, gremlin=None, mapper=None):
        if gremlin is None:
            gremlin = Gremlin()

        self.gremlin = gremlin
        self.mapper = mapper
        self.fields = []
        self.queries = []
Exemplo n.º 49
0
 def test_can_make_conditional_statement(self):
     g      = Gremlin()
     c      = Conditional()
     cond   = '1 == 2'
     body   = 'nope'
     else_c = 'one doesnt equal two'
     
     c.set_if(cond, body)
     c.set_else(else_c)
     g.apply_statement(c)
     
     string   = str(g)
     params   = g.bound_params
     expected = 'if(%s){%s}else{%s}' % (cond, body, else_c)
     
     self.assertTrue(string == expected)
     self.assertTrue(len(params) == 0)
Exemplo n.º 50
0
    def test_can_add_functon_one_arg(self):
        g = Gremlin().function('arg')
        string = str(g)
        bind, value = g.bound_params.copy().popitem()
        expected = 'g.function(%s)' % bind

        self.assertTrue(string == expected)
        self.assertTrue(len(g.bound_params) == 1)
Exemplo n.º 51
0
    def test_can_add_functon_three_args(self):
        g = Gremlin().function('one', 'two', 'three')
        string = str(g)
        bind, value = g.bound_params.copy().popitem()
        expected = 'g.function(one, two, %s)' % bind

        self.assertTrue(string == expected)
        self.assertTrue(len(g.bound_params) == 1)
Exemplo n.º 52
0
    def test_can_add_a_reserved_word_as_apart_of_the_query_as_function_with_args_after_other_calls(
            self):
        g = Gremlin()
        args = ['arg', 'LOOK', 'AT']
        init = Function(g, '__init__', [args[0]])

        g.look(args[1]).at(args[2]).close('--this--').add_token(init)

        s = str(g)
        params = g.bound_params
        arg = get_dict_key(params, args[0])
        look = get_dict_key(params, args[1])
        at = get_dict_key(params, args[2])
        expected = 'g.look(%s).at(%s){--this--}.__init__(%s)' % (look, at, arg)

        self.assertTrue(s == expected)
        self.assertTrue(len(params) == 3)
Exemplo n.º 53
0
    def test_can_make_conditional_statement(self):
        g = Gremlin()
        c = Conditional()
        cond = '1 == 2'
        body = 'nope'
        else_c = 'one doesnt equal two'

        c.set_if(cond, body)
        c.set_else(else_c)
        g.apply_statement(c)

        string = str(g)
        params = g.bound_params
        expected = 'if(%s){%s}else{%s}' % (cond, body, else_c)

        self.assertTrue(string == expected)
        self.assertTrue(len(params) == 0)
Exemplo n.º 54
0
 def test_can_apply_statement_with_args(self):
     arg = 'statement_arg'
     
     class statement(Statement):
         def build(self):
             g = self.gremlin
             
             g.statementFunction(arg)
     
     s = statement()
     g = Gremlin()
     
     g.apply_statement(s)
     
     string   = str(g)
     params   = g.bound_params
     expected = 'g.statementFunction(%s)' % get_dict_key(params, arg)
     
     self.assertTrue(string == expected)
Exemplo n.º 55
0
    def test_can_make_get_edge_statement_out_direction(self):
        out_id = 1
        in_id = 9
        label = 'knows'
        g = Gremlin()
        e = GetEdge(out_id, in_id, label, 'out')

        g.apply_statement(e)

        string = str(g)
        params = g.bound_params
        oid = get_dict_key(params, out_id)
        iid = get_dict_key(params, in_id)
        label_b = get_dict_key(params, label)
        as_b = e.bound_entity
        bound = (oid, label_b, as_b, iid, as_b)
        expected = 'g.V(%s).outE(%s).as(%s).inV().hasId(%s).select(%s)' % \
            bound

        self.assertEqual(expected, string)
Exemplo n.º 56
0
 def test_can_make_get_edge_statement(self):
     out_id = 1
     in_id  = 9
     label  = 'knows'
     g      = Gremlin()
     e      = GetEdge(out_id, in_id, label)
     
     g.apply_statement(e)
     
     string   = str(g)
     params   = g.bound_params
     oid      = get_dict_key(params, out_id)
     iid      = get_dict_key(params, in_id)
     label_b  = get_dict_key(params, label)
     as_b     = get_dict_key(params, 'vertex')
     bound    = (oid, label_b, as_b, iid, as_b)
     expected = 'g.v(%s).outE(%s).as(%s).inV.retain([g.v(%s)]).back(%s)' % bound
     
     self.assertEquals(expected, string)
     self.assertTrue(len(params) == 4)
Exemplo n.º 57
0
 def test_can_make_conditional_statement_with_two_elseif(self):
     g       = Gremlin()
     c       = Conditional()
     cond    = '1 == 2'
     body    = 'nope'
     else_i  = '2 == 2'
     else_b  = 'two does equal 2'
     else_i2 = '20 == 20'
     else_b2 = 'already caught above'
     else_c  = 'one doesnt equal two'
     
     c.set_if(cond, body)
     c.set_elif(else_i, else_b)
     c.set_elif(else_i2, else_b2)
     c.set_else(else_c)
     g.apply_statement(c)
     
     string   = str(g)
     params   = g.bound_params
     expected = 'if(%s){%s}elseif(%s){%s}elseif(%s){%s}else{%s}' % (cond, body, else_i, else_b, else_i2, else_b2, else_c)
     
     self.assertTrue(string == expected)
     self.assertTrue(len(params) == 0) 
Exemplo n.º 58
0
    def test_can_nest_with_bound_params(self):
        g = Gremlin()
        d = {'name': 'parent'}
        n = Gremlin()
        p = {'prop': 'child'}
        
        n.set_graph_variable('').setSubProp('prop', p['prop'])
        g.func('name', d['name']).nest(n)
        
        string   = str(g)
        params   = g.bound_params
        name     = get_dict_key(params, 'parent')
        child    = get_dict_key(params, 'child')
        expected = 'g.func(name, %s).nest(setSubProp(prop, %s))' % (name, child)

        self.assertTrue(expected == string)
        self.assertTrue(len(params) == 2)