diff options
| author | Chris McDonough <chrism@plope.com> | 2012-03-12 12:42:39 -0700 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2012-03-12 12:42:39 -0700 |
| commit | 352f6adf5e55b1c2f4a0332056a6ef31984b2d30 (patch) | |
| tree | e9b1c14123ab83415d16ae2818e238e5ce5225a3 | |
| parent | 3b4deef1f6a7825c7c3eb904af15f4d626793b5f (diff) | |
| parent | 31178753df47eacb0b9154c65aac03c1b311ce0f (diff) | |
| download | pyramid-352f6adf5e55b1c2f4a0332056a6ef31984b2d30.tar.gz pyramid-352f6adf5e55b1c2f4a0332056a6ef31984b2d30.tar.bz2 pyramid-352f6adf5e55b1c2f4a0332056a6ef31984b2d30.zip | |
Merge branch 'master' of github.com:Pylons/pyramid
| -rw-r--r-- | pyramid/tests/test_config/test_init.py | 58 | ||||
| -rw-r--r-- | pyramid/tests/test_config/test_rendering.py | 37 | ||||
| -rw-r--r-- | pyramid/tests/test_config/test_settings.py | 32 |
3 files changed, 55 insertions, 72 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 diff --git a/pyramid/tests/test_config/test_settings.py b/pyramid/tests/test_config/test_settings.py index 8a385b8ab..0f5239915 100644 --- a/pyramid/tests/test_config/test_settings.py +++ b/pyramid/tests/test_config/test_settings.py @@ -48,20 +48,6 @@ class TestSettingsConfiguratorMixin(unittest.TestCase): self.assertEqual(settings['a'], 1) class TestSettings(unittest.TestCase): - def setUp(self): - self.warnings = [] - import warnings - warnings.old_showwarning = warnings.showwarning - warnings.showwarning = self._showwarning - - def tearDown(self): - del self.warnings - import warnings - warnings.showwarning = warnings.old_showwarning - - def _showwarning(self, message, category, filename, lineno, file=None, - line=None): - self.warnings.append(message) def _getTargetClass(self): from pyramid.config.settings import Settings @@ -74,14 +60,20 @@ class TestSettings(unittest.TestCase): return klass(d, _environ_=environ) def test_getattr_success(self): - settings = self._makeOne({'reload_templates':False}) - self.assertEqual(settings.reload_templates, False) - self.assertEqual(len(self.warnings), 1) + import warnings + with warnings.catch_warnings(record=True) as w: + warnings.filterwarnings('always') + settings = self._makeOne({'reload_templates':False}) + self.assertEqual(settings.reload_templates, False) + self.assertEqual(len(w), 1) def test_getattr_fail(self): - settings = self._makeOne({}) - self.assertRaises(AttributeError, settings.__getattr__, 'wontexist') - self.assertEqual(len(self.warnings), 0) + import warnings + with warnings.catch_warnings(record=True) as w: + warnings.filterwarnings('always') + settings = self._makeOne({}) + self.assertRaises(AttributeError, settings.__getattr__, 'wontexist') + self.assertEqual(len(w), 0) def test_getattr_raises_attribute_error(self): settings = self._makeOne() |
