Example #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))
 def setup_class(cls):
     cls.walker = spires_to_invenio.SpiresToInvenio
     cls.parser = converter.SpiresToInvenioSyntaxConverter()
 def setup_class(cls):
     from invenio_query_parser.contrib.spires import converter
     cls.parser = converter.SpiresToInvenioSyntaxConverter()
Example #4
0
 def setup_class(cls):
     from invenio_query_parser.contrib.spires import converter
     cls.parser = converter.SpiresToInvenioSyntaxConverter()
     build_valid_keywords_grammar()
 def setup_class(cls):
     cls.walker = spires_to_invenio.SpiresToInvenio
     cls.parser = converter.SpiresToInvenioSyntaxConverter()
     build_valid_keywords_grammar()