[CalendarServer-changes] [11274] CalendarServer/trunk/twext/python

source_changes at macosforge.org source_changes at macosforge.org
Thu May 30 13:41:42 PDT 2013


Revision: 11274
          http://trac.calendarserver.org//changeset/11274
Author:   wsanchez at apple.com
Date:     2013-05-30 13:41:42 -0700 (Thu, 30 May 2013)
Log Message:
-----------
Add test_defaultFailure.
Add message optional arg to log.failure().  Shove it into why instead of message, because twisted.log is weird.

Modified Paths:
--------------
    CalendarServer/trunk/twext/python/log.py
    CalendarServer/trunk/twext/python/test/test_log.py

Modified: CalendarServer/trunk/twext/python/log.py
===================================================================
--- CalendarServer/trunk/twext/python/log.py	2013-05-30 20:34:14 UTC (rev 11273)
+++ CalendarServer/trunk/twext/python/log.py	2013-05-30 20:41:42 UTC (rev 11274)
@@ -269,14 +269,14 @@
         twistedLogMessage(**kwargs)
 
 
-    def failure(self, failure=None, **kwargs):
+    def failure(self, message=None, failure=None, **kwargs):
         """
         Log a Failure.
         """
         if failure is None:
             failure=Failure()
 
-        self.emit(LogLevel.error, failure=failure, isError=1, **kwargs)
+        self.emit(LogLevel.error, None, failure=failure, isError=1, why=message, **kwargs)
 
 
     def level(self):

Modified: CalendarServer/trunk/twext/python/test/test_log.py
===================================================================
--- CalendarServer/trunk/twext/python/test/test_log.py	2013-05-30 20:34:14 UTC (rev 11273)
+++ CalendarServer/trunk/twext/python/test/test_log.py	2013-05-30 20:41:42 UTC (rev 11274)
@@ -33,7 +33,7 @@
 
 
 class TestLogger(Logger):
-    def emit(self, level, message, **kwargs):
+    def emit(self, level, message=None, **kwargs):
         def observer(eventDict):
             self.eventDict = eventDict
 
@@ -152,6 +152,27 @@
                 self.assertFalse(hasattr(log, "eventDict"))
 
 
+    def test_defaultFailure(self):
+        """
+        Test that log.failure() emits the right data.
+        """
+        log = TestLogger()
+        try:
+            raise RuntimeError("baloney!")
+        except RuntimeError:
+            log.failure()
+
+        #
+        # log.failure() will cause trial to complain, so here we check that
+        # trial saw the correct error and remove it from the list of things to
+        # complain about.
+        #
+        errors = self.flushLoggedErrors(RuntimeError)
+        self.assertEquals(len(errors), 1)
+
+        self.assertEquals(log.emitted["level"], LogLevel.error)
+
+
     def test_conflicting_kwargs(self):
         """
         Make sure that conflicting kwargs don't pass through.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130530/24e5506c/attachment-0001.html>


More information about the calendarserver-changes mailing list