Skip to content
Snippets Groups Projects
Commit 557cfdb4 authored by Manuel Günther's avatar Manuel Günther
Browse files

Made tests less verbose so that console output is not filled with garbage

parent 13364682
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,7 @@ from __future__ import print_function ...@@ -5,6 +5,7 @@ from __future__ import print_function
import bob.measure import bob.measure
import os import os
import sys
import shutil import shutil
import tempfile import tempfile
import numpy import numpy
...@@ -20,6 +21,22 @@ import pkg_resources ...@@ -20,6 +21,22 @@ import pkg_resources
regenerate_reference = False regenerate_reference = False
# based on: http://stackoverflow.com/questions/6796492/temporarily-redirect-stdout-stderr
class Quiet(object):
def __init__(self):
devnull = open(os.devnull, 'w')
self._stdout = devnull
self._stderr = devnull
def __enter__(self):
self.old_stdout, self.old_stderr = sys.stdout, sys.stderr
self.old_stdout.flush(); self.old_stderr.flush()
sys.stdout, sys.stderr = self._stdout, self._stderr
def __exit__(self, exc_type, exc_value, traceback):
self._stdout.flush(); self._stderr.flush()
sys.stdout = self.old_stdout
sys.stderr = self.old_stderr
dummy_dir = pkg_resources.resource_filename('bob.bio.base', 'test/dummy') dummy_dir = pkg_resources.resource_filename('bob.bio.base', 'test/dummy')
...@@ -72,8 +89,7 @@ def test_verify_local(): ...@@ -72,8 +89,7 @@ def test_verify_local():
'-e', os.path.join(dummy_dir, 'extractor.py'), '-e', os.path.join(dummy_dir, 'extractor.py'),
'-a', os.path.join(dummy_dir, 'algorithm.py'), '-a', os.path.join(dummy_dir, 'algorithm.py'),
'--zt-norm', '--zt-norm',
'-vvv', '-vs', 'test_local',
'-s', 'test_local',
'--temp-directory', test_dir, '--temp-directory', test_dir,
'--result-directory', test_dir '--result-directory', test_dir
] ]
...@@ -92,8 +108,7 @@ def test_verify_resources(): ...@@ -92,8 +108,7 @@ def test_verify_resources():
'-e', 'dummy', '-e', 'dummy',
'-a', 'dummy', '-a', 'dummy',
'--zt-norm', '--zt-norm',
'-vvv', '-vs', 'test_resource',
'-s', 'test_resource',
'--temp-directory', test_dir, '--temp-directory', test_dir,
'--result-directory', test_dir '--result-directory', test_dir
] ]
...@@ -112,8 +127,7 @@ def test_verify_commandline(): ...@@ -112,8 +127,7 @@ def test_verify_commandline():
'-e', 'bob.bio.base.test.dummy.extractor.DummyExtractor()', '-e', 'bob.bio.base.test.dummy.extractor.DummyExtractor()',
'-a', 'bob.bio.base.test.dummy.algorithm.DummyAlgorithm()', '-a', 'bob.bio.base.test.dummy.algorithm.DummyAlgorithm()',
'--zt-norm', '--zt-norm',
'-vvv', '-vs', 'test_commandline',
'-s', 'test_commandline',
'--temp-directory', test_dir, '--temp-directory', test_dir,
'--result-directory', test_dir '--result-directory', test_dir
] ]
...@@ -135,8 +149,7 @@ def test_verify_parallel(): ...@@ -135,8 +149,7 @@ def test_verify_parallel():
'-e', 'bob.bio.base.test.dummy.extractor.DummyExtractor()', '-e', 'bob.bio.base.test.dummy.extractor.DummyExtractor()',
'-a', 'dummy', '-a', 'dummy',
'--zt-norm', '--zt-norm',
'-vvv', '-vs', 'test_parallel',
'-s', 'test_parallel',
'--temp-directory', test_dir, '--temp-directory', test_dir,
'--result-directory', test_dir, '--result-directory', test_dir,
'-g', 'bob.bio.base.grid.Grid(grid_type = "local", number_of_parallel_processes = 2, scheduler_sleep_time = 0.1)', '-G', test_database, '--run-local-scheduler', '--stop-on-failure', '-g', 'bob.bio.base.grid.Grid(grid_type = "local", number_of_parallel_processes = 2, scheduler_sleep_time = 0.1)', '-G', test_database, '--run-local-scheduler', '--stop-on-failure',
...@@ -157,8 +170,7 @@ def test_verify_compressed(): ...@@ -157,8 +170,7 @@ def test_verify_compressed():
'-e', 'dummy', '-e', 'dummy',
'-a', 'dummy', '-a', 'dummy',
'--zt-norm', '--zt-norm',
'-vvv', '-vs', 'test_compressed',
'-s', 'test_compressed',
'--temp-directory', test_dir, '--temp-directory', test_dir,
'--result-directory', test_dir, '--result-directory', test_dir,
'--write-compressed-score-files' '--write-compressed-score-files'
...@@ -178,8 +190,7 @@ def test_verify_calibrate(): ...@@ -178,8 +190,7 @@ def test_verify_calibrate():
'-e', 'dummy', '-e', 'dummy',
'-a', 'dummy', '-a', 'dummy',
'--zt-norm', '--zt-norm',
'-vvv', '-vs', 'test_calibrate',
'-s', 'test_calibrate',
'--temp-directory', test_dir, '--temp-directory', test_dir,
'--result-directory', test_dir, '--result-directory', test_dir,
'--calibrate-scores' '--calibrate-scores'
...@@ -199,8 +210,7 @@ def test_verify_fileset(): ...@@ -199,8 +210,7 @@ def test_verify_fileset():
'-e', 'bob.bio.base.test.dummy.extractor.DummyExtractor()', '-e', 'bob.bio.base.test.dummy.extractor.DummyExtractor()',
'-a', 'dummy', '-a', 'dummy',
'--zt-norm', '--zt-norm',
'-vvv', '-vs', 'test_fileset',
'-s', 'test_fileset',
'--temp-directory', test_dir, '--temp-directory', test_dir,
'--result-directory', test_dir '--result-directory', test_dir
] ]
...@@ -224,8 +234,7 @@ def test_verify_filelist(): ...@@ -224,8 +234,7 @@ def test_verify_filelist():
'-e', 'dummy', '-e', 'dummy',
'-a', 'dummy', '-a', 'dummy',
'--zt-norm', '--zt-norm',
'-vvv', '-vs', 'test_filelist',
'-s', 'test_filelist',
'--temp-directory', test_dir, '--temp-directory', test_dir,
'--result-directory', test_dir '--result-directory', test_dir
] ]
...@@ -275,7 +284,7 @@ def test_evaluate(): ...@@ -275,7 +284,7 @@ def test_evaluate():
'--roc', plots[0], '--roc', plots[0],
'--det', plots[1], '--det', plots[1],
'--cmc', plots[2], '--cmc', plots[2],
'-vvv', '-v',
] ]
# execute the script # execute the script
...@@ -312,10 +321,12 @@ def test_grid_search(): ...@@ -312,10 +321,12 @@ def test_grid_search():
'-s', 'test_grid_search', '-s', 'test_grid_search',
'-T', test_dir, '-T', test_dir,
'-R', test_dir, '-R', test_dir,
'-v',
'--', '--dry-run', '--', '--dry-run',
] ]
from bob.bio.base.script.grid_search import main from bob.bio.base.script.grid_search import main
main(parameters) with Quiet():
main(parameters)
# number of jobs should be 12 # number of jobs should be 12
assert bob.bio.base.script.grid_search.task_count == 6 assert bob.bio.base.script.grid_search.task_count == 6
...@@ -333,9 +344,11 @@ def test_grid_search(): ...@@ -333,9 +344,11 @@ def test_grid_search():
'-R', test_dir, '-R', test_dir,
'-w', 'Job.txt', '-w', 'Job.txt',
'-g', 'grid', '-g', 'grid',
'-v',
'--', '--dry-run', '--', '--dry-run',
] ]
main(parameters) with Quiet():
main(parameters)
# number of jobs should be 12 # number of jobs should be 12
assert bob.bio.base.script.grid_search.task_count == 6 assert bob.bio.base.script.grid_search.task_count == 6
...@@ -351,11 +364,12 @@ def test_grid_search(): ...@@ -351,11 +364,12 @@ def test_grid_search():
'-T', test_dir, '-T', test_dir,
'-R', test_dir, '-R', test_dir,
'-w', 'Job.txt', '-w', 'Job.txt',
'-l', '4', '-L', '-1', '-vvv', '-l', '4', '-L', '-1', '-v',
'--', '--imports', 'bob.io.image', '--', '--imports', 'bob.io.image',
'--dry-run' '--dry-run',
] ]
main(parameters) with Quiet():
main(parameters)
# number of jobs should be 12 # number of jobs should be 12
assert bob.bio.base.script.grid_search.task_count == 6 assert bob.bio.base.script.grid_search.task_count == 6
...@@ -408,7 +422,7 @@ def test_scripts(): ...@@ -408,7 +422,7 @@ def test_scripts():
'-p', 'dummy', '-p', 'dummy',
'-o', preprocessed_file, '-o', preprocessed_file,
'-c', preprocessed_image, '-c', preprocessed_image,
'-vvv', '-v',
] ]
preprocess(parameters) preprocess(parameters)
...@@ -424,7 +438,7 @@ def test_scripts(): ...@@ -424,7 +438,7 @@ def test_scripts():
'-e', 'dummy', '-e', 'dummy',
'-E', extractor_file, '-E', extractor_file,
'-o', extracted_file, '-o', extracted_file,
'-vvv', '-v',
] ]
extract(parameters) extract(parameters)
...@@ -439,7 +453,7 @@ def test_scripts(): ...@@ -439,7 +453,7 @@ def test_scripts():
'-P', projector_file, '-P', projector_file,
'-E', enroller_file, '-E', enroller_file,
'-o', model_file, '-o', model_file,
'-vvv', '-v',
] ]
enroll(parameters) enroll(parameters)
...@@ -453,9 +467,10 @@ def test_scripts(): ...@@ -453,9 +467,10 @@ def test_scripts():
'-a', 'dummy', '-a', 'dummy',
'-P', projector_file, '-P', projector_file,
'-E', enroller_file, '-E', enroller_file,
'-vvv', '-v',
] ]
score(parameters) with Quiet():
score(parameters)
finally: finally:
shutil.rmtree(test_dir) shutil.rmtree(test_dir)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment