diff options
author | Sean Dague <sean@dague.net> | 2014-09-25 07:16:06 -0400 |
---|---|---|
committer | Robert Collins <robertc@robertcollins.net> | 2014-09-26 08:48:10 +1200 |
commit | f556cff258c44a3e9d8e556e6ebb3bd303b623c5 (patch) | |
tree | 010846dbfac77fe3a9306342cc2df5494ff8cec2 /fixtures/tests | |
parent | 797b17bc3a801e7ebaac4a9b48cb37b9ddf8b61c (diff) | |
download | fixtures-git-f556cff258c44a3e9d8e556e6ebb3bd303b623c5.tar.gz |
Add support for datefmt in FakeLogger
The logging fixture is extremely useful to be used a temp buffer for
collecting log messages into a buffer, and only decide if we're going
to emit them after some event in the future (like the failure or
success of some future criteria). However, in it's current form we are
not given access to the datefmt variable of the underlying Formatter,
which means we always end up with the default python time string for
%(asctime), which looks incorrectly localized many places.
This merely adds the ability to pass the datefmt param through to the
Formatter.
Signed-off-by: Sean Dague <sean@dague.net>
Diffstat (limited to 'fixtures/tests')
-rw-r--r-- | fixtures/tests/_fixtures/test_logger.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/fixtures/tests/_fixtures/test_logger.py b/fixtures/tests/_fixtures/test_logger.py index 1f69459..bde29ec 100644 --- a/fixtures/tests/_fixtures/test_logger.py +++ b/fixtures/tests/_fixtures/test_logger.py @@ -14,6 +14,7 @@ # limitations under that license. import logging +import time from testtools import TestCase from testtools.compat import StringIO @@ -81,6 +82,15 @@ class FakeLoggerTest(TestCase, TestWithFixtures): logging.info("message") self.assertEqual("test_logger\n", fixture.output) + def test_custom_datefmt(self): + fixture = FakeLogger(format="%(asctime)s %(module)s", + datefmt="%Y") + self.useFixture(fixture) + logging.info("message") + self.assertEqual( + time.strftime("%Y test_logger\n", time.localtime()), + fixture.output) + def test_logging_output_included_in_details(self): fixture = FakeLogger() detail_name = "pythonlogging:''" |