예제 #1
0
 def test_literal_set_empty(self):
     inp = "{}"
     lexer = parser.get_lexer()
     p = parser.get_parser()
     res = p.parse(inp, lexer=lexer)
     assert isinstance(res, ast.LiteralSet)
     assert res.value == set([])
예제 #2
0
파일: test_parser.py 프로젝트: armon/pypred
 def test_literal_set_empty(self):
     inp = "{}"
     lexer = parser.get_lexer()
     p = parser.get_parser()
     res = p.parse(inp, lexer=lexer)
     assert isinstance(res, ast.LiteralSet)
     assert res.value == set([])
예제 #3
0
 def test_error_expr(self):
     inp = "a > 1 b > 2"
     lexer = parser.get_lexer()
     p = parser.get_parser()
     lexer.parser = p
     res = p.parse(inp, lexer=lexer)
     assert isinstance(res, ast.CompareOperator)
     assert len(p.errors) == 3
예제 #4
0
 def test_error_expr(self):
     inp = "a > 1 b > 2"
     lexer = parser.get_lexer()
     p = parser.get_parser()
     lexer.parser = p
     res = p.parse(inp, lexer=lexer)
     assert isinstance(res, ast.CompareOperator)
     assert len(p.errors) == 3
예제 #5
0
 def test_literal_set(self):
     inp = "{true false 1.0 \"quote\"}"
     lexer = parser.get_lexer()
     p = parser.get_parser()
     res = p.parse(inp, lexer=lexer)
     assert isinstance(res, ast.LiteralSet)
     assert res.value == set([
         ast.Constant(True),
         ast.Constant(False),
         ast.Number(1.0),
         ast.Literal("\"quote\"")
     ])
예제 #6
0
파일: test_parser.py 프로젝트: armon/pypred
 def test_literal_set(self):
     inp = "{true false 1.0 \"quote\"}"
     lexer = parser.get_lexer()
     p = parser.get_parser()
     res = p.parse(inp, lexer=lexer)
     assert isinstance(res, ast.LiteralSet)
     assert res.value == set([
         ast.Constant(True),
         ast.Constant(False),
         ast.Number(1.0),
         ast.Literal("\"quote\"")
     ])
예제 #7
0
    def assert_nodes(self, inp, exp_nodes):
        lexer = parser.get_lexer()
        p = parser.get_parser()
        res = p.parse(inp, lexer=lexer)
        assert isinstance(res, ast.Node)

        # Do a pre-order traversal
        nodes = []
        res.pre(lambda n: nodes.append(n))

        # Get the class names
        names = [repr(n) for n in nodes]
        #assert len(names) == len(exp_nodes)
        assert names == exp_nodes
예제 #8
0
    def assert_nodes(self, inp, exp_nodes):
        lexer = parser.get_lexer()
        p = parser.get_parser()
        res = p.parse(inp, lexer=lexer)
        assert isinstance(res, ast.Node)

        # Do a pre-order traversal
        nodes = []
        res.pre(lambda n: nodes.append(n))

        # Get the class names
        names = [repr(n) for n in nodes]
        #assert len(names) == len(exp_nodes)
        assert names == exp_nodes
예제 #9
0
    def convert(self, source):
        """
        """
        ast = None
        lexer = pypred_parser.get_lexer()
        parser = pypred_parser.get_parser()

        try:
            ast = parser.parse(source, lexer)
        except AttributeError:
            raise SyntaxError('Could not convert predicate %s' % source)

        if parser.errors or lexer.errors:
            raise SyntaxError('Could not convert due to the following errors %s' % (parser.errors + lexer.errors))

        if type(ast) == Literal:
            raise SyntaxError('Invalid predicate %s' % source)

        return self.convert_tree(ast)  # pragma: no cover
예제 #10
0
    def convert(self, source):
        """
        """
        ast = None
        lexer = pypred_parser.get_lexer()
        parser = pypred_parser.get_parser()

        try:
            ast = parser.parse(source, lexer)
        except AttributeError:
            raise SyntaxError('Could not convert predicate %s' % source)

        if parser.errors or lexer.errors:
            raise SyntaxError(
                'Could not convert due to the following errors %s' %
                (parser.errors + lexer.errors))

        if type(ast) == Literal:
            raise SyntaxError('Invalid predicate %s' % source)

        return self.convert_tree(ast)  # pragma: no cover
예제 #11
0
파일: test_ast.py 프로젝트: armon/pypred
 def ast(self, inp):
     lexer = parser.get_lexer()
     p = parser.get_parser(lexer=lexer)
     return p.parse(inp, lexer=lexer)
예제 #12
0
파일: test_ast.py 프로젝트: dungba88/pypred
 def ast(self, inp):
     lexer = parser.get_lexer()
     p = parser.get_parser(lexer=lexer)
     return p.parse(inp, lexer=lexer)
예제 #13
0
 def test_error_end(self):
     inp = "false and"
     lexer = parser.get_lexer()
     p = parser.get_parser()
     with pytest.raises(SyntaxError):
         p.parse(inp, lexer=lexer)
예제 #14
0
 def test_error_end(self):
     inp = "false and"
     lexer = parser.get_lexer()
     p = parser.get_parser()
     with pytest.raises(SyntaxError):
         p.parse(inp, lexer=lexer)