[CalendarServer-changes] [11288] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Mon Jun 3 14:51:41 PDT 2013
Revision: 11288
http://trac.calendarserver.org//changeset/11288
Author: wsanchez at apple.com
Date: 2013-06-03 14:51:40 -0700 (Mon, 03 Jun 2013)
Log Message:
-----------
Test bogus arg to log.err().
Separate the log.err() sub-tests into separate tests.
Modified Paths:
--------------
CalendarServer/trunk/twext/python/log.py
CalendarServer/trunk/twext/python/test/test_log.py
CalendarServer/trunk/twistedcaldav/directory/calendaruserproxyloader.py
CalendarServer/trunk/twistedcaldav/directory/xmlaccountsparser.py
CalendarServer/trunk/twistedcaldav/directory/xmlaugmentsparser.py
CalendarServer/trunk/txdav/caldav/datastore/scheduling/ischedule/localservers.py
Modified: CalendarServer/trunk/twext/python/log.py
===================================================================
--- CalendarServer/trunk/twext/python/log.py 2013-06-03 20:46:37 UTC (rev 11287)
+++ CalendarServer/trunk/twext/python/log.py 2013-06-03 21:51:40 UTC (rev 11288)
@@ -339,10 +339,8 @@
#
# Attach methods to Logger
#
- def log_emit(self, message=None, raiseException=None, **kwargs):
+ def log_emit(self, message=None, **kwargs):
self.emit(level, message, **kwargs)
- if raiseException:
- raise raiseException(message)
def will_emit(self):
return self.willLogAtLevel(level)
Modified: CalendarServer/trunk/twext/python/test/test_log.py
===================================================================
--- CalendarServer/trunk/twext/python/test/test_log.py 2013-06-03 20:46:37 UTC (rev 11287)
+++ CalendarServer/trunk/twext/python/test/test_log.py 2013-06-03 21:51:40 UTC (rev 11288)
@@ -329,60 +329,100 @@
self.assertIdentical(log.emitted["message"], None)
- def test_legacy_err(self):
+ def test_legacy_err_implicit(self):
"""
- Test LegacyLogger's log.err()
+ Test LegacyLogger's log.err() capturing the in-flight exception.
"""
log = TestLegacyLogger()
exception = RuntimeError("Oh me, oh my.")
kwargs = { "foo": "bar", "obj": object() }
+
+ try:
+ raise exception
+ except RuntimeError:
+ log.err(**kwargs)
+
+ self.legacy_err(log, kwargs, None, exception)
+
+
+ def test_legacy_err_exception(self):
+ """
+ Test LegacyLogger's log.err() with a given exception.
+ """
+ log = TestLegacyLogger()
+
+ exception = RuntimeError("Oh me, oh my.")
+ kwargs = { "foo": "bar", "obj": object() }
why = "Because I said so."
- def implicit():
- try:
- raise exception
- except RuntimeError:
- log.err(**kwargs)
+ try:
+ raise exception
+ except RuntimeError as e:
+ log.err(e, why, **kwargs)
- def withException():
- try:
- raise exception
- except RuntimeError as e:
- log.err(e, why, **kwargs)
+ self.legacy_err(log, kwargs, why, exception)
- def withFailure():
- try:
- raise exception
- except RuntimeError:
- log.err(Failure(), why, **kwargs)
- def withBogus():
- try:
- raise exception
- except RuntimeError:
- log.err(object(), why, **kwargs)
+ def test_legacy_err_failure(self):
+ """
+ Test LegacyLogger's log.err() with a given L{Failure}.
+ """
+ log = TestLegacyLogger()
- for rabbleRouser in (implicit, withException, withFailure):
- rabbleRouser()
+ exception = RuntimeError("Oh me, oh my.")
+ kwargs = { "foo": "bar", "obj": object() }
+ why = "Because I said so."
- #
- # 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)
+ try:
+ raise exception
+ except RuntimeError:
+ log.err(Failure(), why, **kwargs)
- self.assertIdentical(log.emitted["level"], LogLevel.error)
- self.assertIdentical(log.emitted["message"], None)
- self.assertIdentical(log.emitted["kwargs"]["failure"].__class__, Failure)
- self.assertIdentical(log.emitted["kwargs"]["failure"].value, exception)
+ self.legacy_err(log, kwargs, why, exception)
- if rabbleRouser is implicit:
- self.assertIdentical(log.emitted["kwargs"]["why"], None)
- else:
- self.assertIdentical(log.emitted["kwargs"]["why"], why)
- for key, value in kwargs.items():
- self.assertIdentical(log.emitted["kwargs"][key], value)
+ def test_legacy_err_bogus(self):
+ """
+ Test LegacyLogger's log.err() with a bogus argument.
+ """
+ log = TestLegacyLogger()
+
+ exception = RuntimeError("Oh me, oh my.")
+ kwargs = { "foo": "bar", "obj": object() }
+ why = "Because I said so."
+ bogus = object()
+
+ try:
+ raise exception
+ except RuntimeError:
+ log.err(bogus, why, **kwargs)
+
+ errors = self.flushLoggedErrors(exception.__class__)
+ self.assertEquals(len(errors), 0)
+
+ self.assertIdentical(log.emitted["level"], LogLevel.error)
+ self.assertEquals(log.emitted["message"], repr(bogus))
+ self.assertIdentical(log.emitted["kwargs"]["why"], why)
+
+ for key, value in kwargs.items():
+ self.assertIdentical(log.emitted["kwargs"][key], value)
+
+
+ def legacy_err(self, log, kwargs, why, exception):
+ #
+ # 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(exception.__class__)
+ self.assertEquals(len(errors), 1)
+
+ self.assertIdentical(log.emitted["level"], LogLevel.error)
+ self.assertEquals(log.emitted["message"], None)
+ self.assertIdentical(log.emitted["kwargs"]["failure"].__class__, Failure)
+ self.assertIdentical(log.emitted["kwargs"]["failure"].value, exception)
+ self.assertIdentical(log.emitted["kwargs"]["why"], why)
+
+ for key, value in kwargs.items():
+ self.assertIdentical(log.emitted["kwargs"][key], value)
Modified: CalendarServer/trunk/twistedcaldav/directory/calendaruserproxyloader.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/calendaruserproxyloader.py 2013-06-03 20:46:37 UTC (rev 11287)
+++ CalendarServer/trunk/twistedcaldav/directory/calendaruserproxyloader.py 2013-06-03 21:51:40 UTC (rev 11288)
@@ -60,8 +60,9 @@
try:
_ignore_tree, proxies_node = readXML(self.xmlFile, ELEMENT_PROXIES)
except ValueError, e:
- log.error("XML parse error for '%s' because: %s" % (self.xmlFile, e,), raiseException=RuntimeError)
+ log.failure("XML parse error for '%s'" % (self.xmlFile,), e)
+ # FIXME: RuntimeError is dumb.
self._parseXML(proxies_node)
def _parseXML(self, rootnode):
@@ -72,7 +73,7 @@
for child in rootnode.getchildren():
if child.tag != ELEMENT_RECORD:
- log.error("Unknown augment type: '%s' in augment file: '%s'" % (child.tag, self.xmlFile,), raiseException=RuntimeError)
+ raise RuntimeError("Unknown augment type: '%s' in augment file: '%s'" % (child.tag, self.xmlFile,))
repeat = int(child.get(ATTRIBUTE_REPEAT, "1"))
@@ -90,11 +91,11 @@
):
self._parseMembers(node, write_proxies if node.tag == ELEMENT_PROXIES else read_proxies)
else:
- log.error("Invalid element '%s' in proxies file: '%s'" % (node.tag, self.xmlFile,), raiseException=RuntimeError)
+ raise RuntimeError("Invalid element '%s' in proxies file: '%s'" % (node.tag, self.xmlFile,))
# Must have at least a guid
if not guid:
- log.error("Invalid record '%s' without a guid in proxies file: '%s'" % (child, self.xmlFile,), raiseException=RuntimeError)
+ raise RuntimeError("Invalid record '%s' without a guid in proxies file: '%s'" % (child, self.xmlFile,))
if repeat > 1:
for i in xrange(1, repeat+1):
Modified: CalendarServer/trunk/twistedcaldav/directory/xmlaccountsparser.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/xmlaccountsparser.py 2013-06-03 20:46:37 UTC (rev 11287)
+++ CalendarServer/trunk/twistedcaldav/directory/xmlaccountsparser.py 2013-06-03 21:51:40 UTC (rev 11288)
@@ -90,7 +90,7 @@
try:
_ignore_tree, accounts_node = readXML(self.xmlFile.path, ELEMENT_ACCOUNTS)
except ValueError, e:
- log.error("XML parse error for '%s' because: %s" % (self.xmlFile, e,), raiseException=RuntimeError)
+ raise RuntimeError("XML parse error for '%s' because: %s" % (self.xmlFile, e,))
self._parseXML(accounts_node)
def _parseXML(self, node):
Modified: CalendarServer/trunk/twistedcaldav/directory/xmlaugmentsparser.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/xmlaugmentsparser.py 2013-06-03 20:46:37 UTC (rev 11287)
+++ CalendarServer/trunk/twistedcaldav/directory/xmlaugmentsparser.py 2013-06-03 21:51:40 UTC (rev 11288)
@@ -80,7 +80,7 @@
try:
_ignore_tree, augments_node = readXML(self.xmlFile, ELEMENT_AUGMENTS)
except ValueError, e:
- log.error("XML parse error for '%s' because: %s" % (self.xmlFile, e,), raiseException=RuntimeError)
+ raise RuntimeError("XML parse error for '%s' because: %s" % (self.xmlFile, e,))
self._parseXML(augments_node)
@@ -92,7 +92,7 @@
for child in rootnode.getchildren():
if child.tag != ELEMENT_RECORD:
- log.error("Unknown augment type: '%s' in augment file: '%s'" % (child.tag, self.xmlFile,), raiseException=RuntimeError)
+ raise RuntimeError("Unknown augment type: '%s' in augment file: '%s'" % (child.tag, self.xmlFile,))
repeat = int(child.get(ATTRIBUTE_REPEAT, "1"))
@@ -117,11 +117,11 @@
):
fields[node.tag] = node.text == VALUE_TRUE
else:
- log.error("Invalid element '%s' in augment file: '%s'" % (node.tag, self.xmlFile,), raiseException=RuntimeError)
+ raise RuntimeError("Invalid element '%s' in augment file: '%s'" % (node.tag, self.xmlFile,))
# Must have at least a uid
if ELEMENT_UID not in fields:
- log.error("Invalid record '%s' without a uid in augment file: '%s'" % (child, self.xmlFile,), raiseException=RuntimeError)
+ raise RuntimeError("Invalid record '%s' without a uid in augment file: '%s'" % (child, self.xmlFile,))
if repeat > 1:
for i in xrange(1, repeat+1):
Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/ischedule/localservers.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/ischedule/localservers.py 2013-06-03 20:46:37 UTC (rev 11287)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/ischedule/localservers.py 2013-06-03 21:51:40 UTC (rev 11288)
@@ -267,12 +267,12 @@
try:
_ignore_tree, servers_node = readXML(xmlFile, ELEMENT_SERVERS)
except ValueError, e:
- log.error("XML parse error for '%s' because: %s" % (xmlFile, e,), raiseException=RuntimeError)
+ raise RuntimeError("XML parse error for '%s' because: %s" % (xmlFile, e,))
for child in servers_node.getchildren():
if child.tag != ELEMENT_SERVER:
- log.error("Unknown server type: '%s' in servers file: '%s'" % (child.tag, xmlFile,), raiseException=RuntimeError)
+ raise RuntimeError("Unknown server type: '%s' in servers file: '%s'" % (child.tag, xmlFile,))
server = Server()
server.isImplicit = child.get(ATTR_IMPLICIT, ATTR_VALUE_YES) == ATTR_VALUE_YES
@@ -289,10 +289,10 @@
elif node.tag == ELEMENT_PARTITIONS:
ServersParser._parsePartition(xmlFile, node, server)
else:
- log.error("Invalid element '%s' in servers file: '%s'" % (node.tag, xmlFile,), raiseException=RuntimeError)
+ raise RuntimeError("Invalid element '%s' in servers file: '%s'" % (node.tag, xmlFile,))
if server.id is None or server.uri is None:
- log.error("Invalid partition '%s' in servers file: '%s'" % (child.tag, xmlFile,), raiseException=RuntimeError)
+ raise RuntimeError("Invalid partition '%s' in servers file: '%s'" % (child.tag, xmlFile,))
server.check(ignoreIPLookupFailures=ignoreIPLookupFailures)
results[server.id] = server
@@ -306,7 +306,7 @@
for child in partitions.getchildren():
if child.tag != ELEMENT_PARTITION:
- log.error("Unknown partition type: '%s' in servers file: '%s'" % (child.tag, xmlFile,), raiseException=RuntimeError)
+ raise RuntimeError("Unknown partition type: '%s' in servers file: '%s'" % (child.tag, xmlFile,))
id = None
uri = None
@@ -316,9 +316,9 @@
elif node.tag == ELEMENT_URI:
uri = node.text
else:
- log.error("Invalid element '%s' in augment file: '%s'" % (node.tag, xmlFile,), raiseException=RuntimeError)
+ raise RuntimeError("Invalid element '%s' in augment file: '%s'" % (node.tag, xmlFile,))
if id is None or uri is None:
- log.error("Invalid partition '%s' in servers file: '%s'" % (child.tag, xmlFile,), raiseException=RuntimeError)
+ raise RuntimeError("Invalid partition '%s' in servers file: '%s'" % (child.tag, xmlFile,))
server.addPartition(id, uri)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130603/5dfab49b/attachment-0001.html>
More information about the calendarserver-changes
mailing list