Commit 49b9e491 authored by Manuel Günther's avatar Manuel Günther
Browse files

Moved the Quiet class into test.utils

parent 557cfdb4
...@@ -5,7 +5,6 @@ from __future__ import print_function ...@@ -5,7 +5,6 @@ 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
...@@ -21,24 +20,6 @@ import pkg_resources ...@@ -21,24 +20,6 @@ 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')
data_dir = pkg_resources.resource_filename('bob.bio.base', 'test/data') data_dir = pkg_resources.resource_filename('bob.bio.base', 'test/data')
...@@ -325,7 +306,7 @@ def test_grid_search(): ...@@ -325,7 +306,7 @@ def test_grid_search():
'--', '--dry-run', '--', '--dry-run',
] ]
from bob.bio.base.script.grid_search import main from bob.bio.base.script.grid_search import main
with Quiet(): with utils.Quiet():
main(parameters) main(parameters)
# number of jobs should be 12 # number of jobs should be 12
...@@ -347,7 +328,7 @@ def test_grid_search(): ...@@ -347,7 +328,7 @@ def test_grid_search():
'-v', '-v',
'--', '--dry-run', '--', '--dry-run',
] ]
with Quiet(): with utils.Quiet():
main(parameters) main(parameters)
# number of jobs should be 12 # number of jobs should be 12
...@@ -368,7 +349,7 @@ def test_grid_search(): ...@@ -368,7 +349,7 @@ def test_grid_search():
'--', '--imports', 'bob.io.image', '--', '--imports', 'bob.io.image',
'--dry-run', '--dry-run',
] ]
with Quiet(): with utils.Quiet():
main(parameters) main(parameters)
# number of jobs should be 12 # number of jobs should be 12
...@@ -469,7 +450,7 @@ def test_scripts(): ...@@ -469,7 +450,7 @@ def test_scripts():
'-E', enroller_file, '-E', enroller_file,
'-v', '-v',
] ]
with Quiet(): with utils.Quiet():
score(parameters) score(parameters)
finally: finally:
......
...@@ -19,10 +19,30 @@ ...@@ -19,10 +19,30 @@
import numpy import numpy
import os import os
import sys
import functools import functools
from nose.plugins.skip import SkipTest from nose.plugins.skip import SkipTest
# based on: http://stackoverflow.com/questions/6796492/temporarily-redirect-stdout-stderr
class Quiet(object):
"""A class that supports the ``with`` statement to redirect any output of wrapped function calls to /dev/null"""
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
import logging import logging
logger = logging.getLogger("bob.bio.base") logger = logging.getLogger("bob.bio.base")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment