本文整理汇总了Python中warnings.simplefilter函数的典型用法代码示例。如果您正苦于以下问题:Python simplefilter函数的具体用法?Python simplefilter怎么用?Python simplefilter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了simplefilter函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_parseable_output_deprecated
def test_parseable_output_deprecated(self):
with warnings.catch_warnings(record=True) as cm:
warnings.simplefilter("always")
ParseableTextReporter()
self.assertEqual(len(cm), 1)
self.assertIsInstance(cm[0].message, DeprecationWarning)
开发者ID:Wooble,项目名称:pylint,代码行数:7,代码来源:unittest_reporting.py
示例2: test_idlever
def test_idlever(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
import idlelib.idlever
self.assertEqual(len(w), 1)
self.assertTrue(issubclass(w[-1].category, DeprecationWarning))
self.assertIn("version", str(w[-1].message))
开发者ID:AtomicConductor,项目名称:conductor_client,代码行数:7,代码来源:test_warning.py
示例3: test_op
def test_op(self):
# motor.Op is deprecated in Motor 0.2, superseded by Tornado 3 Futures.
# Just make sure it still works.
collection = self.cx.pymongo_test.test_collection
doc = {'_id': 'jesse'}
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
# Op works.
_id = yield motor.Op(collection.insert, doc)
self.assertEqual('jesse', _id)
# Raised a DeprecationWarning.
self.assertEqual(1, len(w))
warning = w[-1]
self.assertTrue(issubclass(warning.category, DeprecationWarning))
message = str(warning.message)
self.assertTrue("deprecated" in message)
self.assertTrue("insert" in message)
result = yield motor.Op(collection.find_one, doc)
self.assertEqual(doc, result)
# Make sure it works with no args.
result = yield motor.Op(collection.find_one)
self.assertTrue(isinstance(result, dict))
with assert_raises(pymongo.errors.DuplicateKeyError):
yield motor.Op(collection.insert, doc)
开发者ID:MeirKriheli,项目名称:motor,代码行数:31,代码来源:test_motor_gen.py
示例4: _lasso_stability_path
def _lasso_stability_path(X, y, mask, weights, eps):
"Inner loop of lasso_stability_path"
X = X * weights[np.newaxis, :]
X = X[safe_mask(X, mask), :]
y = y[mask]
alpha_max = np.max(np.abs(np.dot(X.T, y))) / X.shape[0]
alpha_min = eps * alpha_max # set for early stopping in path
with warnings.catch_warnings():
warnings.simplefilter('ignore', ConvergenceWarning)
alphas, _, coefs = lars_path(X, y, method='lasso', verbose=False,
alpha_min=alpha_min)
# Scale alpha by alpha_max
alphas /= alphas[0]
# Sort alphas in assending order
alphas = alphas[::-1]
coefs = coefs[:, ::-1]
# Get rid of the alphas that are too small
mask = alphas >= eps
# We also want to keep the first one: it should be close to the OLS
# solution
mask[0] = True
alphas = alphas[mask]
coefs = coefs[:, mask]
return alphas, coefs
开发者ID:AlexanderFabisch,项目名称:scikit-learn,代码行数:25,代码来源:randomized_l1.py
示例5: __unit_test_onset_function
def __unit_test_onset_function(metric):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
# First, test for a warning on empty onsets
metric(np.array([]), np.arange(10))
assert len(w) == 1
assert issubclass(w[-1].category, UserWarning)
assert str(w[-1].message) == "Reference onsets are empty."
metric(np.arange(10), np.array([]))
assert len(w) == 2
assert issubclass(w[-1].category, UserWarning)
assert str(w[-1].message) == "Estimated onsets are empty."
# And that the metric is 0
assert np.allclose(metric(np.array([]), np.array([])), 0)
# Now test validation function - onsets must be 1d ndarray
onsets = np.array([[1., 2.]])
nose.tools.assert_raises(ValueError, metric, onsets, onsets)
# onsets must be in seconds (so not huge)
onsets = np.array([1e10, 1e11])
nose.tools.assert_raises(ValueError, metric, onsets, onsets)
# onsets must be sorted
onsets = np.array([2., 1.])
nose.tools.assert_raises(ValueError, metric, onsets, onsets)
# Valid onsets which are the same produce a score of 1 for all metrics
onsets = np.arange(10, dtype=np.float)
assert np.allclose(metric(onsets, onsets), 1)
开发者ID:justinsalamon,项目名称:mir_eval,代码行数:28,代码来源:test_onset.py
示例6: test_get_default_base_name_deprecation
def test_get_default_base_name_deprecation(self):
msg = "`CustomRouter.get_default_base_name` method should be renamed `get_default_basename`."
# Class definition should raise a warning
with pytest.warns(RemovedInDRF311Warning) as w:
warnings.simplefilter('always')
class CustomRouter(SimpleRouter):
def get_default_base_name(self, viewset):
return 'foo'
assert len(w) == 1
assert str(w[0].message) == msg
# Deprecated method implementation should still be called
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
router = CustomRouter()
router.register('mock', MockViewSet)
assert len(w) == 0
assert router.registry == [
('mock', MockViewSet, 'foo'),
]
开发者ID:seawolf42,项目名称:django-rest-framework,代码行数:25,代码来源:test_routers.py
示例7: test_usgs_eventype
def test_usgs_eventype(self):
filename = os.path.join(self.path, 'usgs_event.xml')
with warnings.catch_warnings(record=True):
warnings.simplefilter("ignore")
catalog = _read_quakeml(filename)
self.assertEqual(len(catalog), 1)
self.assertEqual(catalog[0].event_type, 'quarry blast')
开发者ID:Brtle,项目名称:obspy,代码行数:7,代码来源:test_quakeml.py
示例8: test_decorator_attrs
def test_decorator_attrs(self):
def fxn(module): pass
with warnings.catch_warnings():
warnings.simplefilter('ignore', DeprecationWarning)
wrapped = self.util.set_package(fxn)
self.assertEqual(wrapped.__name__, fxn.__name__)
self.assertEqual(wrapped.__qualname__, fxn.__qualname__)
开发者ID:10sr,项目名称:cpython,代码行数:7,代码来源:test_util.py
示例9: test_attribute_is_None
def test_attribute_is_None(self):
loader = self.DummyLoader()
loader.module = types.ModuleType('blah')
loader.module.__loader__ = None
with warnings.catch_warnings():
warnings.simplefilter('ignore', DeprecationWarning)
self.assertEqual(loader, loader.load_module('blah').__loader__)
开发者ID:10sr,项目名称:cpython,代码行数:7,代码来源:test_util.py
示例10: setUp
def setUp(self):
super(converterTestsCDF, self).setUp()
self.SDobj = dm.SpaceData(attrs={'global': 'test'})
self.SDobj['var'] = dm.dmarray([1, 2, 3], attrs={'a': 'a'})
self.testdir = tempfile.mkdtemp()
self.testfile = os.path.join(self.testdir, 'test.cdf')
warnings.simplefilter('error', dm.DMWarning)
开发者ID:dpshelio,项目名称:spacepy,代码行数:7,代码来源:test_datamodel.py
示例11: tearDown
def tearDown(self):
super(converterTestsCDF, self).tearDown()
del self.SDobj
if os.path.exists(self.testfile):
os.remove(self.testfile)
os.rmdir(self.testdir)
warnings.simplefilter('default', dm.DMWarning)
开发者ID:dpshelio,项目名称:spacepy,代码行数:7,代码来源:test_datamodel.py
示例12: properties
def properties(self):
"""
return a dictionary mapping property name -> value
"""
o = self.oorig
getters = [name for name in dir(o)
if name.startswith('get_')
and six.callable(getattr(o, name))]
getters.sort()
d = dict()
for name in getters:
func = getattr(o, name)
if self.is_alias(func):
continue
try:
with warnings.catch_warnings():
warnings.simplefilter('ignore')
val = func()
except:
continue
else:
d[name[4:]] = val
return d
开发者ID:JenniferWenHsu,项目名称:matplotlib,代码行数:25,代码来源:artist.py
示例13: _evaluate_projection
def _evaluate_projection(self, x, y):
"""
kNNEvaluate - evaluate class separation in the given projection using a k-NN method
Parameters
----------
x - variables to evaluate
y - class
Returns
-------
scores
"""
if self.percent_data_used != 100:
rand = np.random.choice(len(x), int(len(x) * self.percent_data_used / 100),
replace=False)
x = x[rand]
y = y[rand]
neigh = KNeighborsClassifier(n_neighbors=3) if self.attr_color.is_discrete else \
KNeighborsRegressor(n_neighbors=3)
assert ~(np.isnan(x).any(axis=None) | np.isnan(x).any(axis=None))
neigh.fit(x, y)
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=UserWarning)
scores = cross_val_score(neigh, x, y, cv=3)
return scores.mean()
开发者ID:astaric,项目名称:orange3,代码行数:25,代码来源:owradviz.py
示例14: test_ica_rank_reduction
def test_ica_rank_reduction():
"""Test recovery of full data when no source is rejected"""
# Most basic recovery
raw = Raw(raw_fname).crop(0.5, stop, False)
raw.load_data()
picks = pick_types(raw.info, meg=True, stim=False, ecg=False,
eog=False, exclude='bads')[:10]
n_components = 5
max_pca_components = len(picks)
for n_pca_components in [6, 10]:
with warnings.catch_warnings(record=True): # non-convergence
warnings.simplefilter('always')
ica = ICA(n_components=n_components,
max_pca_components=max_pca_components,
n_pca_components=n_pca_components,
method='fastica', max_iter=1).fit(raw, picks=picks)
rank_before = raw.estimate_rank(picks=picks)
assert_equal(rank_before, len(picks))
raw_clean = ica.apply(raw, copy=True)
rank_after = raw_clean.estimate_rank(picks=picks)
# interaction between ICA rejection and PCA components difficult
# to preduct. Rank_after often seems to be 1 higher then
# n_pca_components
assert_true(n_components < n_pca_components <= rank_after <=
rank_before)
开发者ID:mdclarke,项目名称:mne-python,代码行数:26,代码来源:test_ica.py
示例15: test_unicode_decode_error
def test_unicode_decode_error():
# decode_error default to strict, so this should fail
# First, encode (as bytes) a unicode string.
text = "J'ai mang\xe9 du kangourou ce midi, c'\xe9tait pas tr\xeas bon."
text_bytes = text.encode('utf-8')
# Then let the Analyzer try to decode it as ascii. It should fail,
# because we have given it an incorrect encoding.
wa = CountVectorizer(ngram_range=(1, 2), encoding='ascii').build_analyzer()
assert_raises(UnicodeDecodeError, wa, text_bytes)
ca = CountVectorizer(analyzer='char', ngram_range=(3, 6),
encoding='ascii').build_analyzer()
assert_raises(UnicodeDecodeError, ca, text_bytes)
# Check the old interface
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
ca = CountVectorizer(analyzer='char', ngram_range=(3, 6),
charset='ascii').build_analyzer()
assert_raises(UnicodeDecodeError, ca, text_bytes)
assert_equal(len(w), 1)
assert_true(issubclass(w[0].category, DeprecationWarning))
assert_true("charset" in str(w[0].message).lower())
开发者ID:BloodD,项目名称:scikit-learn,代码行数:26,代码来源:test_text.py
示例16: test_not_reset
def test_not_reset(self):
loader = self.DummyLoader()
loader.module = types.ModuleType('blah')
loader.module.__loader__ = 42
with warnings.catch_warnings():
warnings.simplefilter('ignore', DeprecationWarning)
self.assertEqual(42, loader.load_module('blah').__loader__)
开发者ID:10sr,项目名称:cpython,代码行数:7,代码来源:test_util.py
示例17: test_warningsConfiguredAsErrors
def test_warningsConfiguredAsErrors(self):
"""
If a warnings filter has been installed which turns warnings into
exceptions, tests have an error added to the reporter for them for each
unflushed warning.
"""
class CustomWarning(Warning):
pass
result = TestResult()
case = Mask.MockTests('test_unflushed')
case.category = CustomWarning
originalWarnings = warnings.filters[:]
try:
warnings.simplefilter('error')
case.run(result)
self.assertEqual(len(result.errors), 1)
self.assertIdentical(result.errors[0][0], case)
self.assertTrue(
# Different python versions differ in whether they report the
# fully qualified class name or just the class name.
result.errors[0][1].splitlines()[-1].endswith(
"CustomWarning: some warning text"))
finally:
warnings.filters[:] = originalWarnings
开发者ID:alfonsjose,项目名称:international-orders-app,代码行数:26,代码来源:test_warning.py
示例18: test_PR_424
def test_PR_424():
"""Ensure deprecation and user warnings are triggered."""
import warnings
warnings.simplefilter('always') # Alert us of deprecation warnings.
# Recommended use
ColorClip([1000, 600], color=(60, 60, 60), duration=10).close()
with pytest.warns(DeprecationWarning):
# Uses `col` so should work the same as above, but give warning.
ColorClip([1000, 600], col=(60, 60, 60), duration=10).close()
# Catch all warnings as record.
with pytest.warns(None) as record:
# Should give 2 warnings and use `color`, not `col`
ColorClip([1000, 600], color=(60, 60, 60), duration=10, col=(2,2,2)).close()
message1 = 'The `ColorClip` parameter `col` has been deprecated. ' + \
'Please use `color` instead.'
message2 = 'The arguments `color` and `col` have both been passed to ' + \
'`ColorClip` so `col` has been ignored.'
# Assert that two warnings popped and validate the message text.
assert len(record) == 2
assert str(record[0].message) == message1
assert str(record[1].message) == message2
开发者ID:mgaitan,项目名称:moviepy,代码行数:26,代码来源:test_PR.py
示例19: test_writing_invalid_quakeml_id
def test_writing_invalid_quakeml_id(self):
"""
Some ids might be invalid. We still want to write them to not mess
with any external tools relying on the ids. But we also raise a
warning of course.
"""
filename = os.path.join(self.path, 'invalid_id.xml')
cat = read_events(filename)
self.assertEqual(
cat[0].resource_id.id,
"smi:org.gfz-potsdam.de/geofon/RMHP(60)>>ITAPER(3)>>BW(4,5,15)")
with NamedTemporaryFile() as tf:
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
cat.write(tf.name, format="quakeml")
cat2 = read_events(tf.name)
self.assertEqual(len(w), 19)
self.assertEqual(
w[0].message.args[0],
"'smi:org.gfz-potsdam.de/geofon/RMHP(60)>>ITAPER(3)>>BW(4,5,15)' "
"is not a valid QuakeML URI. It will be in the final file but "
"note that the file will not be a valid QuakeML file.")
self.assertEqual(
cat2[0].resource_id.id,
"smi:org.gfz-potsdam.de/geofon/RMHP(60)>>ITAPER(3)>>BW(4,5,15)")
开发者ID:Brtle,项目名称:obspy,代码行数:25,代码来源:test_quakeml.py
示例20: _validate_regex
def _validate_regex(pattern, flags):
"""Check if the given regex is valid.
This is more complicated than it could be since there's a warning on
invalid escapes with newer Python versions, and we want to catch that case
and treat it as invalid.
"""
with warnings.catch_warnings(record=True) as recorded_warnings:
warnings.simplefilter('always')
try:
re.compile(pattern, flags)
except re.error as e:
raise configexc.ValidationError(
pattern, "must be a valid regex - " + str(e))
except RuntimeError:
raise configexc.ValidationError(
pattern, "must be a valid regex - recursion depth exceeded")
for w in recorded_warnings:
if (issubclass(w.category, DeprecationWarning) and
str(w.message).startswith('bad escape')):
raise configexc.ValidationError(
pattern, "must be a valid regex - " + str(w.message))
else:
warnings.warn(w.message)
开发者ID:torsava,项目名称:qutebrowser,代码行数:25,代码来源:configtypes.py
注:本文中的warnings.simplefilter函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论