>>> from sqlalchemy import Column, Integer
>>> from sqlalchemy.sql import ColumnCollection
>>> x, y = Column('x', Integer), Column('y', Integer)
- >>> cc = ColumnCollection(columns=[x, y])
+ >>> cc = ColumnCollection(columns=[(x.name, x), (y.name, y)])
>>> cc.x
Column('x', Integer(), table=None)
>>> cc.y
returned by key access is **arbitrary**::
>>> x1, x2 = Column('x', Integer), Column('x', Integer)
- >>> cc = ColumnCollection(columns=[x1, x2])
+ >>> cc = ColumnCollection(columns=[(x1.name, x1), (x2.name, x2)])
>>> list(cc)
[Column('x', Integer(), table=None),
Column('x', Integer(), table=None)]
return default
def __str__(self):
- return repr([str(c) for c in self])
+ return "%s(%s)" % (
+ self.__class__.__name__,
+ ", ".join(str(c) for c in self),
+ )
def __setitem__(self, key, value):
raise NotImplementedError()
).compare(self._column_collection([("col1", c1), ("col2", c2)]))
)
+ def test_str(self):
+ c1 = sql.column("col1")
+ c2 = c1.label("col2")
+ c3 = sql.column("col3")
+ cc = self._column_collection(
+ [("col1", c1), ("col2", c2), ("col3", c3)]
+ )
+
+ eq_(str(cc), "%s(%s, %s, %s)" % (type(cc).__name__, c1, c2, c3))
+ eq_(repr(cc), object.__repr__(cc))
+
class ColumnCollectionTest(ColumnCollectionCommon, fixtures.TestBase):
def _column_collection(self, columns=None):