Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(7)

Side by Side Diff: Lib/sqlite3/test/factory.py

Issue 13583: sqlite3.Row doesn't support slice indexes
Patch Set: Created 4 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Modules/_sqlite/row.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #-*- coding: iso-8859-1 -*- 1 #-*- coding: iso-8859-1 -*-
2 # pysqlite2/test/factory.py: tests for the various factories in pysqlite 2 # pysqlite2/test/factory.py: tests for the various factories in pysqlite
3 # 3 #
4 # Copyright (C) 2005-2007 Gerhard Häring <gh@ghaering.de> 4 # Copyright (C) 2005-2007 Gerhard Häring <gh@ghaering.de>
5 # 5 #
6 # This file is part of pysqlite. 6 # This file is part of pysqlite.
7 # 7 #
8 # This software is provided 'as-is', without any express or implied 8 # This software is provided 'as-is', without any express or implied
9 # warranty. In no event will the authors be held liable for any damages 9 # warranty. In no event will the authors be held liable for any damages
10 # arising from the use of this software. 10 # arising from the use of this software.
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 self.assertEqual(row[-2], 1, "by index: wrong result for column -2") 103 self.assertEqual(row[-2], 1, "by index: wrong result for column -2")
104 104
105 with self.assertRaises(IndexError): 105 with self.assertRaises(IndexError):
106 row['c'] 106 row['c']
107 with self.assertRaises(IndexError): 107 with self.assertRaises(IndexError):
108 row[2] 108 row[2]
109 with self.assertRaises(IndexError): 109 with self.assertRaises(IndexError):
110 row[-3] 110 row[-3]
111 with self.assertRaises(IndexError): 111 with self.assertRaises(IndexError):
112 row[2**1000] 112 row[2**1000]
113
114 def CheckSqliteRowSlice(self):
115 # A sqlite.Row can be sliced like a list.
116 self.con.row_factory = sqlite.Row
117 row = self.con.execute("select 1, 2, 3, 4").fetchone()
118 self.assertEqual(row[0:0], ())
119 self.assertEqual(row[0:1], (1,))
120 self.assertEqual(row[1:3], (2, 3))
121 self.assertEqual(row[3:1], ())
122 # Explicit bounds are optional.
123 self.assertEqual(row[1:], (2, 3, 4))
124 self.assertEqual(row[:3], (1, 2, 3))
125 # Slices can use negative indices.
126 self.assertEqual(row[-2:-1], (3,))
127 self.assertEqual(row[-2:], (3, 4))
128 # Slicing supports steps.
129 self.assertEqual(row[0:4:2], (1, 3))
130 self.assertEqual(row[3:0:-2], (4, 2))
113 131
114 def CheckSqliteRowIter(self): 132 def CheckSqliteRowIter(self):
115 """Checks if the row object is iterable""" 133 """Checks if the row object is iterable"""
116 self.con.row_factory = sqlite.Row 134 self.con.row_factory = sqlite.Row
117 row = self.con.execute("select 1 as a, 2 as b").fetchone() 135 row = self.con.execute("select 1 as a, 2 as b").fetchone()
118 for col in row: 136 for col in row:
119 pass 137 pass
120 138
121 def CheckSqliteRowAsTuple(self): 139 def CheckSqliteRowAsTuple(self):
122 """Checks if the row object can be converted to a tuple""" 140 """Checks if the row object can be converted to a tuple"""
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 text_suite = unittest.makeSuite(TextFactoryTests, "Check") 262 text_suite = unittest.makeSuite(TextFactoryTests, "Check")
245 text_zero_bytes_suite = unittest.makeSuite(TextFactoryTestsWithEmbeddedZeroB ytes, "Check") 263 text_zero_bytes_suite = unittest.makeSuite(TextFactoryTestsWithEmbeddedZeroB ytes, "Check")
246 return unittest.TestSuite((connection_suite, cursor_suite, row_suite_compat, row_suite, text_suite, text_zero_bytes_suite)) 264 return unittest.TestSuite((connection_suite, cursor_suite, row_suite_compat, row_suite, text_suite, text_zero_bytes_suite))
247 265
248 def test(): 266 def test():
249 runner = unittest.TextTestRunner() 267 runner = unittest.TextTestRunner()
250 runner.run(suite()) 268 runner.run(suite())
251 269
252 if __name__ == "__main__": 270 if __name__ == "__main__":
253 test() 271 test()
OLDNEW
« no previous file with comments | « no previous file | Modules/_sqlite/row.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+