Commit 965b31d0 authored by di68kap's avatar di68kap

- bugfix: remove REPORT subdir after testing

parent 9d0e948f
......@@ -55,7 +55,8 @@ __all__ = ('unit_from_config',
'extract_symbols',
'create_test_templates',
'reset_unit',
'runner')
'runner',
'clean_report')
UNIT_STAGES = {'match*', 'match', 'fail', 'ast', 'cst'}
......@@ -798,6 +799,7 @@ def run_file(fname):
exec('import ' + fname[:-3])
runner('', eval(fname[:-3]).__dict__)
def run_with_log(logdir, f):
"""
Run `grammar_unit()` with logs written to `log_dir` or no logs if `log_dir`
......@@ -808,6 +810,7 @@ def run_with_log(logdir, f):
with logging(logdir):
run_file(f)
def run_path(path):
"""Runs all unit tests in `path`"""
if os.path.isdir(path):
......@@ -835,3 +838,17 @@ def run_path(path):
run_file(fname)
sys.path.pop()
def clean_report():
"""Deletes any test-report-files in the REPORT sub-directory and removes
the REPORT sub-directory, if it is empty after deleting the files."""
if os.path.exists('REPORT'):
files = os.listdir('REPORT')
flag = False
for file in files:
if re.match(r'\w*_test_\d+\.md', file):
os.remove(os.path.join('REPORT', file))
else:
flag = True
if not flag:
os.rmdir('REPORT')
......@@ -20,9 +20,12 @@ See the License for the specific language governing permissions and
limitations under the License.
"""
import os
import sys
from multiprocessing import Pool
scriptdir = os.path.dirname(os.path.realpath(__file__))
sys.path.extend(['../', './'])
from DHParser.toolkit import compile_python_object, get_config_value, set_config_value, re
......@@ -33,7 +36,7 @@ from DHParser.syntaxtree import WHITESPACE_PTYPE
from DHParser.ebnf import get_ebnf_grammar, get_ebnf_transformer, EBNFTransform, \
get_ebnf_compiler, compile_ebnf, DHPARSER_IMPORTS
from DHParser.dsl import CompilationError, compileDSL, grammar_provider
from DHParser.testing import grammar_unit
from DHParser.testing import grammar_unit, clean_report
class TestDirectives:
......@@ -130,8 +133,14 @@ class TestEBNFParser:
}
def setup(self):
self.save_dir = os.getcwd()
os.chdir(scriptdir)
self.EBNF = get_ebnf_grammar()
def teardown(self):
clean_report()
os.chdir(self.save_dir)
def test_RE(self):
gr = get_ebnf_grammar()
m = gr.regexp.parsers[0].regexp.match(r'/[\\\\]/ xxx /')
......
......@@ -20,10 +20,11 @@ limitations under the License.
"""
import os
import re
import sys
from functools import partial
scriptdir = os.path.dirname(os.path.realpath(__file__))
sys.path.extend(['../', './'])
from DHParser.syntaxtree import parse_sxpr, flatten_sxpr, TOKEN_PTYPE
......@@ -32,9 +33,7 @@ from DHParser.transform import traverse, remove_whitespace, remove_empty, \
from DHParser.dsl import grammar_provider
from DHParser.error import Error
from DHParser.testing import get_report, grammar_unit, unit_from_file, \
reset_unit
from DHParser.log import logging
clean_report
CFG_FILE_1 = '''
# a comment
......@@ -92,6 +91,8 @@ M1*: """Trigger CST-output with an asterix!"""
class TestTestfiles:
def setup(self):
self.save_dir = os.getcwd()
os.chdir(scriptdir)
with open('configfile_test_1.ini', 'w', encoding="utf-8") as f:
f.write(CFG_FILE_1)
with open('configfile_test_2.ini', 'w', encoding="utf-8") as f:
......@@ -103,6 +104,7 @@ class TestTestfiles:
os.remove('configfile_test_1.ini')
os.remove('configfile_test_2.ini')
os.remove('configfile_test_3.ini')
os.chdir(self.save_dir)
def test_unit_from_config_file(self):
unit = unit_from_file('configfile_test_1.ini')
......@@ -146,19 +148,6 @@ ARITHMETIC_EBNF_transformation_table = {
ARITHMETIC_EBNFTransform = partial(traverse, processing_table=ARITHMETIC_EBNF_transformation_table)
def clean_report():
if os.path.exists('REPORT'):
files = os.listdir('REPORT')
flag = False
for file in files:
if re.match(r'unit_test_\d+\.md', file):
os.remove(os.path.join('REPORT', file))
else:
flag = True
if not flag:
os.rmdir('REPORT')
class TestGrammarTest:
cases = {
"factor": {
......@@ -213,8 +202,13 @@ class TestGrammarTest:
}
}
def setup(self):
self.save_dir = os.getcwd()
os.chdir(scriptdir)
def teardown(self):
clean_report()
os.chdir(self.save_dir)
def test_testing_grammar(self):
parser_fac = grammar_provider(ARITHMETIC_EBNF)
......@@ -289,11 +283,14 @@ class TestLookahead:
}
def setup(self):
self.save_dir = os.getcwd()
os.chdir(scriptdir)
self.grammar_fac = grammar_provider(TestLookahead.EBNF)
self.trans_fac = lambda : partial(traverse, processing_table={"*": [flatten, remove_empty]})
def teardown(self):
clean_report()
os.chdir(self.save_dir)
def test_selftest(self):
doc = """
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment