Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
badw-it
DHParser
Commits
ab609a77
Commit
ab609a77
authored
May 24, 2021
by
Eckhart Arnold
Browse files
testing.py: bugfix: teardown()-method was not called
parent
d07f3b0f
Changes
4
Hide whitespace changes
Inline
Side-by-side
DHParser/testing.py
View file @
ab609a77
...
...
@@ -783,30 +783,26 @@ def run_tests_in_class(cls_name, namespace, methods=()):
exec
(
"instance = "
+
cls
+
"()"
,
nspace
)
instance
=
nspace
[
"instance"
]
setup
=
instance
.
setup
if
"setup"
in
dir
(
instance
)
else
lambda
:
0
teardown
=
instance
.
teardown
if
"teardown"
in
dir
(
obj
)
else
lambda
:
0
teardown
=
instance
.
teardown
if
"teardown"
in
dir
(
instance
)
else
lambda
:
0
return
instance
,
setup
,
teardown
obj
=
None
try
:
if
methods
:
obj
,
setup
,
teardown
=
instantiate
(
cls_name
,
namespace
)
for
name
in
methods
:
if
methods
:
obj
,
setup
,
teardown
=
instantiate
(
cls_name
,
namespace
)
for
name
in
methods
:
func
=
obj
.
__getattribute__
(
name
)
if
callable
(
func
):
print
(
"Running "
+
cls_name
+
"."
+
name
)
setup
();
func
();
teardown
()
# exec('obj.' + name + '()')
else
:
obj
,
setup
,
teardown
=
instantiate
(
cls_name
,
namespace
)
for
name
in
dir
(
obj
):
if
name
.
lower
().
startswith
(
"test"
):
func
=
obj
.
__getattribute__
(
name
)
if
callable
(
func
):
print
(
"Running "
+
cls_name
+
"."
+
name
)
setup
();
func
();
teardown
()
# exec('obj.' + name + '()')
else
:
obj
,
setup
,
teardown
=
instantiate
(
cls_name
,
namespace
)
for
name
in
dir
(
obj
):
if
name
.
lower
().
startswith
(
"test"
):
func
=
obj
.
__getattribute__
(
name
)
if
callable
(
func
):
print
(
"Running "
+
cls_name
+
"."
+
name
)
setup
();
func
();
teardown
()
finally
:
if
"teardown"
in
dir
(
obj
):
obj
.
teardown
()
def
run_test_function
(
func_name
,
namespace
):
...
...
tests/test_preprocess.py
View file @
ab609a77
...
...
@@ -268,7 +268,6 @@ class TestIncludes:
os
.
rmdir
(
self
.
dirname
)
os
.
chdir
(
TestIncludes
.
cwd
)
def
create_files
(
self
,
files
:
Dict
[
str
,
str
]):
for
name
,
content
in
files
.
items
():
with
open
(
name
,
'w'
,
encoding
=
'utf-8'
)
as
f
:
...
...
tests/test_testing.py
View file @
ab609a77
...
...
@@ -118,10 +118,10 @@ class TestTestfiles:
f
.
write
(
CFG_FILE_4
)
def
teardown
(
self
):
os
.
remove
(
self
.
cfg1
)
os
.
remove
(
self
.
cfg2
)
os
.
remove
(
self
.
cfg3
)
os
.
remove
(
self
.
cfg4
)
if
os
.
path
.
exists
(
self
.
cfg1
):
os
.
remove
(
self
.
cfg1
)
if
os
.
path
.
exists
(
self
.
cfg2
):
os
.
remove
(
self
.
cfg2
)
if
os
.
path
.
exists
(
self
.
cfg3
):
os
.
remove
(
self
.
cfg3
)
if
os
.
path
.
exists
(
self
.
cfg4
):
os
.
remove
(
self
.
cfg4
)
os
.
chdir
(
self
.
save_dir
)
def
test_unit_from_config_file
(
self
):
...
...
tests/test_toolkit.py
View file @
ab609a77
...
...
@@ -50,13 +50,13 @@ class TestLoggingAndLoading:
self
.
LOGDIR
=
os
.
path
.
abspath
(
os
.
path
.
join
(
scriptpath
,
"TESTLOGS"
+
str
(
os
.
getpid
())))
def
teardown
(
self
):
os
.
remove
(
self
.
filename
)
if
os
.
path
.
exists
(
self
.
filename
):
os
.
remove
(
self
.
filename
)
pycachedir
=
os
.
path
.
join
(
self
.
dirname
,
'__pycache__'
)
if
os
.
path
.
exists
(
pycachedir
):
for
fname
in
os
.
listdir
(
pycachedir
):
os
.
remove
(
os
.
path
.
join
(
pycachedir
,
fname
))
os
.
rmdir
(
pycachedir
)
os
.
rmdir
(
self
.
dirname
)
if
os
.
path
.
exists
(
self
.
dirname
):
os
.
rmdir
(
self
.
dirname
)
if
os
.
path
.
exists
(
self
.
LOGDIR
):
# for fname in os.listdir(self.LOGDIR):
# os.remove(os.path.join(self.LOGDIR, fname))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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