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

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

Issue 13583: sqlite3.Row doesn't support slice indexes
Patch Set: Created 5 years, 11 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') | Modules/_sqlite/row.c » ('J')
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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 self.assertEqual(col1, 1, "by name: wrong result for column 'a'") 92 self.assertEqual(col1, 1, "by name: wrong result for column 'a'")
93 self.assertEqual(col2, 2, "by name: wrong result for column 'a'") 93 self.assertEqual(col2, 2, "by name: wrong result for column 'a'")
94 94
95 col1, col2 = row["A"], row["B"] 95 col1, col2 = row["A"], row["B"]
96 self.assertEqual(col1, 1, "by name: wrong result for column 'A'") 96 self.assertEqual(col1, 1, "by name: wrong result for column 'A'")
97 self.assertEqual(col2, 2, "by name: wrong result for column 'B'") 97 self.assertEqual(col2, 2, "by name: wrong result for column 'B'")
98 98
99 col1, col2 = row[0], row[1] 99 col1, col2 = row[0], row[1]
100 self.assertEqual(col1, 1, "by index: wrong result for column 0") 100 self.assertEqual(col1, 1, "by index: wrong result for column 0")
101 self.assertEqual(col2, 2, "by index: wrong result for column 1") 101 self.assertEqual(col2, 2, "by index: wrong result for column 1")
102
103 def CheckSqliteRowSlice(self):
104 # A sqlite.Row can be sliced like a list.
105 self.con.row_factory = sqlite.Row
106 row = self.con.execute("select 1, 2, 3, 4").fetchone()
107 self.assertEqual(row[0:0], ())
108 self.assertEqual(row[0:1], (1,))
109 self.assertEqual(row[1:3], (2, 3))
110 self.assertEqual(row[3:1], ())
111 # Explicit bounds are optional.
112 self.assertEqual(row[1:], (2, 3, 4))
113 self.assertEqual(row[:3], (1, 2, 3))
114 # Slices can use negative indices.
115 self.assertEqual(row[-2:-1], (3,))
116 self.assertEqual(row[-2:], (3, 4))
117 # Slicing supports steps.
118 self.assertEqual(row[0:4:2], (1, 3))
119 self.assertEqual(row[3:0:-2], (4, 2))
102 120
103 def CheckSqliteRowIter(self): 121 def CheckSqliteRowIter(self):
104 """Checks if the row object is iterable""" 122 """Checks if the row object is iterable"""
105 self.con.row_factory = sqlite.Row 123 self.con.row_factory = sqlite.Row
106 row = self.con.execute("select 1 as a, 2 as b").fetchone() 124 row = self.con.execute("select 1 as a, 2 as b").fetchone()
107 for col in row: 125 for col in row:
108 pass 126 pass
109 127
110 def CheckSqliteRowAsTuple(self): 128 def CheckSqliteRowAsTuple(self):
111 """Checks if the row object can be converted to a tuple""" 129 """Checks if the row object can be converted to a tuple"""
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 text_suite = unittest.makeSuite(TextFactoryTests, "Check") 242 text_suite = unittest.makeSuite(TextFactoryTests, "Check")
225 text_zero_bytes_suite = unittest.makeSuite(TextFactoryTestsWithEmbeddedZeroB ytes, "Check") 243 text_zero_bytes_suite = unittest.makeSuite(TextFactoryTestsWithEmbeddedZeroB ytes, "Check")
226 return unittest.TestSuite((connection_suite, cursor_suite, row_suite_compat, row_suite, text_suite, text_zero_bytes_suite)) 244 return unittest.TestSuite((connection_suite, cursor_suite, row_suite_compat, row_suite, text_suite, text_zero_bytes_suite))
227 245
228 def test(): 246 def test():
229 runner = unittest.TextTestRunner() 247 runner = unittest.TextTestRunner()
230 runner.run(suite()) 248 runner.run(suite())
231 249
232 if __name__ == "__main__": 250 if __name__ == "__main__":
233 test() 251 test()
OLDNEW
« no previous file with comments | « no previous file | Modules/_sqlite/row.c » ('j') | Modules/_sqlite/row.c » ('J')

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