[CalendarServer-changes] [9690] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Mon Aug 13 09:41:28 PDT 2012
Revision: 9690
http://trac.macosforge.org/projects/calendarserver/changeset/9690
Author: glyph at apple.com
Date: 2012-08-13 09:41:28 -0700 (Mon, 13 Aug 2012)
Log Message:
-----------
`__getattr__` should raise `AttributeError`, not `KeyError`.
Modified Paths:
--------------
CalendarServer/trunk/twext/enterprise/dal/syntax.py
CalendarServer/trunk/twext/enterprise/dal/test/test_sqlsyntax.py
Property Changed:
----------------
CalendarServer/trunk/
Modified: CalendarServer/trunk/twext/enterprise/dal/syntax.py
===================================================================
--- CalendarServer/trunk/twext/enterprise/dal/syntax.py 2012-08-11 09:01:06 UTC (rev 9689)
+++ CalendarServer/trunk/twext/enterprise/dal/syntax.py 2012-08-13 16:41:28 UTC (rev 9690)
@@ -43,16 +43,18 @@
class DALError(Exception):
"""
- Base class for exceptions raised by this module. This can be raised directly for
- API violations. This exception represents a serious programming error and should
- normally never be caught or ignored.
+ Base class for exceptions raised by this module. This can be raised
+ directly for API violations. This exception represents a serious
+ programming error and should normally never be caught or ignored.
"""
+
+
class QueryPlaceholder(object):
"""
Representation of the placeholders required to generate some SQL, for a
- single statement. Contains information necessary
- to generate place holder strings based on the database dialect.
+ single statement. Contains information necessary to generate place holder
+ strings based on the database dialect.
"""
def placeholder(self):
@@ -562,7 +564,14 @@
integer, baz integer)', 'schemaSyntax.foo.bar' and
'schemaSyntax.foo.baz'
"""
- return ColumnSyntax(self.model.columnNamed(attr))
+ try:
+ column = self.model.columnNamed(attr)
+ except KeyError:
+ raise AttributeError("table {0} has no column {1}".format(
+ self.model.name, attr
+ ))
+ else:
+ return ColumnSyntax(column)
def __iter__(self):
Modified: CalendarServer/trunk/twext/enterprise/dal/test/test_sqlsyntax.py
===================================================================
--- CalendarServer/trunk/twext/enterprise/dal/test/test_sqlsyntax.py 2012-08-11 09:01:06 UTC (rev 9689)
+++ CalendarServer/trunk/twext/enterprise/dal/test/test_sqlsyntax.py 2012-08-13 16:41:28 UTC (rev 9690)
@@ -433,6 +433,24 @@
)
+ def test_tableIteration(self):
+ """
+ Iterating a L{TableSyntax} iterates its columns, in the order that they
+ are defined.
+ """
+ self.assertEquals(list(self.schema.FOO),
+ [self.schema.FOO.BAR, self.schema.FOO.BAZ])
+
+
+ def test_noColumn(self):
+ """
+ Accessing an attribute that is not a defined column on a L{TableSyntax}
+ raises an L{AttributeError}.
+ """
+ self.assertRaises(AttributeError,
+ lambda : self.schema.FOO.NOT_A_COLUMN)
+
+
def test_columnAliases(self):
"""
When attributes are set on a L{TableSyntax}, they will be remembered as
@@ -719,8 +737,8 @@
def test_inSubSelect(self):
"""
- L{ColumnSyntax.In} returns a sub-expression using the SQL 'in' syntax with
- a sub-select.
+ L{ColumnSyntax.In} returns a sub-expression using the SQL 'in' syntax
+ with a sub-select.
"""
wherein = (self.schema.FOO.BAR.In(
Select([self.schema.BOZ.QUX], From=self.schema.BOZ)))
@@ -732,10 +750,9 @@
def test_inParameter(self):
"""
- L{ColumnSyntax.In} returns a sub-expression using the SQL 'in' syntax with
- parameter list.
+ L{ColumnSyntax.In} returns a sub-expression using the SQL 'in' syntax
+ with parameter list.
"""
-
# One item with IN only
items = set(('A',))
self.assertEquals(
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120813/a3b09c7d/attachment.html>
More information about the calendarserver-changes
mailing list