Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.bio.base
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
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
bob
bob.bio.base
Commits
9ccf6ba8
Commit
9ccf6ba8
authored
4 years ago
by
Tiago de Freitas Pereira
Browse files
Options
Downloads
Patches
Plain Diff
[py] Implemented generic decorator that tests if a library is available
parent
cdf7f1af
No related branches found
No related tags found
1 merge request
!206
Created decorators
Pipeline
#45393
failed
4 years ago
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob/bio/base/test/utils.py
+12
-38
12 additions, 38 deletions
bob/bio/base/test/utils.py
with
12 additions
and
38 deletions
bob/bio/base/test/utils.py
+
12
−
38
View file @
9ccf6ba8
...
...
@@ -9,6 +9,7 @@ import sys
import
functools
from
nose.plugins.skip
import
SkipTest
from
bob.extension.download
import
download_and_unzip
import
importlib
# based on: http://stackoverflow.com/questions/6796492/temporarily-redirect-stdout-stderr
class
Quiet
(
object
):
...
...
@@ -66,21 +67,6 @@ def random_training_set_by_id(shape, count=50, minimum=0, maximum=1, seed=42):
return
train_set
def
grid_available
(
test
):
"""
Decorator to check if the gridtk is present, before running the test
"""
@functools.wraps
(
test
)
def
wrapper
(
*
args
,
**
kwargs
):
try
:
import
gridtk
return
test
(
*
args
,
**
kwargs
)
except
ImportError
as
e
:
raise
SkipTest
(
"
Skipping test since gridtk is not available: %s
"
%
e
)
return
wrapper
def
db_available
(
dbname
):
"""
Decorator that checks if a given bob.db database is available.
This is a double-indirect decorator, see http://thecodeship.com/patterns/guide-to-python-function-decorators
"""
...
...
@@ -149,31 +135,19 @@ def atnt_database_directory():
return
atnt_downloaded_directory
def
mxnet
_available
(
test
):
def
is_library
_available
(
library
):
"""
Decorator to check if the mxnet is present, before running the test
"""
@functools.wraps
(
test
)
def
wrapper
(
*
args
,
**
kwargs
):
try
:
import
mxnet
return
test
(
*
args
,
**
kwargs
)
except
ImportError
as
e
:
raise
SkipTest
(
"
Skipping test since `mxnet` is not available: %s
"
%
e
)
return
wrapper
def
tensorflow_available
(
test
):
"""
Decorator to check if the mxnet is present, before running the test
"""
def
_is_library_available
(
function
):
@functools.wraps
(
function
)
def
wrapper
(
*
args
,
**
kwargs
):
try
:
importlib
.
import_module
(
library
)
@functools.wraps
(
test
)
def
wrapper
(
*
args
,
**
kwargs
):
try
:
import
tensorflow
return
function
(
*
args
,
**
kwargs
)
except
ImportError
as
e
:
raise
SkipTest
(
"
Skipping test since `mxnet` is not available: %s
"
%
e
)
return
test
(
*
args
,
**
kwargs
)
except
ImportError
as
e
:
raise
SkipTest
(
"
Skipping test since `mxnet` is not available: %s
"
%
e
)
return
wrapper
return
wrapper
return
_is_library_available
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