[CalendarServer-changes] [11729] CalendarServer/branches/users/glyph/log-cleanups/twext/python

source_changes at macosforge.org source_changes at macosforge.org
Tue Sep 17 16:02:35 PDT 2013


Revision: 11729
          http://trac.calendarserver.org//changeset/11729
Author:   glyph at apple.com
Date:     2013-09-17 16:02:35 -0700 (Tue, 17 Sep 2013)
Log Message:
-----------
Share constant between test and implementation module rather than duplicating it.

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/log-cleanups/twext/python/log.py
    CalendarServer/branches/users/glyph/log-cleanups/twext/python/test/test_log.py

Modified: CalendarServer/branches/users/glyph/log-cleanups/twext/python/log.py
===================================================================
--- CalendarServer/branches/users/glyph/log-cleanups/twext/python/log.py	2013-09-17 23:02:34 UTC (rev 11728)
+++ CalendarServer/branches/users/glyph/log-cleanups/twext/python/log.py	2013-09-17 23:02:35 UTC (rev 11729)
@@ -83,8 +83,10 @@
 from twisted.python.log import addObserver, removeObserver
 from twisted.python.log import ILogObserver as ILegacyLogObserver
 
+OBSERVER_REMOVED = (
+    "Temporarily removing observer {observer} due to exception: {e}"
+)
 
-
 #
 # Log level definitions
 #
@@ -549,10 +551,7 @@
                 #
                 self.removeObserver(observer)
                 try:
-                    self.log.failure(
-                        "Temporarily removing observer {observer} "
-                        "due to exception: {e}", observer=observer, e=e
-                    )
+                    self.log.failure(OBSERVER_REMOVED, observer=observer, e=e)
                 except BaseException:
                     pass
                 finally:

Modified: CalendarServer/branches/users/glyph/log-cleanups/twext/python/test/test_log.py
===================================================================
--- CalendarServer/branches/users/glyph/log-cleanups/twext/python/test/test_log.py	2013-09-17 23:02:34 UTC (rev 11728)
+++ CalendarServer/branches/users/glyph/log-cleanups/twext/python/test/test_log.py	2013-09-17 23:02:35 UTC (rev 11729)
@@ -27,7 +27,7 @@
     Logger, LegacyLogger,
     ILogObserver, LogPublisher, DefaultLogPublisher,
     FilteringLogObserver, PredicateResult,
-    LogLevelFilterPredicate,
+    LogLevelFilterPredicate, OBSERVER_REMOVED
 )
 
 
@@ -595,12 +595,13 @@
         # 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
+                event.get("log_format", None) == OBSERVER_REMOVED and
                 getattr(event.get("failure", None), "value") is exception
             ):
                 break
         else:
-            self.fail("Observer raised an exception and the exception was not logged.")
+            self.fail("Observer raised an exception "
+                      "and the exception was not logged.")
 
 
     def test_observerRaisesAndLoggerHatesMe(self):
@@ -835,6 +836,7 @@
         self.assertEquals(self.filterWith("twoPlus", "twoMinus", "no"),
                           [0, 1, 2, 3])
 
+
     def test_shouldLogEvent_badPredicateResult(self):
         self.assertRaises(TypeError, self.filterWith, "bogus")
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130917/e7f63ca8/attachment-0001.html>


More information about the calendarserver-changes mailing list