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
import bob.measure
import os
import sys
import shutil
import tempfile
import numpy
......@@ -21,24 +20,6 @@ import pkg_resources
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')
data_dir = pkg_resources.resource_filename('bob.bio.base', 'test/data')
......@@ -325,7 +306,7 @@ def test_grid_search():
'--', '--dry-run',
]
from bob.bio.base.script.grid_search import main
with Quiet():
with utils.Quiet():
main(parameters)
# number of jobs should be 12
......@@ -347,7 +328,7 @@ def test_grid_search():
'-v',
'--', '--dry-run',
]
with Quiet():
with utils.Quiet():
main(parameters)
# number of jobs should be 12
......@@ -368,7 +349,7 @@ def test_grid_search():
'--', '--imports', 'bob.io.image',
'--dry-run',
]
with Quiet():
with utils.Quiet():
main(parameters)
# number of jobs should be 12
......@@ -469,7 +450,7 @@ def test_scripts():
'-E', enroller_file,
'-v',
]
with Quiet():
with utils.Quiet():
score(parameters)
finally:
......
......@@ -19,10 +19,30 @@
import numpy
import os
import sys
import functools
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
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