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

Delta Between Two Patch Sets: Lib/sqlite3/test/factory.py

Issue 10203: sqlite3.Row doesn't support sequence protocol
Left Patch Set: Created 5 years, 9 months ago
Right Patch Set: Created 5 years, 3 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/sqlite3/dbapi2.py ('k') | Modules/_sqlite/row.c » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 self.con.row_factory = sqlite.Row 106 self.con.row_factory = sqlite.Row
107 row = self.con.execute("select 1 as a, 2 as b").fetchone() 107 row = self.con.execute("select 1 as a, 2 as b").fetchone()
108 for col in row: 108 for col in row:
109 pass 109 pass
110 110
111 def CheckSqliteRowAsTuple(self): 111 def CheckSqliteRowAsTuple(self):
112 """Checks if the row object can be converted to a tuple""" 112 """Checks if the row object can be converted to a tuple"""
113 self.con.row_factory = sqlite.Row 113 self.con.row_factory = sqlite.Row
114 row = self.con.execute("select 1 as a, 2 as b").fetchone() 114 row = self.con.execute("select 1 as a, 2 as b").fetchone()
115 t = tuple(row) 115 t = tuple(row)
116 self.assertEqual(t, (row['a'], row['b']))
116 117
117 def CheckSqliteRowAsDict(self): 118 def CheckSqliteRowAsDict(self):
118 """Checks if the row object can be correctly converted to a dictionary"" " 119 """Checks if the row object can be correctly converted to a dictionary"" "
119 self.con.row_factory = sqlite.Row 120 self.con.row_factory = sqlite.Row
120 row = self.con.execute("select 1 as a, 2 as b").fetchone() 121 row = self.con.execute("select 1 as a, 2 as b").fetchone()
121 d = dict(row) 122 d = dict(row)
122 self.assertEqual(d["a"], row["a"]) 123 self.assertEqual(d["a"], row["a"])
123 self.assertEqual(d["b"], row["b"]) 124 self.assertEqual(d["b"], row["b"])
124 125
125 def CheckSqliteRowHashCmp(self): 126 def CheckSqliteRowHashCmp(self):
(...skipping 16 matching lines...) Expand all
142 self.assertNotEqual(row_1, row_3) 143 self.assertNotEqual(row_1, row_3)
143 self.assertNotEqual(hash(row_1), hash(row_3)) 144 self.assertNotEqual(hash(row_1), hash(row_3))
144 145
145 def CheckSqliteRowAsSequence(self): 146 def CheckSqliteRowAsSequence(self):
146 """ Checks if the row object can act like a sequence """ 147 """ Checks if the row object can act like a sequence """
147 self.con.row_factory = sqlite.Row 148 self.con.row_factory = sqlite.Row
148 row = self.con.execute("select 1 as a, 2 as b").fetchone() 149 row = self.con.execute("select 1 as a, 2 as b").fetchone()
149 150
150 as_tuple = tuple(row) 151 as_tuple = tuple(row)
151 self.assertEqual(list(reversed(row)), list(reversed(as_tuple))) 152 self.assertEqual(list(reversed(row)), list(reversed(as_tuple)))
153 self.assertEqual(row[-1], 2)
154 self.assertEqual(row[-2], 1)
155 with self.assertRaises(IndexError):
156 row[-3]
157 with self.assertRaisesRegex(IndexError,
158 "cannot fit 'int' into an "
159 "index-sized integer"):
160 row[2 ** 1000]
152 self.assertIsInstance(row, Sequence) 161 self.assertIsInstance(row, Sequence)
153 162
154 def tearDown(self): 163 def tearDown(self):
155 self.con.close() 164 self.con.close()
156 165
157 class TextFactoryTests(unittest.TestCase): 166 class TextFactoryTests(unittest.TestCase):
158 def setUp(self): 167 def setUp(self):
159 self.con = sqlite.connect(":memory:") 168 self.con = sqlite.connect(":memory:")
160 169
161 def CheckUnicode(self): 170 def CheckUnicode(self):
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 text_suite = unittest.makeSuite(TextFactoryTests, "Check") 242 text_suite = unittest.makeSuite(TextFactoryTests, "Check")
234 text_zero_bytes_suite = unittest.makeSuite(TextFactoryTestsWithEmbeddedZeroB ytes, "Check") 243 text_zero_bytes_suite = unittest.makeSuite(TextFactoryTestsWithEmbeddedZeroB ytes, "Check")
235 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))
236 245
237 def test(): 246 def test():
238 runner = unittest.TextTestRunner() 247 runner = unittest.TextTestRunner()
239 runner.run(suite()) 248 runner.run(suite())
240 249
241 if __name__ == "__main__": 250 if __name__ == "__main__":
242 test() 251 test()
LEFTRIGHT

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