Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix 2 test failures under py26 dealing with differences in zcml and a…

…ction handling
  • Loading branch information...
commit 892eac4c2e775466ea2eb648afc742501825696b 1 parent eb73710
@mcdonc mcdonc authored
View
2  .gitignore
@@ -1,4 +1,4 @@
-env26/
+env*/
*.egg
*.egg-info
*.pyc
View
52 pyramid_handlers/tests.py
@@ -1,6 +1,7 @@
import sys
import unittest
from pyramid import testing
+from pyramid.config import Configurator
PY3 = sys.version_info[0] == 3
@@ -415,7 +416,11 @@ def _conflictFunctions(self, e):
conflicts = e._conflicts.values()
for conflict in conflicts:
for confinst in conflict:
- yield confinst[2]
+ try:
+ # pyramid 1.2
+ yield confinst[2]
+ except TypeError:
+ yield confinst.function
class TestActionPredicate(unittest.TestCase):
def _getTargetClass(self):
@@ -563,21 +568,36 @@ def action1(self):
def action2(self):
return 'response 2'
-def extract_actions(native):
+try:
+ from pyramid.config import expand_action
+ dict_actions = True
+except ImportError:
from zope.configuration.config import expand_action
- L = []
- for action in native:
- (discriminator, callable, args, kw, includepath, info, order
- ) = expand_action(*action)
- d = {}
- d['discriminator'] = discriminator
- d['callable'] = callable
- d['args'] = args
- d['kw'] = kw
- d['order'] = order
- L.append(d)
- return L
-
+ dict_actions = False
+
+if dict_actions:
+ # pyramid 1.Xsomeversion uses dictionary-based actions; the imprecision
+ # of which is because i'm at a sprint and figuring out exactly which
+ # version is less important than keeping things moving, sorry.
+ def extract_actions(native):
+ return native
+
+else:
+ # some other version of pyramid uses tuple-based actions
+ def extract_actions(native): # pragma: no cover
+ L = []
+ for action in native:
+ (discriminator, callable, args, kw, includepath, info, order
+ ) = expand_action(*action)
+ d = {}
+ d['discriminator'] = discriminator
+ d['callable'] = callable
+ d['args'] = args
+ d['kw'] = kw
+ d['order'] = order
+ L.append(d)
+ return L
+
def _execute_actions(actions):
for action in sorted(actions, key=lambda x: x['order']):
if 'callable' in action:
@@ -585,6 +605,8 @@ def _execute_actions(actions):
action['callable']()
class DummyZCMLContext(object):
+ config_class = Configurator
+ introspection = False
def __init__(self, config):
if hasattr(config, '_make_context'): # pragma: no cover
# 1.0, 1.1 b/c
View
5 pyramid_handlers/zcml.py
@@ -1,12 +1,11 @@
from pyramid_zcml import IRouteLikeDirective
+from pyramid_zcml import with_context
from zope.schema import TextLine
from zope.configuration.fields import GlobalObject
from pyramid.exceptions import ConfigurationError
-from pyramid.config import Configurator
-
from pyramid_handlers import add_handler
class IHandlerDirective(IRouteLikeDirective):
@@ -54,7 +53,7 @@ def handler(_context,
if pattern is None:
raise ConfigurationError('handler directive must include a "pattern"')
- config = Configurator.with_context(_context)
+ config = with_context(_context)
if not hasattr(config, 'add_handler'):
config.add_directive('add_handler', add_handler)
View
7 setup.py
@@ -30,11 +30,14 @@
]
PY3 = sys.version_info[0] == 3
+
+# pyramid_zcml 0.9.2 required for with_context function
+
if platform.system() == 'Java':
- tests_require = install_requires + ['pyramid_zcml']
+ tests_require = install_requires + ['pyramid_zcml>=0.9.2']
else:
if not PY3:
- tests_require= install_requires + ['pyramid_zcml', 'Sphinx', 'docutils',]
+ tests_require= install_requires + ['pyramid_zcml>=0.9.2', 'Sphinx', 'docutils',]
else:
tests_require= install_requires + ['Sphinx', 'docutils',]
Please sign in to comment.
Something went wrong with that request. Please try again.