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

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

Issue 13583: sqlite3.Row doesn't support slice indexes
Patch Set: Created 8 years, 2 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 self.assertTrue(col1 == 1, "by name: wrong result for column 'a'") 102 self.assertTrue(col1 == 1, "by name: wrong result for column 'a'")
103 self.assertTrue(col2 == 2, "by name: wrong result for column 'a'") 103 self.assertTrue(col2 == 2, "by name: wrong result for column 'a'")
104 104
105 col1, col2 = row["A"], row["B"] 105 col1, col2 = row["A"], row["B"]
106 self.assertTrue(col1 == 1, "by name: wrong result for column 'A'") 106 self.assertTrue(col1 == 1, "by name: wrong result for column 'A'")
107 self.assertTrue(col2 == 2, "by name: wrong result for column 'B'") 107 self.assertTrue(col2 == 2, "by name: wrong result for column 'B'")
108 108
109 col1, col2 = row[0], row[1] 109 col1, col2 = row[0], row[1]
110 self.assertTrue(col1 == 1, "by index: wrong result for column 0") 110 self.assertTrue(col1 == 1, "by index: wrong result for column 0")
111 self.assertTrue(col2 == 2, "by index: wrong result for column 1") 111 self.assertTrue(col2 == 2, "by index: wrong result for column 1")
112
113 def CheckSqliteRowSlice(self):
114 self.con.row_factory = sqlite.Row
115 row = self.con.execute("select 1, 2, 3, 4").fetchone()
116 self.assertTrue(row[0:0] == (), "by slice: wrong result for [0:0] ")
117 self.assertTrue(row[0:1] == (1,), "by slice: wrong result for [0:1] ")
118 self.assertTrue(row[1:3] == (2,3), "by slice: wrong result for [1:3] ")
119 self.assertTrue(row[1:] == (2,3,4), "by slice: wrong result for [1:]" )
120 self.assertTrue(row[:3] == (1,2,3), "by slice: wrong result for [:3]" )
121 self.assertTrue(row[-2:-1] == (3,), "by slice: wrong result for [-2:- 1]")
122 self.assertTrue(row[-2:] == (3,4), "by slice: wrong result for [-2:] ")
112 123
113 def CheckSqliteRowIter(self): 124 def CheckSqliteRowIter(self):
114 """Checks if the row object is iterable""" 125 """Checks if the row object is iterable"""
115 self.con.row_factory = sqlite.Row 126 self.con.row_factory = sqlite.Row
116 row = self.con.execute("select 1 as a, 2 as b").fetchone() 127 row = self.con.execute("select 1 as a, 2 as b").fetchone()
117 for col in row: 128 for col in row:
118 pass 129 pass
119 130
120 def CheckSqliteRowAsTuple(self): 131 def CheckSqliteRowAsTuple(self):
121 """Checks if the row object can be converted to a tuple""" 132 """Checks if the row object can be converted to a tuple"""
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 row_suite = unittest.makeSuite(RowFactoryTests, "Check") 207 row_suite = unittest.makeSuite(RowFactoryTests, "Check")
197 text_suite = unittest.makeSuite(TextFactoryTests, "Check") 208 text_suite = unittest.makeSuite(TextFactoryTests, "Check")
198 return unittest.TestSuite((connection_suite, cursor_suite, row_suite_compat, row_suite, text_suite)) 209 return unittest.TestSuite((connection_suite, cursor_suite, row_suite_compat, row_suite, text_suite))
199 210
200 def test(): 211 def test():
201 runner = unittest.TextTestRunner() 212 runner = unittest.TextTestRunner()
202 runner.run(suite()) 213 runner.run(suite())
203 214
204 if __name__ == "__main__": 215 if __name__ == "__main__":
205 test() 216 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+