[CalendarServer-changes] [11680] CalendarServer/trunk/twext/python/test/test_log.py
source_changes at macosforge.org
source_changes at macosforge.org
Thu Sep 12 15:13:56 PDT 2013
Revision: 11680
http://trac.calendarserver.org//changeset/11680
Author: wsanchez at apple.com
Date: 2013-09-12 15:13:56 -0700 (Thu, 12 Sep 2013)
Log Message:
-----------
Add test_observerRaiseAndLoggerHatesMe().
In test_observerRaises(), verify that the exception was logged.
Modified Paths:
--------------
CalendarServer/trunk/twext/python/test/test_log.py
Modified: CalendarServer/trunk/twext/python/test/test_log.py
===================================================================
--- CalendarServer/trunk/twext/python/test/test_log.py 2013-09-12 21:24:21 UTC (rev 11679)
+++ CalendarServer/trunk/twext/python/test/test_log.py 2013-09-12 22:13:56 UTC (rev 11680)
@@ -557,16 +557,19 @@
def test_observerRaises(self):
+ nonTestEvents = []
+ Logger.publisher.addObserver(lambda e: nonTestEvents.append(e))
+
event = dict(foo=1, bar=2)
exception = RuntimeError("ARGH! EVIL DEATH!")
events = []
- def o(event):
+ def observer(event):
events.append(event)
raise exception
- publisher = LogPublisher(o)
+ publisher = LogPublisher(observer)
publisher(event)
# Verify that the observer saw my event
@@ -577,8 +580,39 @@
self.assertEquals(len(errors), 1)
self.assertIdentical(errors[0].value, exception)
+ # Verify that the exception was logged
+ for event in nonTestEvents:
+ if (
+ event.get("log_format", None) == "Temporarily removing observer {observer} due to exception: {e}" and
+ getattr(event.get("failure", None), "value") is exception
+ ):
+ break
+ else:
+ self.fail("Observer raised an exception and the exception was not logged.")
+ def test_observerRaiseAndLoggerHatesMe(self):
+ nonTestEvents = []
+ Logger.publisher.addObserver(lambda e: nonTestEvents.append(e))
+
+ event = dict(foo=1, bar=2)
+ exception = RuntimeError("ARGH! EVIL DEATH!")
+
+ def observer(event):
+ raise RuntimeError("Sad panda")
+
+ class GurkLogger(Logger):
+ def failure(self, *args, **kwargs):
+ raise exception
+
+ publisher = LogPublisher(observer)
+ publisher.log = GurkLogger()
+ publisher(event)
+
+ # Here, the lack of an exception thus far is a success, of sorts
+
+
+
class FilteringLogObserverTests(SetUpTearDown, unittest.TestCase):
"""
Tests for L{FilteringLogObserver}.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130912/308bfc3a/attachment.html>
More information about the calendarserver-changes
mailing list