summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2011-04-12 12:29:36 -0400
committerChris McDonough <chrism@plope.com>2011-04-12 12:29:36 -0400
commit70d504d70c0ff06cb0742bdbbfe04f31ea042462 (patch)
tree211130442b7556cac05d4b7716f451c4e3824eee
parent027ad87d7e04ed55c9175b77b4cccce375fdb79c (diff)
downloadpyramid-70d504d70c0ff06cb0742bdbbfe04f31ea042462.tar.gz
pyramid-70d504d70c0ff06cb0742bdbbfe04f31ea042462.tar.bz2
pyramid-70d504d70c0ff06cb0742bdbbfe04f31ea042462.zip
add test for mimetypes initialization import-time side-effect callable
-rw-r--r--pyramid/tests/test_view.py21
-rw-r--r--pyramid/view.py26
2 files changed, 36 insertions, 11 deletions
diff --git a/pyramid/tests/test_view.py b/pyramid/tests/test_view.py
index 5d6028b4f..826fc4290 100644
--- a/pyramid/tests/test_view.py
+++ b/pyramid/tests/test_view.py
@@ -499,6 +499,27 @@ class Test_default_exceptionresponse_view(unittest.TestCase):
result = self._callFUT(context, request)
self.assertEqual(result, 'abc')
+class Test_patch_mimetypes(unittest.TestCase):
+ def _callFUT(self, module):
+ from pyramid.view import init_mimetypes
+ return init_mimetypes(module)
+
+ def test_has_init(self):
+ class DummyMimetypes(object):
+ def init(self):
+ self.initted = True
+ module = DummyMimetypes()
+ result = self._callFUT(module)
+ self.assertEqual(result, True)
+ self.assertEqual(module.initted, True)
+
+ def test_missing_init(self):
+ class DummyMimetypes(object):
+ pass
+ module = DummyMimetypes()
+ result = self._callFUT(module)
+ self.assertEqual(result, False)
+
class ExceptionResponse(Exception):
status = '404 Not Found'
app_iter = ['Not Found']
diff --git a/pyramid/view.py b/pyramid/view.py
index 659a63e1e..b2aaba964 100644
--- a/pyramid/view.py
+++ b/pyramid/view.py
@@ -1,15 +1,4 @@
import mimetypes
-
-# See http://bugs.python.org/issue5853 which is a recursion bug
-# that seems to effect Python 2.6, Python 2.6.1, and 2.6.2 (a fix
-# has been applied on the Python 2 trunk). This workaround should
-# really be in Paste if anywhere, but it's easiest to just do it
-# here and get it over with to avoid needing to deal with any
-# fallout.
-
-if hasattr(mimetypes, 'init'):
- mimetypes.init()
-
import venusian
from zope.interface import providedBy
@@ -24,6 +13,21 @@ from pyramid.renderers import RendererHelper
from pyramid.static import static_view
from pyramid.threadlocal import get_current_registry
+def init_mimetypes(mimetypes):
+ # this is a function so it can be unittested
+ if hasattr(mimetypes, 'init'):
+ mimetypes.init()
+ return True
+ return False
+
+# See http://bugs.python.org/issue5853 which is a recursion bug
+# that seems to effect Python 2.6, Python 2.6.1, and 2.6.2 (a fix
+# has been applied on the Python 2 trunk). This workaround should
+# really be in Paste if anywhere, but it's easiest to just do it
+# here and get it over with to avoid needing to deal with any
+# fallout.
+init_mimetypes(mimetypes)
+
# Nast BW compat hack: dont yet deprecate this (ever?)
class static(static_view): # only subclass for purposes of autodoc
__doc__ = static_view.__doc__