[Checkins] SVN: zope.introspector/trunk/src/zope/introspector/tests/descriptorgrokker.txt Add tests for descriptorgrokker.

Uli Fouquet uli at gnufix.de
Thu Jul 3 18:59:54 EDT 2008


Log message for revision 87973:
  Add tests for descriptorgrokker.

Changed:
  A   zope.introspector/trunk/src/zope/introspector/tests/descriptorgrokker.txt

-=-
Added: zope.introspector/trunk/src/zope/introspector/tests/descriptorgrokker.txt
===================================================================
--- zope.introspector/trunk/src/zope/introspector/tests/descriptorgrokker.txt	                        (rev 0)
+++ zope.introspector/trunk/src/zope/introspector/tests/descriptorgrokker.txt	2008-07-03 22:59:54 UTC (rev 87973)
@@ -0,0 +1,70 @@
+The description provider grokker
+********************************
+
+:Test-Layer: unit
+
+The DescriptionProviderGrokker
+==============================
+
+The ``DescriptionProviderGrokker`` adds classes to the registry in the
+`descriptionprovider` module. In the beginning, this registry is
+empty::
+
+  >>> import zope.introspector.descriptionprovider as zid 
+  >>> reg = zid.descriptor_registry
+  >>> reg
+  []
+
+We create an Grokker instance::
+
+  >>> from zope.introspector.meta import DescriptionProviderGrokker
+  >>> grokker = DescriptionProviderGrokker()
+
+
+Description providers have an ordering
+--------------------------------------
+
+Now we can add an object to the registry by calling the ``execute``
+method of the grokker. The grokker expects a class and a priority
+number between 0 (highest priority) and 1000 (lowest)::
+
+  >>> grokker.execute(object, 666)
+  True
+
+The registry now contains an entry::
+
+  >>> from pprint import pprint
+  >>> pprint(sorted(reg))
+  [{'priority': 666, 'handler': <type 'object'>}]
+
+If we call the grokker with a lower number, it should be inserted
+before the existing one::
+
+  >>> trash = grokker.execute(object, 665)
+  >>> pprint(reg)
+  [{'priority': 665, 'handler': <type 'object'>},
+   {'priority': 666, 'handler': <type 'object'>}]
+
+
+The same applies to entries with an existing priority::
+
+  >>> trash = grokker.execute(int, 666)
+  >>> pprint(reg)
+  [{'priority': 665, 'handler': <type 'object'>},
+   {'priority': 666, 'handler': <type 'int'>},
+   {'priority': 666, 'handler': <type 'object'>}]
+
+
+An upper priority will insert the new object at the end of the list::
+
+  >>> trash = grokker.execute(object, 667)
+  >>> pprint(reg)
+  [{'priority': 665, 'handler': <type 'object'>},
+   {'priority': 666, 'handler': <type 'int'>},
+   {'priority': 666, 'handler': <type 'object'>},
+   {'priority': 667, 'handler': <type 'object'>}]
+
+
+Clean up the registry::
+
+  >>> del zid.descriptor_registry[0:4]



More information about the Checkins mailing list