[Checkins] SVN: z3c.componentdebug/trunk/src/z3c/componentdebug/
Use repr instead of str for things like requests
Ross Patterson
me at rpatterson.net
Thu May 31 02:23:24 EDT 2007
Log message for revision 76042:
Use repr instead of str for things like requests
Changed:
U z3c.componentdebug/trunk/src/z3c/componentdebug/README.txt
U z3c.componentdebug/trunk/src/z3c/componentdebug/lookup/__init__.py
A z3c.componentdebug/trunk/src/z3c/componentdebug/tests/lookup.txt
U z3c.componentdebug/trunk/src/z3c/componentdebug/tests/site.txt
U z3c.componentdebug/trunk/src/z3c/componentdebug/tests/tests.py
-=-
Modified: z3c.componentdebug/trunk/src/z3c/componentdebug/README.txt
===================================================================
--- z3c.componentdebug/trunk/src/z3c/componentdebug/README.txt 2007-05-31 05:38:26 UTC (rev 76041)
+++ z3c.componentdebug/trunk/src/z3c/componentdebug/README.txt 2007-05-31 06:23:23 UTC (rev 76042)
@@ -1,5 +1,5 @@
;-*-Doctest-*-
-===================
+p===================
Component Debugging
===================
@@ -115,8 +115,8 @@
lookup API that provide more verbose reporting from
ComponentLookupError exceptions::
- >>> from zope.component import _api
- >>> _api.getMultiAdapter((foo, bar), IBaz)
+ >>> from zope import component
+ >>> component.getMultiAdapter((foo, bar), IBaz)
Traceback (most recent call last):
...
ComponentLookupError: ((<Foo object at ...>, <Bar object at ...>),
@@ -124,13 +124,13 @@
>>> bar2 = Bar()
>>> alsoProvides(bar2, IBar)
- >>> _api.getMultiAdapter((foo, bar2), IBaz)
+ >>> component.getMultiAdapter((foo, bar2), IBaz)
'baz'
>>> from z3c.componentdebug.lookup.patch import patch
>>> patch()
- >>> _api.getMultiAdapter((foo, bar), IBaz)
+ >>> component.getMultiAdapter((foo, bar), IBaz)
Traceback (most recent call last):
...
VerboseComponentLookupError: Lookup failed for...
@@ -146,17 +146,17 @@
- AdapterRegistration(<BaseGlobalComponents base>, [IFoo, IBar], IBaz, '', getBaz, u'')
<Bar object at ...>: no matches
- >>> _api.getMultiAdapter((foo, bar2), IBaz)
+ >>> component.getMultiAdapter((foo, bar2), IBaz)
'baz'
>>> from z3c.componentdebug.lookup.patch import cleanup
>>> cleanup()
- >>> _api.getMultiAdapter((foo, bar), IBaz)
+ >>> component.getMultiAdapter((foo, bar), IBaz)
Traceback (most recent call last):
...
ComponentLookupError: ((<Foo object at ...>, <Bar object at ...>),
<InterfaceClass __builtin__.IBaz>, u'')
- >>> _api.getMultiAdapter((foo, bar2), IBaz)
+ >>> component.getMultiAdapter((foo, bar2), IBaz)
'baz'
Modified: z3c.componentdebug/trunk/src/z3c/componentdebug/lookup/__init__.py
===================================================================
--- z3c.componentdebug/trunk/src/z3c/componentdebug/lookup/__init__.py 2007-05-31 05:38:26 UTC (rev 76041)
+++ z3c.componentdebug/trunk/src/z3c/componentdebug/lookup/__init__.py 2007-05-31 06:23:23 UTC (rev 76042)
@@ -17,31 +17,31 @@
str_ = 'Lookup failed for...\n\n'
if objects is not False:
- str_ += 'objects: %s\n' % ', '.join(str(i) for i in
+ str_ += 'objects: %s\n' % ', '.join(repr(i) for i in
objects)
if provided is not False:
str_ += 'provided: %s\n' % provided
if name is not False:
str_ += 'name: %s\n' % name
if context is not None:
- str_ += 'context: %s\n' % context
+ str_ += 'context: %s\n' % repr(context)
if objects is not False:
str_ += '\nRegistrations with matching objects:\n\n'
for reg, objs in self.registrations.byRegistration():
- str_ += '%s:\n' % reg
+ str_ += '%s:\n' % repr(reg)
for idx in xrange(self.registrations.order):
obj = objs[idx]
str_ += ' - %s%s\n' % (
obj is False and 'unmatched: ' or '',
- objects[idx])
+ repr(objects[idx]))
str_ += '\nObjects with matching registrations:\n\n'
for obj, regs in self.registrations.byObject():
if regs:
str_ += '%s:\n - %s\n' % (
- obj, '\n - '.join(str(i) for i in regs))
+ obj, '\n - '.join(repr(i) for i in regs))
else:
- str_ += '%s: no matches\n' % obj
+ str_ += '%s: no matches\n' % repr(obj)
ComponentLookupError.__init__(self, str_)
Added: z3c.componentdebug/trunk/src/z3c/componentdebug/tests/lookup.txt
===================================================================
--- z3c.componentdebug/trunk/src/z3c/componentdebug/tests/lookup.txt (rev 0)
+++ z3c.componentdebug/trunk/src/z3c/componentdebug/tests/lookup.txt 2007-05-31 06:23:23 UTC (rev 76042)
@@ -0,0 +1,81 @@
+;-*-Doctest-*-
+====================
+ComponentLookupError
+====================
+
+ >>> from zope.interface import Interface
+ >>> from zope.component import getSiteManager
+ >>> from zope.component.persistentregistry import (
+ ... PersistentComponents,)
+ >>> gsm = getSiteManager()
+ >>> sm = PersistentComponents(bases=(gsm,))
+
+ >>> class IFoo(Interface): pass
+ >>> gsm.registerAdapter(lambda x: x, (IFoo,), Interface)
+ >>> sm.registerAdapter(lambda x: x, (IFoo,), Interface)
+
+Check the ComponentLookupError patch for other site managers::
+
+ >>> sm.getAdapter(None, Interface)
+ Traceback (most recent call last):
+ ...
+ ComponentLookupError: (None, <InterfaceClass
+ zope.interface.Interface>, u'')
+
+ >>> from zope.interface import implements
+ >>> class Foo(object):
+ ... implements(IFoo)
+ >>> foo = Foo()
+ >>> sm.getAdapter(foo, Interface)
+ <Foo object at ...>
+
+ >>> from z3c.componentdebug.lookup.patch import patch
+ >>> patch()
+
+ >>> sm.getAdapter(None, Interface)
+ Traceback (most recent call last):
+ ...
+ VerboseComponentLookupError: Lookup failed for...
+ objects: None
+ provided: <InterfaceClass zope.interface.Interface>
+ name:
+ context: <PersistentComponents >
+ Registrations with matching objects:
+ AdapterRegistration(<PersistentComponents >, [IFoo], Interface, u'', <lambda>, u''):
+ - unmatched: None
+ AdapterRegistration(<BaseGlobalComponents base>, [IFoo], Interface, u'', <lambda>, u''):
+ - unmatched: None
+ Objects with matching registrations:
+ None: no matches
+
+Make sure repr is used instead of str with a request::
+
+ >>> from zope import component
+ >>> from zope.publisher.base import TestRequest
+ >>> component.getAdapter(TestRequest('bar'), Interface)
+ Traceback (most recent call last):
+ ...
+ VerboseComponentLookupError: Lookup failed for...
+ objects: <zope.publisher.base.TestRequest object at ...>
+ provided: <InterfaceClass zope.interface.Interface>
+ name:
+ Registrations with matching objects:
+ AdapterRegistration(<BaseGlobalComponents base>, [IFoo], Interface, u'', <lambda>, u''):
+ - unmatched: <zope.publisher.base.TestRequest object at ...>
+ Objects with matching registrations:
+ <zope.publisher.base.TestRequest object at ...>: no matches
+
+ >>> sm.getAdapter(foo, Interface)
+ <Foo object at ...>
+
+ >>> from z3c.componentdebug.lookup.patch import cleanup
+ >>> cleanup()
+
+ >>> sm.getAdapter(None, Interface)
+ Traceback (most recent call last):
+ ...
+ ComponentLookupError: (None, <InterfaceClass
+ zope.interface.Interface>, u'')
+
+ >>> sm.getAdapter(foo, Interface)
+ <Foo object at ...>
Modified: z3c.componentdebug/trunk/src/z3c/componentdebug/tests/site.txt
===================================================================
--- z3c.componentdebug/trunk/src/z3c/componentdebug/tests/site.txt 2007-05-31 05:38:26 UTC (rev 76041)
+++ z3c.componentdebug/trunk/src/z3c/componentdebug/tests/site.txt 2007-05-31 06:23:23 UTC (rev 76042)
@@ -26,58 +26,3 @@
Interface, u'', <lambda>, u''),
AdapterRegistration(<BaseGlobalComponents base>, [Interface],
Interface, u'', <lambda>, u'')]
-
-Check the ComponentLookupError patch for other site managers::
-
- >>> sm.getAdapter(None, Interface)
- Traceback (most recent call last):
- ...
- ComponentLookupError: (None, <InterfaceClass
- zope.interface.Interface>, u'')
-
- >>> from zope.interface import implements
- >>> class Foo(object):
- ... implements(Interface)
- >>> foo = Foo()
- >>> sm.getAdapter(foo, Interface)
- <Foo object at ...>
-
- >>> from z3c.componentdebug.lookup.patch import patch
- >>> patch()
-
- >>> sm.getAdapter(None, Interface)
- Traceback (most recent call last):
- ...
- VerboseComponentLookupError: Lookup failed for...
- objects: None
- provided: <InterfaceClass zope.interface.Interface>
- name:
- context: <PersistentComponents >
- Registrations with matching objects:
- AdapterRegistration(<PersistentComponents >, [Interface],
- Interface, u'', <lambda>, u''):
- - None
- AdapterRegistration(<BaseGlobalComponents base>, [Interface],
- Interface, u'', <lambda>, u''):
- - None
- Objects with matching registrations:
- None:
- - AdapterRegistration(<PersistentComponents >, [Interface],
- Interface, u'', <lambda>, u'')
- - AdapterRegistration(<BaseGlobalComponents base>, [Interface],
- Interface, u'', <lambda>, u'')
-
- >>> sm.getAdapter(foo, Interface)
- <Foo object at ...>
-
- >>> from z3c.componentdebug.lookup.patch import cleanup
- >>> cleanup()
-
- >>> sm.getAdapter(None, Interface)
- Traceback (most recent call last):
- ...
- ComponentLookupError: (None, <InterfaceClass
- zope.interface.Interface>, u'')
-
- >>> sm.getAdapter(foo, Interface)
- <Foo object at ...>
Modified: z3c.componentdebug/trunk/src/z3c/componentdebug/tests/tests.py
===================================================================
--- z3c.componentdebug/trunk/src/z3c/componentdebug/tests/tests.py 2007-05-31 05:38:26 UTC (rev 76041)
+++ z3c.componentdebug/trunk/src/z3c/componentdebug/tests/tests.py 2007-05-31 06:23:23 UTC (rev 76042)
@@ -1,11 +1,14 @@
import unittest
from zope.testing import doctest
+from zope.component.testing import setUp, tearDown
def test_suite():
suite = doctest.DocFileSuite(
'site.txt',
'../README.txt',
'component.txt',
+ 'lookup.txt',
+ setUp=setUp, tearDown=tearDown,
optionflags=doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE)
return suite
More information about the Checkins
mailing list