tst_MLW_grammar.py 1.36 KB
Newer Older
1
2
#!/usr/bin/python3

di68kap's avatar
di68kap committed
3
"""test_MLW_grammar.py - unit tests for the MLW grammar 
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

Author: Eckhart Arnold <arnold@badw.de>

Copyright 2017 Bavarian Academy of Sciences and Humanities

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

Eckhart Arnold's avatar
Eckhart Arnold committed
22
import sys
23
24

sys.path.extend(['../../', '../', './'])
Eckhart Arnold's avatar
Eckhart Arnold committed
25

di68kap's avatar
di68kap committed
26
from DHParser import dsl
27
from DHParser import testing
di68kap's avatar
di68kap committed
28
from DHParser import toolkit
di68kap's avatar
di68kap committed
29
30
31
32
33
34

if not dsl.recompile_grammar('MLW.ebnf', force=True):  # recompiles Grammar only if it has changed
    with open('MLW_ebnf_ERRORS.txt') as f:
        print(f.read())
    sys.exit(1)

35
from MLWCompiler import get_grammar, get_transformer
di68kap's avatar
di68kap committed
36

di68kap's avatar
di68kap committed
37
38
with toolkit.logging(True):
    error_report = testing.grammar_suite('grammar_tests', get_grammar, get_transformer,
di68kap's avatar
di68kap committed
39
                                         fn_patterns=['*_test*'],
di68kap's avatar
di68kap committed
40
                                         verbose=True)
di68kap's avatar
di68kap committed
41
    print(error_report)
di68kap's avatar
di68kap committed
42
    print(error_report[:error_report.find('\n')])
di68kap's avatar
di68kap committed
43