summaryrefslogtreecommitdiffstats
path: root/Lib/sqlite3
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-03-31 10:33:11 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-03-31 10:33:11 (GMT)
commit72e731cc03f29cdb8bf17bd9ea34c8448954c798 (patch)
tree02c4ac35bf8bdce758dea1e363912fea0ed3a277 /Lib/sqlite3
parent80d84c89ee8f10cd3a5d1dfa2ea1cd51f810ec33 (diff)
downloadcpython-72e731cc03f29cdb8bf17bd9ea34c8448954c798.zip
cpython-72e731cc03f29cdb8bf17bd9ea34c8448954c798.tar.gz
cpython-72e731cc03f29cdb8bf17bd9ea34c8448954c798.tar.bz2
Issue #13583: sqlite3.Row now supports slice indexing.
Tests by Jessica McKellar.
Diffstat (limited to 'Lib/sqlite3')
-rw-r--r--Lib/sqlite3/test/factory.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/sqlite3/test/factory.py b/Lib/sqlite3/test/factory.py
index 98dcae5..3d4eb0b 100644
--- a/Lib/sqlite3/test/factory.py
+++ b/Lib/sqlite3/test/factory.py
@@ -111,6 +111,24 @@ class RowFactoryTests(unittest.TestCase):
with self.assertRaises(IndexError):
row[2**1000]
+ def CheckSqliteRowSlice(self):
+ # A sqlite.Row can be sliced like a list.
+ self.con.row_factory = sqlite.Row
+ row = self.con.execute("select 1, 2, 3, 4").fetchone()
+ self.assertEqual(row[0:0], ())
+ self.assertEqual(row[0:1], (1,))
+ self.assertEqual(row[1:3], (2, 3))
+ self.assertEqual(row[3:1], ())
+ # Explicit bounds are optional.
+ self.assertEqual(row[1:], (2, 3, 4))
+ self.assertEqual(row[:3], (1, 2, 3))
+ # Slices can use negative indices.
+ self.assertEqual(row[-2:-1], (3,))
+ self.assertEqual(row[-2:], (3, 4))
+ # Slicing supports steps.
+ self.assertEqual(row[0:4:2], (1, 3))
+ self.assertEqual(row[3:0:-2], (4, 2))
+
def CheckSqliteRowIter(self):
"""Checks if the row object is iterable"""
self.con.row_factory = sqlite.Row