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

Unified Diff: Lib/sqlite3/test/factory.py

Issue 10203: sqlite3.Row doesn't support sequence protocol
Patch Set: Created 5 years, 3 months ago
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Lib/sqlite3/dbapi2.py ('k') | Modules/_sqlite/row.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/sqlite3/test/factory.py Wed May 21 17:12:21 2014 +0300
+++ b/Lib/sqlite3/test/factory.py Tue May 27 10:47:37 2014 +0300
@@ -23,6 +23,7 @@
import unittest
import sqlite3 as sqlite
+from collections.abc import Sequence
class MyConnection(sqlite.Connection):
def __init__(self, *args, **kwargs):
@@ -142,6 +143,23 @@
self.assertNotEqual(row_1, row_3)
self.assertNotEqual(hash(row_1), hash(row_3))
+ def CheckSqliteRowAsSequence(self):
+ """ Checks if the row object can act like a sequence """
+ self.con.row_factory = sqlite.Row
+ row = self.con.execute("select 1 as a, 2 as b").fetchone()
+
+ as_tuple = tuple(row)
+ self.assertEqual(list(reversed(row)), list(reversed(as_tuple)))
+ self.assertEqual(row[-1], 2)
+ self.assertEqual(row[-2], 1)
+ with self.assertRaises(IndexError):
+ row[-3]
+ with self.assertRaisesRegex(IndexError,
+ "cannot fit 'int' into an "
+ "index-sized integer"):
+ row[2 ** 1000]
+ self.assertIsInstance(row, Sequence)
+
def tearDown(self):
self.con.close()
« no previous file with comments | « Lib/sqlite3/dbapi2.py ('k') | Modules/_sqlite/row.c » ('j') | no next file with comments »

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