Exemple #1
0
def test_parser_lark(patch, parser):
    patch.init(Lark)
    patch.object(Grammar, 'grammar')
    patch.many(Parser, ['default_ebnf', 'indenter'])
    result = parser.lark()
    Grammar.grammar.assert_called_with(Parser.default_ebnf())
    Lark.__init__.assert_called_with(Grammar.grammar(),
                                     parser='lalr',
                                     postlex=Parser.indenter())
    assert isinstance(result, Lark)
Exemple #2
0
def test_parser_default_ebnf(patch):
    patch.many(os.path, ['dirname', 'join', 'realpath'])
    result = Parser.default_ebnf()
    os.path.join.assert_called_with(os.path.dirname(), '..', 'grammar',
                                    'grammar.ebnf')
    os.path.realpath.assert_called_with(os.path.join())
    assert result == os.path.realpath()
Exemple #3
0
def test_app_parse(patch):
    patch.object(io, 'open')
    patch.init(Parser)
    patch.object(Parser, 'parse')
    result = Burpless.parse('path')
    io.open.assert_called_with(os.path.join(os.getcwd(), 'path'), 'r')
    Parser.parse.assert_called_with(io.open().__enter__().read())
    assert result == Parser.parse()
Exemple #4
0
def test_parser_parse(patch, parser):
    patch.many(Parser, ['lark', 'transformer'])
    result = parser.parse('source')
    Parser.lark().parse.assert_called_with('source\n')
    Parser.transformer().transform.assert_called_with(Parser.lark().parse())
    assert result == Parser.transformer().transform()
Exemple #5
0
def test_parser_transformer(patch):
    patch.init(Transformer)
    result = Parser.transformer()
    assert isinstance(result, Transformer)
Exemple #6
0
def test_parser_indenter(patch):
    patch.init(CustomIndenter)
    result = Parser.indenter()
    assert isinstance(result, CustomIndenter)
Exemple #7
0
def test_parser_init__keyargs():
    parser = Parser('algo', 'ebnf')
    assert parser.algo == 'algo'
    assert parser.ebnf_file == 'ebnf'
Exemple #8
0
def parser():
    return Parser()