Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
9.2.2023: Due to updates GitLab will be unavailable for some minutes between 9:00 and 11:00.
Open sidebar
badw-it
DHParser
Commits
5220a7f7
Commit
5220a7f7
authored
Jul 31, 2018
by
di68kap
Browse files
- inferus vervollständigt
parent
07003c56
Changes
3
Show whitespace changes
Inline
Side-by-side
DHParser/log.py
View file @
5220a7f7
...
...
@@ -372,7 +372,7 @@ def log_ST(syntax_tree, log_file_name):
f
.
write
(
syntax_tree
.
as_sxpr
())
LOG_SIZE_THRESHOLD
=
10000
0
# maximum number of history records to log
LOG_SIZE_THRESHOLD
=
10000
# maximum number of history records to log
LOG_TAIL_THRESHOLD
=
500
# maximum number of history recors for "tail log"
...
...
DHParser/testing.py
View file @
5220a7f7
...
...
@@ -44,8 +44,9 @@ from DHParser.toolkit import re, typing
from
typing
import
Tuple
__all__
=
(
'unit_from_config
file
'
,
__all__
=
(
'unit_from_config'
,
'unit_from_json'
,
'TEST_READERS'
,
'unit_from_file'
,
'get_report'
,
'grammar_unit'
,
...
...
@@ -93,12 +94,12 @@ RX_ENTRY = re.compile('\s*(\w+\*?)\s*:\s*(?:{value})\s*'.format(value=RE_VALUE))
RX_COMMENT
=
re
.
compile
(
'\s*#.*
\n
'
)
def
unit_from_config
file
(
config_
filename
):
def
unit_from_config
(
config_
str
):
""" Reads grammar unit tests contained in a file in config file (.ini)
syntax.
Args:
config_
filename
(str): A
config file containing
Grammar unit-tests
config_
str
(str): A
string containing a config-file with
Grammar unit-tests
Returns:
A dictionary representing the unit tests.
...
...
@@ -112,9 +113,7 @@ def unit_from_configfile(config_filename):
m
=
RX_COMMENT
.
match
(
txt
,
pos
)
return
pos
with
open
(
config_filename
,
'r'
,
encoding
=
"utf-8"
)
as
f
:
cfg
=
f
.
read
()
cfg
=
cfg
.
replace
(
'
\t
'
,
' '
)
cfg
=
config_str
.
replace
(
'
\t
'
,
' '
)
OD
=
collections
.
OrderedDict
unit
=
OD
()
...
...
@@ -154,31 +153,41 @@ def unit_from_configfile(config_filename):
return
unit
def
unit_from_json
(
json_
filename
):
def
unit_from_json
(
json_
str
):
"""
Reads grammar unit tests from a json
file
.
Reads grammar unit tests from a json
string
.
"""
with
open
(
json_filename
,
'r'
,
encoding
=
'utf8'
)
as
f
:
unit
=
json
.
load
(
f
)
unit
=
json
.
loads
(
json_str
)
for
symbol
in
unit
:
for
stage
in
unit
[
symbol
]:
if
stage
not
in
UNIT_STAGES
:
raise
ValueError
(
'Test stage %s not in: %s'
%
(
stage
,
str
(
UNIT_STAGES
)))
return
unit
# TODO: add support for yaml, cson, toml
# A dictionary associating file endings with reader functions that
# transfrom strings containing the file's content to a nested dictionary
# structure of test cases.
TEST_READERS
=
{
'.ini'
:
unit_from_config
,
'.json'
:
unit_from_json
}
def
unit_from_file
(
filename
):
"""
Reads a grammar unit test from a file. The format of the file is
determined by the ending of its name.
"""
if
filename
.
endswith
(
".json"
):
test_unit
=
unit_from_json
(
filename
)
elif
filename
.
endswith
(
".ini"
):
test_unit
=
unit_from_configfile
(
filename
)
else
:
try
:
reader
=
TEST_READERS
[
os
.
path
.
splitext
(
filename
)[
1
].
lower
()]
with
open
(
filename
,
'r'
,
encoding
=
'utf8'
)
as
f
:
data
=
f
.
read
()
test_unit
=
reader
(
data
)
except
KeyError
:
raise
ValueError
(
"Unknown unit test file type: "
+
filename
[
filename
.
rfind
(
'.'
):])
# Check for ambiguous Test names
...
...
dhparser.py
View file @
5220a7f7
...
...
@@ -155,7 +155,14 @@ def run_grammar_tests(glob_pattern):
if __name__ == '__main__':
arg = sys.argv[1] if len(sys.argv) > 1 else '*_test_*.ini'
if (len(sys.argv) == 2 and (arg.endswith('.ebnf') or (os.path.isfile(sys.argv[1]) and
os.path.splitext(sys.argv[1])[1].lower() in testing.TEST_READERS.keys()))):
# if called with a single filename that is either an EBNF file or a known
# test file type then use the given argument
arg = sys.argv[1]
else:
# otherwise run all tests in the test directory
arg = '*_test_*.ini'
if arg.endswith('.ebnf'):
recompile_grammar(arg, force=True)
else:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment