Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
badw-it
DHParser
Commits
3ac74ef1
Commit
3ac74ef1
authored
Jul 11, 2018
by
di68kap
Browse files
- Korrekturen: testing.py
parent
7aad87a8
Changes
2
Show whitespace changes
Inline
Side-by-side
DHParser/syntaxtree.py
View file @
3ac74ef1
...
@@ -430,7 +430,9 @@ class Node(collections.abc.Sized):
...
@@ -430,7 +430,9 @@ class Node(collections.abc.Sized):
@
property
@
property
def
content
(
self
)
->
str
:
def
content
(
self
)
->
str
:
"""
"""
Returns content as string, omitting error messages.
Returns content as string, omitting error messages. If the node has
child-nodes, the string content of the child-nodes is recursively read
and then concatenated.
"""
"""
if
self
.
_content
is
None
:
if
self
.
_content
is
None
:
if
self
.
children
:
if
self
.
children
:
...
@@ -442,6 +444,11 @@ class Node(collections.abc.Sized):
...
@@ -442,6 +444,11 @@ class Node(collections.abc.Sized):
return
self
.
_content
return
self
.
_content
@
content
.
setter
def
content
(
self
,
content
:
str
):
self
.
result
=
content
@
property
@
property
def
structure
(
self
)
->
str
:
def
structure
(
self
)
->
str
:
"""
"""
...
...
DHParser/testing.py
View file @
3ac74ef1
...
@@ -184,6 +184,14 @@ def unit_from_file(filename):
...
@@ -184,6 +184,14 @@ def unit_from_file(filename):
# Check for ambiguous Test names
# Check for ambiguous Test names
errors
=
[]
errors
=
[]
for
parser_name
,
tests
in
test_unit
.
items
():
for
parser_name
,
tests
in
test_unit
.
items
():
# normalize case for test category names
keys
=
list
(
tests
.
keys
())
for
key
in
keys
:
new_key
=
key
.
lower
()
if
new_key
!=
key
:
tests
[
new_key
]
=
tests
[
keys
]
del
tests
[
keys
]
m_names
=
set
(
tests
.
get
(
'match'
,
dict
()).
keys
())
m_names
=
set
(
tests
.
get
(
'match'
,
dict
()).
keys
())
f_names
=
set
(
tests
.
get
(
'fail'
,
dict
()).
keys
())
f_names
=
set
(
tests
.
get
(
'fail'
,
dict
()).
keys
())
intersection
=
list
(
m_names
&
f_names
)
intersection
=
list
(
m_names
&
f_names
)
...
@@ -265,6 +273,21 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve
...
@@ -265,6 +273,21 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve
"""
"""
Unit tests for a grammar-parser and ast transformations.
Unit tests for a grammar-parser and ast transformations.
"""
"""
def
clean_key
(
k
):
try
:
return
k
.
replace
(
'*'
,
''
)
except
AttributeError
:
return
k
def
get
(
tests
,
category
,
key
):
try
:
value
=
tests
[
category
][
key
]
if
key
in
tests
[
category
]
\
else
tests
[
category
][
clean_key
(
key
)]
except
KeyError
:
raise
AssertionError
(
'%s-test %s for parser %s missing !?'
%
(
category
,
test_name
,
parser_name
))
return
value
if
isinstance
(
test_unit
,
str
):
if
isinstance
(
test_unit
,
str
):
_
,
unit_name
=
os
.
path
.
split
(
os
.
path
.
splitext
(
test_unit
)[
0
])
_
,
unit_name
=
os
.
path
.
split
(
os
.
path
.
splitext
(
test_unit
)[
0
])
test_unit
=
unit_from_file
(
test_unit
)
test_unit
=
unit_from_file
(
test_unit
)
...
@@ -289,12 +312,12 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve
...
@@ -289,12 +312,12 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve
match_tests
=
set
(
tests
[
'match'
].
keys
())
if
'match'
in
tests
else
set
()
match_tests
=
set
(
tests
[
'match'
].
keys
())
if
'match'
in
tests
else
set
()
if
'ast'
in
tests
:
if
'ast'
in
tests
:
ast_tests
=
set
(
tests
[
'ast'
].
keys
())
ast_tests
=
set
(
tests
[
'ast'
].
keys
())
if
not
ast_tests
<=
match_tests
:
if
not
{
clean_key
(
k
)
for
k
in
ast_tests
}
<=
{
clean_key
(
k
)
for
k
in
match_tests
}
:
raise
AssertionError
(
'AST-Tests %s lack corresponding match-tests!'
raise
AssertionError
(
'AST-Tests %s
for parser %s
lack corresponding match-tests!'
%
str
(
ast_tests
-
match_tests
))
%
(
str
(
ast_tests
-
match_tests
)
,
parser_name
)
)
if
'cst'
in
tests
:
if
'cst'
in
tests
:
cst_tests
=
set
(
tests
[
'cst'
].
keys
())
cst_tests
=
set
(
tests
[
'cst'
].
keys
())
if
not
cst_tests
<=
match_tests
:
if
not
{
clean_key
(
k
)
for
k
in
cst_tests
}
<=
{
clean_key
(
k
)
for
k
in
match_tests
}
:
raise
AssertionError
(
'CST-Tests %s lack corresponding match-tests!'
raise
AssertionError
(
'CST-Tests %s lack corresponding match-tests!'
%
str
(
cst_tests
-
match_tests
))
%
str
(
cst_tests
-
match_tests
))
...
@@ -321,24 +344,22 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve
...
@@ -321,24 +344,22 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve
errata
.
append
(
'Match test "%s" for parser "%s" failed:
\n\t
Expr.: %s
\n\n\t
%s
\n\n
'
%
errata
.
append
(
'Match test "%s" for parser "%s" failed:
\n\t
Expr.: %s
\n\n\t
%s
\n\n
'
%
(
test_name
,
parser_name
,
'
\n\t
'
.
join
(
test_code
.
split
(
'
\n
'
)),
(
test_name
,
parser_name
,
'
\n\t
'
.
join
(
test_code
.
split
(
'
\n
'
)),
'
\n\t
'
.
join
(
str
(
m
).
replace
(
'
\n
'
,
'
\n\t\t
'
)
for
m
in
errors
)))
'
\n\t
'
.
join
(
str
(
m
).
replace
(
'
\n
'
,
'
\n\t\t
'
)
for
m
in
errors
)))
tests
.
setdefault
(
'__err__'
,
{})[
test_name
]
=
errata
[
-
1
]
#
tests.setdefault('__err__', {})[test_name] = errata[-1]
# write parsing-history log only in case of failure!
# write parsing-history log only in case of failure!
if
is_logging
():
if
is_logging
():
log_parsing_history
(
parser
,
"match_%s_%s.log"
%
(
parser_name
,
clean_test_name
))
log_parsing_history
(
parser
,
"match_%s_%s.log"
%
(
parser_name
,
clean_test_name
))
elif
"cst"
in
tests
and
parse_sxpr
(
tests
[
"cst"
][
test_name
]
)
!=
cst
:
elif
"cst"
in
tests
and
parse_sxpr
(
get
(
tests
,
"cst"
,
test_name
)
)
!=
cst
:
errata
.
append
(
'Concrete syntax tree test "%s" for parser "%s" failed:
\n
%s'
%
errata
.
append
(
'Concrete syntax tree test "%s" for parser "%s" failed:
\n
%s'
%
(
test_name
,
parser_name
,
cst
.
as_sxpr
()))
(
test_name
,
parser_name
,
cst
.
as_sxpr
()))
elif
"ast"
in
tests
:
elif
"ast"
in
tests
:
try
:
compare
=
parse_sxpr
(
get
(
tests
,
"ast"
,
test_name
))
compare
=
parse_sxpr
(
tests
[
"ast"
][
test_name
])
except
KeyError
:
pass
if
compare
!=
ast
:
if
compare
!=
ast
:
errata
.
append
(
'Abstract syntax tree test "%s" for parser "%s" failed:'
errata
.
append
(
'Abstract syntax tree test "%s" for parser "%s" failed:'
'
\n\t
Expr.: %s
\n\t
Expected: %s
\n\t
Received: %s'
'
\n\t
Expr.: %s
\n\t
Expected: %s
\n\t
Received: %s'
%
(
test_name
,
parser_name
,
'
\n\t
'
.
join
(
test_code
.
split
(
'
\n
'
)),
%
(
test_name
,
parser_name
,
'
\n\t
'
.
join
(
test_code
.
split
(
'
\n
'
)),
flatten_sxpr
(
compare
.
as_sxpr
()),
flatten_sxpr
(
compare
.
as_sxpr
()),
flatten_sxpr
(
ast
.
as_sxpr
())))
flatten_sxpr
(
ast
.
as_sxpr
())))
if
errata
:
tests
.
setdefault
(
'__err__'
,
{})[
test_name
]
=
errata
[
-
1
]
tests
.
setdefault
(
'__err__'
,
{})[
test_name
]
=
errata
[
-
1
]
if
verbose
:
if
verbose
:
print
(
infostr
+
(
"OK"
if
len
(
errata
)
==
errflag
else
"FAIL"
))
print
(
infostr
+
(
"OK"
if
len
(
errata
)
==
errflag
else
"FAIL"
))
...
...
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