Skip to content
This repository has been archived by the owner on May 13, 2020. It is now read-only.

Commit

Permalink
Test the logging decorator a bit more.
Browse files Browse the repository at this point in the history
  • Loading branch information
strichter committed Mar 29, 2012
1 parent 62100a1 commit 6e9a2c5
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/mongopersist/tests/test_datamanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,56 @@ def doctest_ProcessSpecDecorator_basic():
>>> 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,
Expand Down

0 comments on commit 6e9a2c5

Please sign in to comment.