[Checkins] SVN: z3c.componentdebug/trunk/src/z3c/componentdebug/ Much better error messages for ComponentLookupError patch

Ross Patterson me at rpatterson.net
Thu May 31 01:04:16 EDT 2007


Log message for revision 76039:
  Much better error messages for ComponentLookupError patch
  

Changed:
  U   z3c.componentdebug/trunk/src/z3c/componentdebug/README.txt
  U   z3c.componentdebug/trunk/src/z3c/componentdebug/lookup/__init__.py
  U   z3c.componentdebug/trunk/src/z3c/componentdebug/tests/site.txt

-=-
Modified: z3c.componentdebug/trunk/src/z3c/componentdebug/README.txt
===================================================================
--- z3c.componentdebug/trunk/src/z3c/componentdebug/README.txt	2007-05-31 04:40:05 UTC (rev 76038)
+++ z3c.componentdebug/trunk/src/z3c/componentdebug/README.txt	2007-05-31 05:04:15 UTC (rev 76039)
@@ -128,12 +128,18 @@
     >>> _api.getMultiAdapter((foo, bar), IBaz)
     Traceback (most recent call last):
     ...
-    VerboseComponentLookupError:
-    [AdapterRegistration(<BaseGlobalComponents base>, [IFoo, IBar],
-    IBaz, '', getBaz, u'')]
-    [(<Foo object at ...>,
-    [AdapterRegistration(<BaseGlobalComponents base>, [IFoo, IBar],
-    IBaz, '', getBaz, u'')]), (<Bar object at ...>, [])]
+    VerboseComponentLookupError: Lookup failed for...
+    objects: <Foo object at ...>, <Bar object at ...>
+    provided: <InterfaceClass __builtin__.IBaz>
+    name: 
+    Registrations with matching objects:
+    AdapterRegistration(<BaseGlobalComponents base>, [IFoo, IBar], IBaz, '', getBaz, u''):
+      - <Foo object at ...>
+      - unmatched: <Bar object at ...>
+    Objects with matching registrations:
+    <Foo object at ...>:
+      - AdapterRegistration(<BaseGlobalComponents base>, [IFoo, IBar], IBaz, '', getBaz, u'')
+    <Bar object at ...>: no matches
 
     >>> from z3c.componentdebug.lookup.patch import cleanup
     >>> cleanup()

Modified: z3c.componentdebug/trunk/src/z3c/componentdebug/lookup/__init__.py
===================================================================
--- z3c.componentdebug/trunk/src/z3c/componentdebug/lookup/__init__.py	2007-05-31 04:40:05 UTC (rev 76038)
+++ z3c.componentdebug/trunk/src/z3c/componentdebug/lookup/__init__.py	2007-05-31 05:04:15 UTC (rev 76039)
@@ -4,13 +4,44 @@
 
 from z3c.componentdebug.component import Registrations, all_methods
 
+"""
+
+"""
+
 class VerboseComponentLookupError(ComponentLookupError):
 
     def __init__(self, objects=False, provided=False, name=False,
                  context=None, methods=all_methods):
         self.registrations = Registrations(objects, provided, name,
                                            context, methods)
-        ComponentLookupError.__init__(
-            self, '\n'.join(
-                (str(self.registrations),
-                 str([i for i in self.registrations.byObject()]))))
+
+        str_ = 'Lookup failed for...\n\n'
+        if objects is not False:
+            str_ += 'objects: %s\n' % ', '.join(str(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
+
+        if objects is not False:
+            str_ += '\nRegistrations with matching objects:\n\n'
+            for reg, objs in self.registrations.byRegistration():
+                str_ += '%s:\n' % reg
+                for idx in xrange(self.registrations.order):
+                    obj = objs[idx]
+                    str_ += '  - %s%s\n' % (
+                        obj is False and 'unmatched: ' or '',
+                        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))
+                else:
+                    str_ += '%s: no matches\n' % obj
+        
+        ComponentLookupError.__init__(self, str_)        

Modified: z3c.componentdebug/trunk/src/z3c/componentdebug/tests/site.txt
===================================================================
--- z3c.componentdebug/trunk/src/z3c/componentdebug/tests/site.txt	2007-05-31 04:40:05 UTC (rev 76038)
+++ z3c.componentdebug/trunk/src/z3c/componentdebug/tests/site.txt	2007-05-31 05:04:15 UTC (rev 76039)
@@ -41,15 +41,24 @@
     >>> sm.getAdapter(None, Interface)
     Traceback (most recent call last):
     ...
-    VerboseComponentLookupError:
-    [AdapterRegistration(<PersistentComponents >, [Interface],
-    Interface, u'', <lambda>, u''),
+    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, [AdapterRegistration(<PersistentComponents >, [Interface],
-    Interface, u'', <lambda>, u''),
-    AdapterRegistration(<BaseGlobalComponents base>, [Interface],
-    Interface, u'', <lambda>, u'')])]
+    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'')
 
     >>> from z3c.componentdebug.lookup.patch import cleanup
     >>> cleanup()



More information about the Checkins mailing list