Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of github.com:Pylons/pyramid

  • Loading branch information...
commit 352f6adf5e55b1c2f4a0332056a6ef31984b2d30 2 parents 3b4deef + 3117875
@mcdonc mcdonc authored
View
58 pyramid/tests/test_config/test_init.py
@@ -1,4 +1,5 @@
import unittest
+import warnings
import os
@@ -545,39 +546,33 @@ def test_setup_registry_request_factory_dottedname(self):
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 @@ def foo(config): pass
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
View
37 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 @@ def _makeOne(self, *arg, **kw):
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
View
32 pyramid/tests/test_config/test_settings.py
@@ -48,20 +48,6 @@ def test_add_settings_settings_not_yet_registered(self):
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 @@ def _makeOne(self, d=None, environ=None):
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()
Please sign in to comment.
Something went wrong with that request. Please try again.