From 88558bd730814712fae01439d0b9e91f07efca2a Mon Sep 17 00:00:00 2001 From: chaoflow Date: Fri, 9 Jan 2009 09:33:29 +0000 Subject: [PATCH] paula.testing: Mock object should handle non-tuple alsoProvides git-svn-id: https://svn.plone.org/svn/collective/paula/trunk@78627 db7f04ef-aaf3-0310-a811-c281ed44c4ad --- paula.testing/src/paula/testing/testing.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/paula.testing/src/paula/testing/testing.py b/paula.testing/src/paula/testing/testing.py index 201c515..26602ae 100644 --- a/paula.testing/src/paula/testing/testing.py +++ b/paula.testing/src/paula/testing/testing.py @@ -22,6 +22,7 @@ __docformat__ = "plaintext" import os import os.path +import types import unittest from zope.app.testing.functional import ZCMLLayer, FunctionalDocFileSuite @@ -50,9 +51,10 @@ class Mock(object): >>> class IA(Interface): ... pass - >>> class IB(Interface): ... pass + >>> class IC(Interface): + ... pass >>> m = Mock( a = 1, f = lambda : 2, alsoProvides=(IA,IB)) >>> m.a @@ -61,13 +63,26 @@ class Mock(object): 2 >>> IA.providedBy(m) True + >>> IB.providedBy(m) + True + >>> m = Mock( a = 1, f = lambda : 2, alsoProvides=IC) + >>> IC.providedBy(m) + True """ implements(Interface) - def __init__(self, **kwargs): - if kwargs.has_key('alsoProvides'): - alsoProvides(self, *kwargs['alsoProvides']) - del kwargs['alsoProvides'] - for k,v in kwargs.items(): + def __init__(self, **kws): + try: + alsoProvides = kws['alsoProvides'] + except KeyError: + pass + else: + if type alsoProvides is types.TupleType: + alsoProvides(self, *alsoProvides) + else: + alsoProvides(self, alsoProvides) + del kws['alsoProvides'] + + for k,v in kws.items(): setattr(self, k, v) test_globs = dict( -- 2.11.4.GIT