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
341b03ab
Commit
341b03ab
authored
Mar 28, 2018
by
di68kap
Browse files
- DHParser/testing.py: runner now also accepts "test_XXX()"-functions as unit tests
parent
f84a5344
Changes
1
Hide whitespace changes
Inline
Side-by-side
DHParser/testing.py
View file @
341b03ab
...
...
@@ -369,12 +369,16 @@ def grammar_suite(directory, parser_factory, transformer_factory,
return
''
def
runner
(
tests
,
namespace
):
def
runner
(
test
_classe
s
,
namespace
):
"""
Runs all or some selected Python unit tests found in the
namespace. To run all tests in a module, call
``runner("", globals())`` from within that module.
Unit-Tests are either classes, the name of which starts with
"Test" and methods, the name of which starts with "test" contained
in such classes or functions, the name of which starts with "test".
Args:
tests: Either a string or a list of strings that contains the
names of test or test classes. Each test and, in the case
...
...
@@ -403,18 +407,23 @@ def runner(tests, namespace):
obj
.
setup
()
return
obj
if
tests
:
if
isinstance
(
tests
,
str
):
tests
=
tests
.
split
(
" "
)
if
test
_classe
s
:
if
isinstance
(
test
_classe
s
,
str
):
test
_classe
s
=
test
_classe
s
.
split
(
" "
)
else
:
# collect all test classes, in case no methods or classes have been passed explicitly
tests
=
[]
test_classes
=
[]
test_functions
=
[]
for
name
in
namespace
.
keys
():
if
name
.
lower
().
startswith
(
'test'
)
and
inspect
.
isclass
(
namespace
[
name
]):
tests
.
append
(
name
)
if
name
.
lower
().
startswith
(
'test'
):
if
inspect
.
isclass
(
namespace
[
name
]):
test_classes
.
append
(
name
)
elif
inspect
.
isfunction
(
namespace
[
name
]):
test_functions
.
append
(
name
)
obj
=
None
for
test
in
tests
:
for
test
in
test
_classe
s
:
try
:
if
test
.
find
(
'.'
)
>=
0
:
cls_name
,
method_name
=
test
.
split
(
'.'
)
...
...
@@ -430,3 +439,7 @@ def runner(tests, namespace):
finally
:
if
"teardown"
in
dir
(
obj
):
obj
.
teardown
()
for
test
in
test_functions
:
exec
(
test
+
'()'
,
namespace
)
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