本文整理汇总了Python中warnings.resetwarnings方法的典型用法代码示例。如果您正苦于以下问题:Python warnings.resetwarnings方法的具体用法?Python warnings.resetwarnings怎么用?Python warnings.resetwarnings使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类warnings
的用法示例。
在下文中一共展示了warnings.resetwarnings方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ctrb_siso_deprecated
# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import resetwarnings [as 别名]
def test_ctrb_siso_deprecated(self):
A = np.array([[1., 2.], [3., 4.]])
B = np.array([[5.], [7.]])
# Check that default using np.matrix generates a warning
# TODO: remove this check with matrix type is deprecated
warnings.resetwarnings()
with warnings.catch_warnings(record=True) as w:
use_numpy_matrix(True)
self.assertTrue(issubclass(w[-1].category, UserWarning))
Wc = ctrb(A, B)
self.assertTrue(isinstance(Wc, np.matrix))
self.assertTrue(issubclass(w[-1].category,
PendingDeprecationWarning))
use_numpy_matrix(False)
示例2: create_db
# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import resetwarnings [as 别名]
def create_db(instance, db):
""" Create a database if it does not already exist
Args:
instance - a hostAddr object
db - the name of the db to be created
"""
conn = connect_mysql(instance)
cursor = conn.cursor()
sql = ('CREATE DATABASE IF NOT EXISTS `{}`'.format(db))
log.info(sql)
# We don't care if the db already exists and this was a no-op
warnings.filterwarnings('ignore', category=MySQLdb.Warning)
cursor.execute(sql)
warnings.resetwarnings()
示例3: drop_db
# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import resetwarnings [as 别名]
def drop_db(instance, db):
""" Drop a database, if it exists.
Args:
instance - a hostAddr object
db - the name of the db to be dropped
"""
conn = connect_mysql(instance)
cursor = conn.cursor()
sql = ('DROP DATABASE IF EXISTS `{}`'.format(db))
log.info(sql)
# If the DB isn't there, we'd throw a warning, but we don't
# actually care; this will be a no-op.
warnings.filterwarnings('ignore', category=MySQLdb.Warning)
cursor.execute(sql)
warnings.resetwarnings()
示例4: start_event_scheduler
# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import resetwarnings [as 别名]
def start_event_scheduler(instance):
""" Enable the event scheduler on a given MySQL server.
Args:
instance: The hostAddr object to act upon.
"""
cmd = 'SET GLOBAL event_scheduler=ON'
# We don't use the event scheduler in many places, but if we're
# not able to start it when we want to, that could be a big deal.
try:
conn = connect_mysql(instance)
cursor = conn.cursor()
warnings.filterwarnings('ignore', category=MySQLdb.Warning)
log.info(cmd)
cursor.execute(cmd)
except Exception as e:
log.error('Unable to start event scheduler: {}'.format(e))
raise
finally:
warnings.resetwarnings()
示例5: stop_event_scheduler
# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import resetwarnings [as 别名]
def stop_event_scheduler(instance):
""" Disable the event scheduler on a given MySQL server.
Args:
instance: The hostAddr object to act upon.
"""
cmd = 'SET GLOBAL event_scheduler=OFF'
# If for some reason we're unable to disable the event scheduler,
# that isn't likely to be a big deal, so we'll just pass after
# logging the exception.
try:
conn = connect_mysql(instance)
cursor = conn.cursor()
warnings.filterwarnings('ignore', category=MySQLdb.Warning)
log.info(cmd)
cursor.execute(cmd)
except Exception as e:
log.error('Unable to stop event scheduler: {}'.format(e))
pass
finally:
warnings.resetwarnings()
示例6: test_catch_string
# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import resetwarnings [as 别名]
def test_catch_string(self):
# Catching a string should trigger a DeprecationWarning.
with warnings.catch_warnings():
warnings.resetwarnings()
warnings.filterwarnings("error")
str_exc = "spam"
with self.assertRaises(DeprecationWarning):
try:
raise StandardError
except str_exc:
pass
# Make sure that even if the string exception is listed in a tuple
# that a warning is raised.
with self.assertRaises(DeprecationWarning):
try:
raise StandardError
except (AssertionError, str_exc):
pass
示例7: setUp
# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import resetwarnings [as 别名]
def setUp(self):
self.server = self.server_class()
self.server.start()
self.client = self.client_class(timeout=TIMEOUT)
self.client.encoding = 'utf8' # PY3 only
self.client.connect(self.server.host, self.server.port)
self.client.login(USER, PASSWD)
if PY3:
safe_mkdir(bytes(TESTFN_UNICODE, 'utf8'))
touch(bytes(TESTFN_UNICODE_2, 'utf8'))
self.utf8fs = TESTFN_UNICODE in os.listdir('.')
else:
warnings.filterwarnings("ignore")
safe_mkdir(TESTFN_UNICODE)
touch(TESTFN_UNICODE_2)
self.utf8fs = unicode(TESTFN_UNICODE, 'utf8') in os.listdir(u('.'))
warnings.resetwarnings()
示例8: _run_generated_code
# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import resetwarnings [as 别名]
def _run_generated_code(self, code, globs, locs,
fails_under_py3k=True,
):
import warnings
from zope.interface._compat import PYTHON3
with warnings.catch_warnings(record=True) as log:
warnings.resetwarnings()
if not PYTHON3:
exec(code, globs, locs)
self.assertEqual(len(log), 0) # no longer warn
return True
else:
try:
exec(code, globs, locs)
except TypeError:
return False
else:
if fails_under_py3k:
self.fail("Didn't raise TypeError")
示例9: test_called_from_function
# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import resetwarnings [as 别名]
def test_called_from_function(self):
import warnings
from zope.interface.declarations import implements
from zope.interface.interface import InterfaceClass
IFoo = InterfaceClass("IFoo")
globs = {'implements': implements, 'IFoo': IFoo}
locs = {}
CODE = "\n".join([
'def foo():',
' implements(IFoo)'
])
if self._run_generated_code(CODE, globs, locs, False):
foo = locs['foo']
with warnings.catch_warnings(record=True) as log:
warnings.resetwarnings()
self.assertRaises(TypeError, foo)
self.assertEqual(len(log), 0) # no longer warn
示例10: test_called_twice_from_class
# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import resetwarnings [as 别名]
def test_called_twice_from_class(self):
import warnings
from zope.interface.declarations import implements
from zope.interface.interface import InterfaceClass
from zope.interface._compat import PYTHON3
IFoo = InterfaceClass("IFoo")
IBar = InterfaceClass("IBar")
globs = {'implements': implements, 'IFoo': IFoo, 'IBar': IBar}
locs = {}
CODE = "\n".join([
'class Foo(object):',
' implements(IFoo)',
' implements(IBar)',
])
with warnings.catch_warnings(record=True) as log:
warnings.resetwarnings()
try:
exec(CODE, globs, locs)
except TypeError:
if not PYTHON3:
self.assertEqual(len(log), 0) # no longer warn
else:
self.fail("Didn't raise TypeError")
示例11: test_setupterm_singleton_issue33
# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import resetwarnings [as 别名]
def test_setupterm_singleton_issue33():
"A warning is emitted if a new terminal ``kind`` is used per process."
@as_subprocess
def child():
warnings.filterwarnings("error", category=UserWarning)
# instantiate first terminal, of type xterm-256color
term = TestTerminal(force_styling=True)
try:
# a second instantiation raises UserWarning
term = TestTerminal(kind="vt220", force_styling=True)
except UserWarning:
err = sys.exc_info()[1]
assert (err.args[0].startswith(
'A terminal of kind "vt220" has been requested')
), err.args[0]
assert ('a terminal of kind "xterm-256color" will '
'continue to be returned' in err.args[0]), err.args[0]
else:
# unless term is not a tty and setupterm() is not called
assert not term.is_a_tty or False, 'Should have thrown exception'
warnings.resetwarnings()
child()
示例12: test_setupterm_invalid_issue39
# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import resetwarnings [as 别名]
def test_setupterm_invalid_issue39():
"A warning is emitted if TERM is invalid."
# https://bugzilla.mozilla.org/show_bug.cgi?id=878089
#
# if TERM is unset, defaults to 'unknown', which should
# fail to lookup and emit a warning on *some* systems.
# freebsd actually has a termcap entry for 'unknown'
@as_subprocess
def child():
warnings.filterwarnings("error", category=UserWarning)
try:
term = TestTerminal(kind='unknown', force_styling=True)
except UserWarning:
err = sys.exc_info()[1]
assert err.args[0] == (
"Failed to setupterm(kind='unknown'): "
"setupterm: could not find terminal")
else:
if platform.system().lower() != 'freebsd':
assert not term.is_a_tty and not term.does_styling, (
'Should have thrown exception')
warnings.resetwarnings()
child()
示例13: test_setupterm_invalid_has_no_styling
# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import resetwarnings [as 别名]
def test_setupterm_invalid_has_no_styling():
"An unknown TERM type does not perform styling."
# https://bugzilla.mozilla.org/show_bug.cgi?id=878089
# if TERM is unset, defaults to 'unknown', which should
# fail to lookup and emit a warning, only.
@as_subprocess
def child():
warnings.filterwarnings("ignore", category=UserWarning)
term = TestTerminal(kind='xxXunknownXxx', force_styling=True)
assert term.kind is None
assert not term.does_styling
assert term.number_of_colors == 0
warnings.resetwarnings()
child()
示例14: test_amz_date_warning
# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import resetwarnings [as 别名]
def test_amz_date_warning(self):
"""
Will be removed when deprecated amz_date attribute is removed
"""
warnings.resetwarnings()
with warnings.catch_warnings(record=True) as w:
obj = AWS4SigningKey('secret_key', 'region', 'service')
if PY2:
warnings.simplefilter('always')
obj.amz_date
self.assertEqual(len(w), 1)
self.assertEqual(w[-1].category, DeprecationWarning)
else:
warnings.simplefilter('ignore')
self.assertWarns(DeprecationWarning, getattr, obj, 'amz_date')
示例15: test_deprecated
# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import resetwarnings [as 别名]
def test_deprecated():
@jams.core.deprecated('old version', 'new version')
def _foo():
pass
warnings.resetwarnings()
warnings.simplefilter('always')
with warnings.catch_warnings(record=True) as out:
_foo()
# And that the warning triggered
assert len(out) > 0
# And that the category is correct
assert out[0].category is DeprecationWarning
# And that it says the right thing (roughly)
assert 'deprecated' in str(out[0].message).lower()