Exemplo n.º 1
0
    def test_func_where_values(self):
        a = "hello"

        def f():
            return "hello"

        def g(x, y, z):
            return x + y + z

        def h(f, x):
            return f(x)

        def i(x):
            return x ** 2

        def j(f):
            return f

        true = True
        false = False
        d = locals()
        try:
            d.update(__builtins__.__dict__)
        except AttributeError:
            d.update(__builtins__)
        self.assertEquals(exe("a[f()]", d), oset([a]))
        self.assertEquals(exe('a[f() == "hello"]', d), oset([a]))
        self.assertEquals(exe("a[g(1,2,3) == 6]", d), oset([a]))
        self.assertEquals(exe("a[h(i,3) == 9]", d), oset([a]))
        self.assertEquals(exe("a[i(j(j)(j)(j)(h)(i,3)) == 81]", d), oset([a]))
Exemplo n.º 2
0
 def test_nested_boolean_exprs(self):
     a = 'hello'
     true = True
     false = False
     self.assertEquals(exe('a[true and (false or true)]', locals()), oset([a]))
     self.assertEquals(exe('a[true and (false and true)]', locals()), oset([]))
     self.assertEquals(exe('a[true and (true and true)]', locals()), oset([a]))
     self.assertEquals(exe('a[true and (true and (not true or false))]', locals()), oset([]))
     self.assertEquals(exe('a[1 and (1 and (not 1 or 0))]', locals()), oset([]))
     self.assertEquals(exe('a[1 and (1 and (not 1 or (1 and 0 or (1 and 1))))]', locals()), oset([a]))
Exemplo n.º 3
0
 def test_nested_boolean_exprs(self):
     a = "hello"
     true = True
     false = False
     self.assertEquals(exe("a[true and (false or true)]", locals()), oset([a]))
     self.assertEquals(exe("a[true and (false and true)]", locals()), oset([]))
     self.assertEquals(exe("a[true and (true and true)]", locals()), oset([a]))
     self.assertEquals(exe("a[true and (true and (not true or false))]", locals()), oset([]))
     self.assertEquals(exe("a[1 and (1 and (not 1 or 0))]", locals()), oset([]))
     self.assertEquals(exe("a[1 and (1 and (not 1 or (1 and 0 or (1 and 1))))]", locals()), oset([a]))
Exemplo n.º 4
0
 def test_iterdown(self):
     class A(object):
         def __init__(self, q):
             self.q = q
     answer = 'o.x.y'
     o = A('top')
     o.x = [A('asdf'), A('123')]
     o.x[0].y = A(answer)
     d = {'hasattr':hasattr, 'o':o}
     self.assertEquals(exe('o/x[hasattr(self,"y")]/y/q', d), oset([answer]))
     self.assertEquals(exe('o/x', d), oset(o.x))
Exemplo n.º 5
0
    def test_iterdown(self):
        class A(object):
            def __init__(self, q):
                self.q = q

        answer = "o.x.y"
        o = A("top")
        o.x = [A("asdf"), A("123")]
        o.x[0].y = A(answer)
        d = {"hasattr": hasattr, "o": o}
        self.assertEquals(exe('o/x[hasattr(self,"y")]/y/q', d), oset([answer]))
        self.assertEquals(exe("o/x", d), oset(o.x))
Exemplo n.º 6
0
 def test_func_where_values(self):
     a = 'hello'
     def f(): return 'hello'
     def g(x,y,z): return x + y + z
     def h(f,x): return f(x)
     def i(x): return x**2
     def j(f): return f
     true = True
     false = False
     d = locals()
     try: d.update(__builtins__.__dict__)
     except AttributeError: d.update(__builtins__)
     self.assertEquals(exe('a[f()]', d), oset([a]))
     self.assertEquals(exe('a[f() == "hello"]', d), oset([a]))
     self.assertEquals(exe('a[g(1,2,3) == 6]', d), oset([a]))
     self.assertEquals(exe('a[h(i,3) == 9]', d), oset([a]))
     self.assertEquals(exe('a[i(j(j)(j)(j)(h)(i,3)) == 81]', d), oset([a]))
Exemplo n.º 7
0
 def test_ifExpr(self):
     a = 'hello'
     l = [1,2,3,4,5,6,7,[1,2,3,4,5,6,7,[1,2,3,4,5,6,7,8]]]
     q = True
     d = locals()
     try: d.update(__builtins__.__dict__)
     except AttributeError: d.update(__builtins__)
     self.assertEquals(exe('''
       for x in <a> return if (q) then 1 else 0
       ''', d), oset([int(q)]))
Exemplo n.º 8
0
 def test_None(self):
     a = 'hello'
     l = [1,2,3,4,5,6,7,[1,2,3,4,5,6,7,[1,2,3,4,5,6,7,8]]]
     q = None
     d = locals()
     try: d.update(__builtins__.__dict__)
     except AttributeError: d.update(__builtins__)
     self.assertEquals(exe('''
       for x in l
       return None
       ''', d), oset([None]))
