summaryrefslogtreecommitdiff
path: root/test/sql/test_select.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2023-04-22 09:41:49 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2023-04-22 12:20:43 -0400
commitd62de424ef738a0cfb9c682d9b25a8644dff5985 (patch)
treef97f37ade36b3f97cb608757b9b1cbd589fe074b /test/sql/test_select.py
parentb3e01c30d2610f5454eda5b29f093b65e54230b5 (diff)
downloadsqlalchemy-d62de424ef738a0cfb9c682d9b25a8644dff5985.tar.gz
support slice access for .c
Added support for slice access with :class:`.ColumnCollection`, e.g. ``table.c[0:5]``, ``subquery.c[:-1]`` etc. Slice access returns a sub :class:`.ColumnCollection` in the same way as passing a tuple of keys. This is a natural continuation of the key-tuple access added for :ticket:`8285`, which it appears to be an oversight that this usage was omitted. Change-Id: I6378642f39501ffbbae4acadf1dc38a43c39d722 References: #8285 References: #9690
Diffstat (limited to 'test/sql/test_select.py')
-rw-r--r--test/sql/test_select.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/test/sql/test_select.py b/test/sql/test_select.py
index 7979fd200..5268c41dc 100644
--- a/test/sql/test_select.py
+++ b/test/sql/test_select.py
@@ -528,6 +528,22 @@ class ColumnCollectionAsSelectTest(fixtures.TestBase, AssertsCompiledSQL):
eq_(list(coll), [table1.c.description, table1.c.myid])
+ def test_c_sub_collection_positive_slice(self):
+ coll = table1.c[0:2]
+
+ is_(coll.myid, table1.c.myid)
+ is_(coll.name, table1.c.name)
+
+ eq_(list(coll), [table1.c.myid, table1.c.name])
+
+ def test_c_sub_collection_negative_slice(self):
+ coll = table1.c[-2:]
+
+ is_(coll.name, table1.c.name)
+ is_(coll.description, table1.c.description)
+
+ eq_(list(coll), [table1.c.name, table1.c.description])
+
def test_missing_key(self):
with expect_raises_message(KeyError, "unknown"):