From d84630fa1b153e881e3715349257092347ce72c6 Mon Sep 17 00:00:00 2001
From: Manuel Gunther <siebenkopf@googlemail.com>
Date: Tue, 7 Jun 2016 12:52:42 -0600
Subject: [PATCH] Fixed newly introduced bug in bin/resources.py and added test
 case

---
 bob/bio/base/grid.py              |  2 ++
 bob/bio/base/script/resources.py  | 20 ++++++++++----------
 bob/bio/base/test/test_scripts.py |  8 ++++++++
 3 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/bob/bio/base/grid.py b/bob/bio/base/grid.py
index 9dcef208..a710bada 100644
--- a/bob/bio/base/grid.py
+++ b/bob/bio/base/grid.py
@@ -33,6 +33,8 @@ PREDEFINED_QUEUES = {
   'GPU'         : {'queue' : 'gpu'}
 }
 
+from . import utils
+
 class Grid:
   """This class is defining the options that are required to submit parallel jobs to the SGE grid, or jobs to the local queue.
 
diff --git a/bob/bio/base/script/resources.py b/bob/bio/base/script/resources.py
index 96ad1568..854dd80b 100644
--- a/bob/bio/base/script/resources.py
+++ b/bob/bio/base/script/resources.py
@@ -4,7 +4,7 @@ from __future__ import print_function
 import bob.bio.base
 import os
 
-def resources():
+def resources(command_line_parameters = None):
 
   import argparse
   parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.ArgumentDefaultsHelpFormatter)
@@ -18,43 +18,43 @@ def resources():
   parser.add_argument("--no-strip-dummy", '-s', action = 'store_true',
                       help = "If given, the dummy elements (usually used for testing purposes only) are **not** removed from the list.")
 
-  args = parser.parse_args()
+  args = parser.parse_args(command_line_parameters)
 
-  kwargs = {'verbose' : args.verbose}
+  kwargs = {'verbose' : args.details}
   if args.no_strip_dummy:
     kwargs['strip'] = []
 
 
-  if 'd' in args.details or 'database' in args.details:
+  if 'd' in args.types or 'database' in args.types:
     print ("\nList of registered databases:")
     print (bob.bio.base.list_resources('database', **kwargs))
 
-  if 'p' in args.details or 'preprocessor' in args.details:
+  if 'p' in args.types or 'preprocessor' in args.types:
     print ("\nList of registered preprocessors:")
     print (bob.bio.base.list_resources('preprocessor', **kwargs))
 
-  if 'e' in args.details or 'extractor' in args.details:
+  if 'e' in args.types or 'extractor' in args.types:
     print ("\nList of registered extractors:")
     print (bob.bio.base.list_resources('extractor', **kwargs))
 
-  if 'a' in args.details or 'algorithm' in args.details:
+  if 'a' in args.types or 'algorithm' in args.types:
     print ("\nList of registered algorithms:")
     print (bob.bio.base.list_resources('algorithm', **kwargs))
 
-  if 'g' in args.details or 'grid' in args.details:
+  if 'g' in args.types or 'grid' in args.types:
     print ("\nList of registered grid configurations:")
     print (bob.bio.base.list_resources('grid', **kwargs))
 
   print()
 
-def databases():
+def databases(command_line_parameters = None):
   import argparse
   database_replacement = "%s/.bob_bio_databases.txt" % os.environ["HOME"]
 
   parser = argparse.ArgumentParser(description="Prints a list of directories for registered databases", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
   parser.add_argument('-D', '--database-directories-file', metavar = 'FILE', default = database_replacement, help = 'The file, where database directories are stored (to avoid changing the database configurations)')
 
-  args = parser.parse_args()
+  args = parser.parse_args(command_line_parameters)
 
   # get registered databases
   databases = bob.bio.base.utils.resources.database_directories(replacements=args.database_directories_file)
diff --git a/bob/bio/base/test/test_scripts.py b/bob/bio/base/test/test_scripts.py
index 1ef855f5..92280814 100644
--- a/bob/bio/base/test/test_scripts.py
+++ b/bob/bio/base/test/test_scripts.py
@@ -365,6 +365,14 @@ def test_evaluate():
   os.rmdir(test_dir)
 
 
+def test_resources():
+  # simply test that the collect_results script works
+  from bob.bio.base.script.resources import resources, databases
+  with utils.Quiet():
+    resources(['--types', 'database', 'preprocessor', 'extractor', 'algorithm', 'grid', '--details'])
+    databases([])
+
+
 def test_collect_results():
   # simply test that the collect_results script works
   test_dir = tempfile.mkdtemp(prefix='bobtest_')
-- 
GitLab