diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-07-27 11:36:57 -0400 |
---|---|---|
committer | Federico Caselli <cfederico87@gmail.com> | 2022-08-01 21:46:33 +0000 |
commit | 1ecbf14cc24aa0b1d303926178941c1f7f9fe93b (patch) | |
tree | 9d6db71363b3dd90dfc69b5388902d68f9e57cb2 /test/base/test_utils.py | |
parent | 3ff18812d8d80b2016ceeea98c808a76cae85e48 (diff) | |
download | sqlalchemy-1ecbf14cc24aa0b1d303926178941c1f7f9fe93b.tar.gz |
implement tuple-slices from .c collections
Added new syntax to the ``.c`` collection on all :class:`.FromClause`
objects allowing tuples of keys to be passed to ``__getitem__()``, along
with support for ``select()`` handling of ``.c`` collections directly,
allowing the syntax ``select(table.c['a', 'b', 'c'])`` to be possible. The
sub-collection returned is itself a :class:`.ColumnCollection` which is
also directly consumable by :func:`_sql.select` and similar now.
Fixes: #8285
Change-Id: I2236662c477ffc50af079310589e213323c960d1
Diffstat (limited to 'test/base/test_utils.py')
-rw-r--r-- | test/base/test_utils.py | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/test/base/test_utils.py b/test/base/test_utils.py index c5a47ddf9..98451cc4f 100644 --- a/test/base/test_utils.py +++ b/test/base/test_utils.py @@ -550,8 +550,10 @@ class ColumnCollectionCommon(testing.AssertsCompiledSQL): eq_(coll._colset, set(c for k, c in coll._collection)) d = {} for k, col in coll._collection: - d.setdefault(k, col) - d.update({idx: col for idx, (k, col) in enumerate(coll._collection)}) + d.setdefault(k, (k, col)) + d.update( + {idx: (k, col) for idx, (k, col) in enumerate(coll._collection)} + ) eq_(coll._index, d) def test_keys(self): @@ -593,6 +595,27 @@ class ColumnCollectionCommon(testing.AssertsCompiledSQL): ci = cc.as_readonly() eq_(ci.items(), [("c1", c1), ("foo", c2), ("c3", c3)]) + def test_getitem_tuple_str(self): + c1, c2, c3 = sql.column("c1"), sql.column("c2"), sql.column("c3") + c2.key = "foo" + cc = self._column_collection( + columns=[("c1", c1), ("foo", c2), ("c3", c3)] + ) + sub_cc = cc["c3", "foo"] + is_(sub_cc.c3, c3) + eq_(list(sub_cc), [c3, c2]) + + def test_getitem_tuple_int(self): + c1, c2, c3 = sql.column("c1"), sql.column("c2"), sql.column("c3") + c2.key = "foo" + cc = self._column_collection( + columns=[("c1", c1), ("foo", c2), ("c3", c3)] + ) + + sub_cc = cc[2, 1] + is_(sub_cc.c3, c3) + eq_(list(sub_cc), [c3, c2]) + def test_key_index_error(self): cc = self._column_collection( columns=[ |