diff --git a/bob/bio/base/test/utils.py b/bob/bio/base/test/utils.py index 353078cf4c59ea8e583a58fa891f71d91d6e4fe4..a3e77135768a9fddbae9fdf8b5c07a19f6923c3b 100644 --- a/bob/bio/base/test/utils.py +++ b/bob/bio/base/test/utils.py @@ -58,6 +58,20 @@ def grid_available(test): 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''' + def wrapped_function(test): + @functools.wraps(test) + def wrapper(*args, **kwargs): + try: + __import__('bob.db.%s' % dbname) + return test(*args, **kwargs) + except ImportError as e: + raise SkipTest("Skipping test since the database bob.db.%s seems not to be available: %s" % (dbname,e)) + return wrapper + return wrapped_function + atnt_default_directory = os.environ['ATNT_DATABASE_DIRECTORY'] if 'ATNT_DATABASE_DIRECTORY' in os.environ else "/idiap/group/biometric/databases/orl/" global atnt_downloaded_directory