Exemplo n.º 9
0
 def test_list_where_values(self):
     a = 'hello'
     l = [1,2,3,4,5,6,7,[1,2,3,4,5,6,7,[1,2,3,4,5,6,7,8]]]
     d = locals()
     try: d.update(__builtins__.__dict__)
     except AttributeError: d.update(__builtins__)
     self.assertEquals(exe('a[l[0] == 1]', d), oset([a]))
     self.assertEquals(exe('a[l[1] == 2]', d), oset([a]))
     self.assertEquals(exe('a[l[7][0] == 1]', d), oset([a]))
     self.assertEquals(exe('a[l[7][1] == 2]', d), oset([a]))
     self.assertEquals(exe('a[l[7][7][0] == 1]', d), oset([a]))
     self.assertEquals(exe('a[l[7][7][1] == 2]', d), oset([a]))
     self.assertEquals(exe('a[l[7][7][7] == 8]', d), oset([a]))
Exemplo n.º 10
0
 def test_simple_where_values(self):
     a = 'hello'
     true = True
     false = False
     d = locals()
     try: d.update(__builtins__.__dict__)
     except AttributeError: d.update(__builtins__)
     self.assertEquals(exe('a[1 == 1]', d), oset([a]))
     self.assertEquals(exe('a[-1 == -1]', d), oset([a]))
     self.assertEquals(exe('a[2.2 == 2.2]', d), oset([a]))
     self.assertEquals(exe('a[2.2 == float("2.2")]', d), oset([a]))
     self.assertEquals(exe('a[2 == int(2.2)]', d), oset([a]))
     self.assertEquals(exe('a["hello" == a]', d), oset([a]))
     self.assertEquals(exe('a["HELLO" == a.upper()]', d), oset([a]))
Exemplo n.º 11
0
 def test_dict_where_values(self):
     a = 'hello'
     l = {"one":1, "two":2, "next":{"one":1, "two":2, "next":{"one":1, "two":2}}}
     d = locals()
     try: d.update(__builtins__.__dict__)
     except AttributeError: d.update(__builtins__)
     self.assertEquals(exe('a[l["one"] == 1]', d), oset([a]))
     self.assertEquals(exe('a[l["two"] == 2]', d), oset([a]))
     self.assertEquals(exe('a[l["next"]["one"] == 1]', d), oset([a]))
     self.assertEquals(exe('a[l["next"]["two"] == 2]', d), oset([a]))
     self.assertEquals(exe('a[l["next"]["next"]["one"] == 1]', d), oset([a]))
     self.assertEquals(exe('a[l["next"]["next"]["two"] == 2]', d), oset([a]))
Exemplo n.º 12
0
 def test_cmpops(self):
     class A(object):
         def __init__(self, q):
             self.q = q
     a = A(5)
     self.assertEquals(exe('a[self.q == 5]', locals()), oset([a]))
     self.assertEquals(exe('a[self.q != 5]', locals()), oset([]))
     self.assertEquals(exe('a[self.q >= 5]', locals()), oset([a]))
     self.assertEquals(exe('a[self.q <= 5]', locals()), oset([a]))
     self.assertEquals(exe('a[self.q > 5]', locals()), oset([]))
     self.assertEquals(exe('a[self.q < 5]', locals()), oset([]))
     self.assertEquals(exe('a[self.q == 7]', locals()), oset([]))
     self.assertEquals(exe('a[self.q != 7]', locals()), oset([a]))
     self.assertEquals(exe('a[self.q >= 7]', locals()), oset([]))
     self.assertEquals(exe('a[self.q <= 7]', locals()), oset([a]))
     self.assertEquals(exe('a[self.q > 7]', locals()), oset([]))
     self.assertEquals(exe('a[self.q < 7]', locals()), oset([a]))
     self.assertEquals(exe('a[self.q == 3]', locals()), oset([]))
     self.assertEquals(exe('a[self.q != 3]', locals()), oset([a]))
     self.assertEquals(exe('a[self.q >= 3]', locals()), oset([a]))
     self.assertEquals(exe('a[self.q <= 3]', locals()), oset([]))
     self.assertEquals(exe('a[self.q > 3]', locals()), oset([a]))
     self.assertEquals(exe('a[self.q < 3]', locals()), oset([]))
Exemplo n.º 13
0
 def test_smpl_boolean_exprs(self):
     a = "hello"
     true = True
     false = False
     self.assertEquals(exe("a[true]", locals()), oset([a]))
     self.assertEquals(exe("a[false]", locals()), oset([]))
     self.assertEquals(exe("a[not true]", locals()), oset([]))
     self.assertEquals(exe("a[not false]", locals()), oset([a]))
     self.assertEquals(exe("a[true and true]", locals()), oset([a]))
     self.assertEquals(exe("a[false and true]", locals()), oset([]))
     self.assertEquals(exe("a[not true and true]", locals()), oset([]))
     self.assertEquals(exe("a[not false and true]", locals()), oset([a]))
     self.assertEquals(exe("a[true or false]", locals()), oset([a]))
     self.assertEquals(exe("a[true or true]", locals()), oset([a]))
     self.assertEquals(exe("a[false or true]", locals()), oset([a]))
     self.assertEquals(exe("a[false or false]", locals()), oset([]))
     self.assertEquals(exe("a[not true or true]", locals()), oset([a]))
     self.assertEquals(exe("a[not false or false]", locals()), oset([a]))
     self.assertEquals(exe("a[true and true and true and true]", locals()), oset([a]))
     self.assertEquals(exe("a[true and true and true and false]", locals()), oset([]))
