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([])
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
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\"") ])
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
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
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
def ast(self, inp): lexer = parser.get_lexer() p = parser.get_parser(lexer=lexer) return p.parse(inp, lexer=lexer)
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)