Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
hysop
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
particle_methods
hysop
Commits
2ee2239e
Commit
2ee2239e
authored
8 years ago
by
Franck Pérignon
Browse files
Options
Downloads
Patches
Plain Diff
Add python file for tests, to define decorators
parent
aa4f79c6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
HySoP/hysop/testsenv.py
+76
-0
76 additions, 0 deletions
HySoP/hysop/testsenv.py
with
76 additions
and
0 deletions
HySoP/hysop/testsenv.py
0 → 100755
+
76
−
0
View file @
2ee2239e
"""
Set some functions and variables useful to run tests.
"""
from
hysop
import
__FFTW_ENABLED__
,
__GPU_ENABLED__
,
__SCALES_ENABLED__
import
pytest
import
shutil
from
hysop.tools.io_utils
import
IO
from
hysop.mpi
import
main_rank
import
os
# accept failing tests when fft is not enabled
if
__FFTW_ENABLED__
:
def
fftw_failed
(
f
):
"""
For fftw tests that must not fail
"""
return
f
else
:
fftw_failed
=
pytest
.
mark
.
xfail
# accept failing tests when scales is not enabled
if
__SCALES_ENABLED__
:
def
scales_failed
(
f
):
"""
For scales tests that must not fail
"""
return
f
else
:
scales_failed
=
pytest
.
mark
.
xfail
hysop_failed
=
pytest
.
mark
.
xfail
"""
Use this decorator for tests that must fail
"""
class
postclean
(
object
):
"""
A decorator to remove files in default path and working dir
at the end of the calling function.
"""
def
__init__
(
self
,
working_dir
=
None
):
"""
A decorator to remove files in default path and working dir
at the end of the calling function.
Usage:
@postclean
def test_name()
or
@postclean(working_dir)
def test_name()
working_dir = current test working directory.
"""
if
working_dir
is
not
None
:
if
not
os
.
path
.
exists
(
working_dir
):
working_dir
=
None
self
.
working_dir
=
working_dir
def
__call__
(
self
,
f
):
"""
Apply decorator
"""
def
wrapped_f
(
*
args
):
"""
return wrapped function + post exec
"""
f
(
*
args
)
print
"
RM ...
"
,
self
.
working_dir
,
IO
.
default_path
(),
main_rank
if
main_rank
==
0
:
if
os
.
path
.
exists
(
IO
.
default_path
()):
shutil
.
rmtree
(
IO
.
default_path
())
if
self
.
working_dir
is
not
None
:
if
os
.
path
.
exists
(
self
.
working_dir
):
shutil
.
rmtree
(
self
.
working_dir
)
return
wrapped_f
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment