Merge lp:~frankban/python-fixtures/fakelogger-getdetails into lp:~python-fixtures/python-fixtures/trunk
Proposed by
Francesco Banconi
Status: | Merged |
---|---|
Merged at revision: | 51 |
Proposed branch: | lp:~frankban/python-fixtures/fakelogger-getdetails |
Merge into: | lp:~python-fixtures/python-fixtures/trunk |
Diff against target: |
117 lines (+24/-10) 3 files modified
lib/fixtures/_fixtures/logger.py (+9/-3) lib/fixtures/fixture.py (+5/-5) lib/fixtures/tests/_fixtures/test_logger.py (+10/-2) |
To merge this branch: | bzr merge lp:~frankban/python-fixtures/fakelogger-getdetails |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
python-fixtures committers | Pending | ||
Review via email: mp+108593@code.launchpad.net |
Description of the change
Following Robert suggestion in his comment to bug 1001520, I've used the FakeLogger fixture to capture Memcached logs in tests generating warnings. This branch implements FakeLogger.
I was confused about what name to use for the detail, I ended up using the FakeLogger instance class name, but I am open to suggestions.
To post a comment you must log in.
Thanks for this patch.
There seem to be a lot of whitespace changes in the diff? Possibly
harmless, but confusing.
Rather than implementing getDetails, the normal mechanism is to call
self.addDetail with a detail that will return the appropriate content
when evaluated. This is cheaper than evaluating when getDetails is
called, and means you only need to test that an appropriate detail is
added, rather than that the getDetails method still Does The Right
Thing. The UTF8_TEXT helper is probably revelant here too, for
brevity.
Finally, on the naming of things, I'd describe the attachment - think
of it as an email attachment.
So, in summary - something like:
E.g.:
=== modified file 'lib/fixtures/ _fixtures/ logger. py' _fixtures/ logger. py 2011-11-25 17:37:36 +0000 _fixtures/ logger. py 2012-06-04 20:16:20 +0000
--- lib/fixtures/
+++ lib/fixtures/
@@ -18,6 +18,10 @@
from fixtures import Fixture
+from testtools.content import Content content_ type import UTF8_TEXT ture',
+from testtools.
+
__all__ = [
'FakeLogger',
'LoggerFix
@@ -52,7 +56,10 @@
def setUp(self):
super( FakeLogger, self).setUp() u"pythonlogging :'%s'" % self._name, self._name)
self. addCleanup( logger. setLevel, logger.level)
- self._output = StringIO()
+ output = StringIO()
+ self._output = output
+ self.addDetail(
+ Content(UTF8_TEXT, lambda: [output]))
logger = getLogger(
if self._level:
Note the use of a closure here so that d = f.getDetails(), )[0].itertext( ) will not return the
f.cleanUp(), f.setUp(), d.items(
new (empty) state of the fixture.
HTH,
Rob