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

source_changes at macosforge.org source_changes at macosforge.org
Fri Jun 14 16:51:23 PDT 2013


Revision: 11370
          http://trac.calendarserver.org//changeset/11370
Author:   wsanchez at apple.com
Date:     2013-06-14 16:51:23 -0700 (Fri, 14 Jun 2013)
Log Message:
-----------
Add test_formatEventNoFormat, test_formatEventWeirdFormat.

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-06-14 22:26:48 UTC (rev 11369)
+++ CalendarServer/trunk/twext/python/log.py	2013-06-14 23:51:23 UTC (rev 11370)
@@ -227,12 +227,16 @@
             raise ValueError("No log format provided")
 
         # Make sure format is unicode.
-        if type(format) is bytes:
+        if isinstance(format, bytes):
             # If we get bytes, assume it's UTF-8 bytes
             format = format.decode("utf-8")
+
+        elif isinstance(format, unicode):
+            pass
+
         else:
-            # For anything else, assume we can just convert to unicode
-            format = unicode(format)
+            raise TypeError("Log format must be unicode or bytes, not {0!r}"
+                            .format(format))
 
         return formatWithCall(format, event)
 

Modified: CalendarServer/trunk/twext/python/test/test_log.py
===================================================================
--- CalendarServer/trunk/twext/python/test/test_log.py	2013-06-14 22:26:48 UTC (rev 11369)
+++ CalendarServer/trunk/twext/python/test/test_log.py	2013-06-14 23:51:23 UTC (rev 11370)
@@ -241,7 +241,28 @@
                       format(b"S{a!r}nchez", a=b"\xe1"))
 
 
+    def test_formatEventNoFormat(self):
+        """
+        Formatting an event with no format.
+        """
+        event = dict(foo=1, bar=2)
+        result = formatEvent(event)
 
+        self.assertIn("Unable to format event", result)
+        self.assertIn(repr(event), result)
+
+
+    def test_formatEventWeirdFormat(self):
+        """
+        Formatting an event with a bogus format.
+        """
+        event = dict(log_format=object(), foo=1, bar=2)
+        result = formatEvent(event)
+
+        self.assertIn("Log format must be unicode or bytes", result)
+        self.assertIn(repr(event), result)
+
+
 class LoggerTests(SetUpTearDown, TestCase):
     """
     Tests for L{Logger}.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130614/5051e1c5/attachment.html>


More information about the calendarserver-changes mailing list