Exemplo n.º 14
0
    def test_cmpops(self):
        class A(object):
            def __init__(self, q):
                self.q = q

        a = A(5)
        self.assertEquals(exe("a[self.q == 5]", locals()), oset([a]))
        self.assertEquals(exe("a[self.q != 5]", locals()), oset([]))
        self.assertEquals(exe("a[self.q >= 5]", locals()), oset([a]))
        self.assertEquals(exe("a[self.q <= 5]", locals()), oset([a]))
        self.assertEquals(exe("a[self.q > 5]", locals()), oset([]))
        self.assertEquals(exe("a[self.q < 5]", locals()), oset([]))
        self.assertEquals(exe("a[self.q == 7]", locals()), oset([]))
        self.assertEquals(exe("a[self.q != 7]", locals()), oset([a]))
        self.assertEquals(exe("a[self.q >= 7]", locals()), oset([]))
        self.assertEquals(exe("a[self.q <= 7]", locals()), oset([a]))
        self.assertEquals(exe("a[self.q > 7]", locals()), oset([]))
        self.assertEquals(exe("a[self.q < 7]", locals()), oset([a]))
        self.assertEquals(exe("a[self.q == 3]", locals()), oset([]))
        self.assertEquals(exe("a[self.q != 3]", locals()), oset([a]))
        self.assertEquals(exe("a[self.q >= 3]", locals()), oset([a]))
        self.assertEquals(exe("a[self.q <= 3]", locals()), oset([]))
        self.assertEquals(exe("a[self.q > 3]", locals()), oset([a]))
        self.assertEquals(exe("a[self.q < 3]", locals()), oset([]))
Exemplo n.º 15
0
 def test_hello(self):
     hello = "hello world!"
     q = pyflwor.compile("hello")
     self.assertEquals(q(locals()), oset([hello]))
Exemplo n.º 16
0
    def test_callable_where_values(self):
        a = "hello"

        def f():
            return "hello"

        def g(x, y, z):
            return x + y + z

        def h(f, x):
            return f(x)

        def i(x):
            return x ** 2

        def j(f):
            return f

        m = {"one": 1, "two": 2, "next": [1, 2, 3, 4, 5, 6, 7, j]}
        true = True
        false = False
        d = locals()
        try:
            d.update(__builtins__.__dict__)
        except AttributeError:
            d.update(__builtins__)
        self.assertEquals(exe('a[m["next"][7](j)(m["next"][7])(m["next"])[7](i)(m["two"]) == 4]', d), oset([a]))
Exemplo n.º 17
0
 def test_callable_where_values(self):
     a = 'hello'
     def f(): return 'hello'
     def g(x,y,z): return x + y + z
     def h(f,x): return f(x)
     def i(x): return x**2
     def j(f): return f
     m = {"one":1, "two":2, "next":[1,2,3,4,5,6,7,j]}
     true = True
     false = False
     d = locals()
     try: d.update(__builtins__.__dict__)
     except AttributeError: d.update(__builtins__)
     self.assertEquals(exe('a[m["next"][7](j)(m["next"][7])(m["next"])[7](i)(m["two"]) == 4]', d), oset([a]))
Exemplo n.º 18
0
 def test_hello(self):
     hello = 'hello world!'
     q = pyflwor.compile('hello')
     self.assertEquals(q(locals()), oset([hello]))
Exemplo n.º 19
0
 def test_smpl_boolean_exprs(self):
     a = 'hello'
     true = True
     false = False
     self.assertEquals(exe('a[true]', locals()), oset([a]))
     self.assertEquals(exe('a[false]', locals()), oset([]))
     self.assertEquals(exe('a[not true]', locals()), oset([]))
     self.assertEquals(exe('a[not false]', locals()), oset([a]))
     self.assertEquals(exe('a[true and true]', locals()), oset([a]))
     self.assertEquals(exe('a[false and true]', locals()), oset([]))
     self.assertEquals(exe('a[not true and true]', locals()), oset([]))
     self.assertEquals(exe('a[not false and true]', locals()), oset([a]))
     self.assertEquals(exe('a[true or false]', locals()), oset([a]))
     self.assertEquals(exe('a[true or true]', locals()), oset([a]))
     self.assertEquals(exe('a[false or true]', locals()), oset([a]))
     self.assertEquals(exe('a[false or false]', locals()), oset([]))
     self.assertEquals(exe('a[not true or true]', locals()), oset([a]))
     self.assertEquals(exe('a[not false or false]', locals()), oset([a]))
     self.assertEquals(exe('a[true and true and true and true]', locals()), oset([a]))
     self.assertEquals(exe('a[true and true and true and false]', locals()), oset([]))