def tearDown(self):
"""Removes the patch."""
set_threshold(self.old_threshold)
super(PyPIRCCommandTestCase, self).tearDown()
python类set_threshold()的实例源码
def setUp(self):
super(CoreTestCase, self).setUp()
self.old_stdout = sys.stdout
self.cleanup_testfn()
self.old_argv = sys.argv, sys.argv[:]
self.addCleanup(log.set_threshold, log._global_log.threshold)
def setUp(self):
super().setUp()
self.threshold = log.set_threshold(log.FATAL)
# catching warnings
# when log will be replaced by logging
# we won't need such monkey-patch anymore
self._old_log = log.Log._log
log.Log._log = self._log
self.logs = []
def tearDown(self):
log.set_threshold(self.threshold)
log.Log._log = self._old_log
super().tearDown()
def test_show_help(self):
# smoke test, just makes sure some help is displayed
self.addCleanup(log.set_threshold, log._global_log.threshold)
dist = Distribution()
sys.argv = []
dist.help = 1
dist.script_name = 'setup.py'
with captured_stdout() as s:
dist.parse_command_line()
output = [line for line in s.getvalue().split('\n')
if line.strip() != '']
self.assertTrue(output)
def setUp(self):
super(LoggingSilencer, self).setUp()
self.threshold = log.set_threshold(log.FATAL)
# catching warnings
# when log will be replaced by logging
# we won't need such monkey-patch anymore
self._old_log = log.Log._log
log.Log._log = self._log
self.logs = []
def tearDown(self):
log.set_threshold(self.threshold)
log.Log._log = self._old_log
super(LoggingSilencer, self).tearDown()
def tearDown(self):
"""Removes the patch."""
set_threshold(self.old_threshold)
super(PyPIRCCommandTestCase, self).tearDown()
def show_all(argv=None):
import inspect
if argv is None:
argv = sys.argv
opts, args = parseCmdLine(argv)
if opts.verbose:
log.set_threshold(log.DEBUG)
else:
log.set_threshold(log.INFO)
show_only = []
for n in args:
if n[-5:] != '_info':
n = n + '_info'
show_only.append(n)
show_all = not show_only
_gdict_ = globals().copy()
for name, c in _gdict_.items():
if not inspect.isclass(c):
continue
if not issubclass(c, system_info) or c is system_info:
continue
if not show_all:
if name not in show_only:
continue
del show_only[show_only.index(name)]
conf = c()
conf.verbosity = 2
r = conf.get_info()
if show_only:
log.info('Info classes not defined: %s', ','.join(show_only))
def setup_method(self, method):
super(TestFileListTest, self).setup_method(method)
self.threshold = log.set_threshold(log.FATAL)
self._old_log = log.Log._log
log.Log._log = self._log
self.logs = []
def teardown_method(self, method):
log.set_threshold(self.threshold)
log.Log._log = self._old_log
super(TestFileListTest, self).teardown_method(method)
def show_all(argv=None):
import inspect
if argv is None:
argv = sys.argv
opts, args = parseCmdLine(argv)
if opts.verbose:
log.set_threshold(log.DEBUG)
else:
log.set_threshold(log.INFO)
show_only = []
for n in args:
if n[-5:] != '_info':
n = n + '_info'
show_only.append(n)
show_all = not show_only
_gdict_ = globals().copy()
for name, c in _gdict_.items():
if not inspect.isclass(c):
continue
if not issubclass(c, system_info) or c is system_info:
continue
if not show_all:
if name not in show_only:
continue
del show_only[show_only.index(name)]
conf = c()
conf.verbosity = 2
r = conf.get_info()
if show_only:
log.info('Info classes not defined: %s', ','.join(show_only))
def setUp(self):
super().setUp()
self.threshold = log.set_threshold(log.FATAL)
# catching warnings
# when log will be replaced by logging
# we won't need such monkey-patch anymore
self._old_log = log.Log._log
log.Log._log = self._log
self.logs = []
def tearDown(self):
log.set_threshold(self.threshold)
log.Log._log = self._old_log
super().tearDown()
def tearDown(self):
"""Removes the patch."""
set_threshold(self.old_threshold)
super(PyPIRCCommandTestCase, self).tearDown()
def setup_method(self, method):
super(TestFileListTest, self).setup_method(method)
self.threshold = log.set_threshold(log.FATAL)
self._old_log = log.Log._log
log.Log._log = self._log
self.logs = []
def teardown_method(self, method):
log.set_threshold(self.threshold)
log.Log._log = self._old_log
super(TestFileListTest, self).teardown_method(method)
def show_all(argv=None):
import inspect
if argv is None:
argv = sys.argv
opts, args = parseCmdLine(argv)
if opts.verbose:
log.set_threshold(log.DEBUG)
else:
log.set_threshold(log.INFO)
show_only = []
for n in args:
if n[-5:] != '_info':
n = n + '_info'
show_only.append(n)
show_all = not show_only
_gdict_ = globals().copy()
for name, c in _gdict_.items():
if not inspect.isclass(c):
continue
if not issubclass(c, system_info) or c is system_info:
continue
if not show_all:
if name not in show_only:
continue
del show_only[show_only.index(name)]
conf = c()
conf.verbosity = 2
r = conf.get_info()
if show_only:
log.info('Info classes not defined: %s', ','.join(show_only))