Esempio n. 1
0
def test_parser_with_context():
    """Test parser with application context."""
    queries = (
        ("",
         EmptyQuery('')),
        ("    \t",
         EmptyQuery('    \t')),
        ("bar",
         ValueQuery(Value('bar'))),
        ("2004",
         ValueQuery(Value('2004'))),
        ("'bar'",
         ValueQuery(SingleQuotedValue('bar'))),
        ("\"bar\"",
         ValueQuery(DoubleQuotedValue('bar'))),
        ("J. Ellis",
         AndOp(ValueQuery(Value('J.')), ValueQuery(Value('Ellis')))),
        ("$e^{+}e^{-}$",
         ValueQuery(Value('$e^{+}e^{-}$'))),
        ("foo:somthing",
         AndOp(ValueQuery(Value('foo:')), ValueQuery(Value('somthing')))),
        ("foo:bar:somthing",
         AndOp(ValueQuery(Value('foo:bar:')), ValueQuery(Value('somthing')))),
        ("title:bar:somthing",
         KeywordOp(Keyword('title'), Value('bar:somthing'))),
        ("035__a:oai:arXiv.org:1503.06238",
         KeywordOp(Keyword('035__a'), Value('oai:arXiv.org:1503.06238'))),
    )

    from invenio_query_parser.walkers import repr_printer
    from invenio_query_parser.contrib.spires import converter
    build_valid_keywords_grammar(keywords=['title', '035__a'])
    parser = converter.SpiresToInvenioSyntaxConverter()

    for count, args in enumerate(queries):
        tree = parser.parse_query(args[0])
        printer = repr_printer.TreeRepr()
        assert tree == args[1], "parsed tree: %s\nexpected tree: %s" % (
            tree.accept(printer), args[1].accept(printer))
Esempio n. 2
0
 def __init__(self):
     self.converter = pypeg_to_ast.PypegConverter()
     self.printer = repr_printer.TreeRepr()
Esempio n. 3
0
 def func(self):
     from invenio_query_parser.walkers import repr_printer
     tree = self.parser.parse_query(query)
     printer = repr_printer.TreeRepr()
     assert tree == expected, "parsed tree: %s\nexpected tree: %s" % (
         tree.accept(printer), expected.accept(printer))