summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoss Patterson <me@rpatterson.net>2012-03-12 11:17:52 -0700
committerRoss Patterson <me@rpatterson.net>2012-03-12 11:17:52 -0700
commit5e99a22964ea4fa42020c822d44a6e534cb30a38 (patch)
treee9b1c14123ab83415d16ae2818e238e5ce5225a3
parentcf95febe026ae347b365bdcc3dc0ddc19a9cb4e8 (diff)
downloadpyramid-5e99a22964ea4fa42020c822d44a6e534cb30a38.tar.gz
pyramid-5e99a22964ea4fa42020c822d44a6e534cb30a38.tar.bz2
pyramid-5e99a22964ea4fa42020c822d44a6e534cb30a38.zip
Use the warnings.catch_warnings context manager in more places.
Neither 2.7 nor 2.6 with "setup.py test" or "setup.py nosetests" show warnings that don't already appear for origin/master. FYI, under 2.6 with nosetests I see: nose/loader.py:303: DeprecationWarning: registerView
-rw-r--r--pyramid/tests/test_config/test_init.py58
-rw-r--r--pyramid/tests/test_config/test_rendering.py37
2 files changed, 43 insertions, 52 deletions
diff --git a/pyramid/tests/test_config/test_init.py b/pyramid/tests/test_config/test_init.py
index da331e5ee..37c3de275 100644
--- a/pyramid/tests/test_config/test_init.py
+++ b/pyramid/tests/test_config/test_init.py
@@ -1,4 +1,5 @@
import unittest
+import warnings
import os
@@ -545,39 +546,33 @@ class ConfiguratorTests(unittest.TestCase):
self.assertEqual(utility, pyramid.tests.test_config)
def test_setup_registry_renderer_globals_factory(self):
- import warnings
- warnings.filterwarnings('ignore')
- try:
- from pyramid.registry import Registry
- from pyramid.interfaces import IRendererGlobalsFactory
- reg = Registry()
- config = self._makeOne(reg)
- factory = object()
+ from pyramid.registry import Registry
+ from pyramid.interfaces import IRendererGlobalsFactory
+ reg = Registry()
+ config = self._makeOne(reg)
+ factory = object()
+ with warnings.catch_warnings():
+ warnings.filterwarnings('ignore')
config.setup_registry(renderer_globals_factory=factory)
- self.assertEqual(reg.queryUtility(IRendererGlobalsFactory), None)
- config.commit()
- utility = reg.getUtility(IRendererGlobalsFactory)
- self.assertEqual(utility, factory)
- finally:
- warnings.resetwarnings()
+ self.assertEqual(reg.queryUtility(IRendererGlobalsFactory), None)
+ config.commit()
+ utility = reg.getUtility(IRendererGlobalsFactory)
+ self.assertEqual(utility, factory)
def test_setup_registry_renderer_globals_factory_dottedname(self):
- import warnings
- warnings.filterwarnings('ignore')
- try:
- from pyramid.registry import Registry
- from pyramid.interfaces import IRendererGlobalsFactory
- reg = Registry()
- config = self._makeOne(reg)
- import pyramid.tests.test_config
+ from pyramid.registry import Registry
+ from pyramid.interfaces import IRendererGlobalsFactory
+ reg = Registry()
+ config = self._makeOne(reg)
+ import pyramid.tests.test_config
+ with warnings.catch_warnings():
+ warnings.filterwarnings('ignore')
config.setup_registry(
renderer_globals_factory='pyramid.tests.test_config')
- self.assertEqual(reg.queryUtility(IRendererGlobalsFactory), None)
- config.commit()
- utility = reg.getUtility(IRendererGlobalsFactory)
- self.assertEqual(utility, pyramid.tests.test_config)
- finally:
- warnings.resetwarnings()
+ self.assertEqual(reg.queryUtility(IRendererGlobalsFactory), None)
+ config.commit()
+ utility = reg.getUtility(IRendererGlobalsFactory)
+ self.assertEqual(utility, pyramid.tests.test_config)
def test_setup_registry_alternate_renderers(self):
from pyramid.registry import Registry
@@ -1182,13 +1177,14 @@ pyramid.tests.test_config.dummy_include2""",
self.assertTrue(getattr(foo_meth, im_func) is foo)
class TestConfiguratorDeprecatedFeatures(unittest.TestCase):
+
def setUp(self):
- import warnings
+ self.warnings = warnings.catch_warnings()
+ self.warnings.__enter__()
warnings.filterwarnings('ignore')
def tearDown(self):
- import warnings
- warnings.resetwarnings()
+ self.warnings.__exit__(None, None, None)
def _makeOne(self, *arg, **kw):
from pyramid.config import Configurator
diff --git a/pyramid/tests/test_config/test_rendering.py b/pyramid/tests/test_config/test_rendering.py
index 655735511..e6ee9ad70 100644
--- a/pyramid/tests/test_config/test_rendering.py
+++ b/pyramid/tests/test_config/test_rendering.py
@@ -1,4 +1,5 @@
import unittest
+import warnings
from pyramid.tests.test_config import dummyfactory
@@ -9,32 +10,26 @@ class TestRenderingConfiguratorMixin(unittest.TestCase):
return config
def test_set_renderer_globals_factory(self):
- import warnings
- warnings.filterwarnings('ignore')
- try:
- from pyramid.interfaces import IRendererGlobalsFactory
- config = self._makeOne(autocommit=True)
- factory = object()
+ from pyramid.interfaces import IRendererGlobalsFactory
+ config = self._makeOne(autocommit=True)
+ factory = object()
+ with warnings.catch_warnings():
+ warnings.filterwarnings('ignore')
config.set_renderer_globals_factory(factory)
- self.assertEqual(
- config.registry.getUtility(IRendererGlobalsFactory),
- factory)
- finally:
- warnings.resetwarnings()
+ self.assertEqual(
+ config.registry.getUtility(IRendererGlobalsFactory),
+ factory)
def test_set_renderer_globals_factory_dottedname(self):
- import warnings
- warnings.filterwarnings('ignore')
- try:
- from pyramid.interfaces import IRendererGlobalsFactory
- config = self._makeOne(autocommit=True)
+ from pyramid.interfaces import IRendererGlobalsFactory
+ config = self._makeOne(autocommit=True)
+ with warnings.catch_warnings():
+ warnings.filterwarnings('ignore')
config.set_renderer_globals_factory(
'pyramid.tests.test_config.dummyfactory')
- self.assertEqual(
- config.registry.getUtility(IRendererGlobalsFactory),
- dummyfactory)
- finally:
- warnings.resetwarnings()
+ self.assertEqual(
+ config.registry.getUtility(IRendererGlobalsFactory),
+ dummyfactory)
def test_add_renderer(self):
from pyramid.interfaces import IRendererFactory