[Checkins] SVN: mongopersist/trunk/src/mongopersist/tests/test_datamanager.py Test the logging decorator a bit more.

Stephen Richter cvs-admin at zope.org
Thu Mar 29 23:06:20 UTC 2012


Log message for revision 124800:
  Test the logging decorator a bit more.

Changed:
  U   mongopersist/trunk/src/mongopersist/tests/test_datamanager.py

-=-
Modified: mongopersist/trunk/src/mongopersist/tests/test_datamanager.py
===================================================================
--- mongopersist/trunk/src/mongopersist/tests/test_datamanager.py	2012-03-29 22:25:51 UTC (rev 124799)
+++ mongopersist/trunk/src/mongopersist/tests/test_datamanager.py	2012-03-29 23:06:16 UTC (rev 124800)
@@ -841,6 +841,56 @@
       >>> PlacelessSetup().tearDown()
     """
 
+
+def doctest_LoggingDecorator_basic():
+    r"""class LoggingDecorator: basic
+
+    The ``LoggingDecorator`` decorator will log the name, arguments ans even
+    current stack of a function call. Let's stub the logger:
+
+      >>> orig_log_debug = datamanager.COLLECTION_LOG.debug
+      >>> def fake_debug(msg, *args):
+      ...     print msg % args
+      >>> datamanager.COLLECTION_LOG.debug = fake_debug
+
+    Let's create the decorator:
+
+      >>> coll = conn[DBNAME]['mongopersist.tests.test_datamanager.Foo']
+      >>> logging_find = datamanager.LoggingDecorator(coll, coll.find)
+      >>> list(logging_find({'life': 42}))
+      collection: mongopersist_test.mongopersist.tests.test_datamanager.Foo find,
+       args:({'life': 42},),
+       kwargs:{},
+       tb:
+          ...
+          list(logging_find({'life': 42}))
+      <BLANKLINE>
+      []
+
+    Keyword arguments are also supported:
+
+      >>> list(logging_find(spec={'life': 42}))
+      collection: mongopersist_test.mongopersist.tests.test_datamanager.Foo find,
+       args:(),
+       kwargs:{'spec': {'life': 42}},
+       tb:
+          ...
+          list(logging_find(spec={'life': 42}))
+      <BLANKLINE>
+      []
+
+    Tracebacks can also be turned off:
+
+      >>> logging_find.ADD_TB = False
+      >>> list(logging_find({'life': 42}))
+      collection: mongopersist_test.mongopersist.tests.test_datamanager.Foo find,
+       args:({'life': 42},),
+       kwargs:{},
+       tb:
+      <omitted>
+      []
+    """
+
 def test_suite():
     return doctest.DocTestSuite(
         setUp=testing.setUp, tearDown=testing.tearDown,



More information about the checkins mailing list