mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-08-02 11:20:08 +03:00
Merge 3bdd1ed043
into 6becf0ef55
This commit is contained in:
commit
3c48c6ff87
|
@ -175,6 +175,9 @@ class DictRow(list):
|
|||
x = self._index[x]
|
||||
super(DictRow, self).__setitem__(x, v)
|
||||
|
||||
def __repr__(self):
|
||||
return repr(dict(self))
|
||||
|
||||
def items(self):
|
||||
g = super(DictRow, self).__getitem__
|
||||
return ((n, g(self._index[n])) for n in self._index)
|
||||
|
|
|
@ -215,6 +215,11 @@ class ExtrasDictCursorTests(_DictCursorBase):
|
|||
self.assertEqual(list(r1.itervalues()), list(r.itervalues()))
|
||||
self.assertEqual(list(r1.iteritems()), list(r.iteritems()))
|
||||
|
||||
def testDictCursorRepresentation(self):
|
||||
curs = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
|
||||
curs.execute("select 5 as foo, 4 as bar, 33 as baz, 2 as qux")
|
||||
r = curs.fetchone()
|
||||
self.assertEqual(repr(r), repr({'foo': 5, 'bar': 4, 'baz': 33, 'qux': 2}))
|
||||
|
||||
class ExtrasDictCursorRealTests(_DictCursorBase):
|
||||
def testDictCursorWithPlainCursorRealFetchOne(self):
|
||||
|
@ -354,6 +359,12 @@ class ExtrasDictCursorRealTests(_DictCursorBase):
|
|||
self.assertEqual(list(r1.itervalues()), list(r.itervalues()))
|
||||
self.assertEqual(list(r1.iteritems()), list(r.iteritems()))
|
||||
|
||||
def testRealDictCursorRepresentation(self):
|
||||
curs = self.conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
|
||||
curs.execute("select 5 as foo, 4 as bar, 33 as baz, 2 as qux")
|
||||
r = curs.fetchone()
|
||||
self.assertEqual(repr(r), repr({'foo': 5, 'bar': 4, 'baz': 33, 'qux': 2}))
|
||||
|
||||
|
||||
class NamedTupleCursorTest(ConnectingTestCase):
|
||||
def setUp(self):
|
||||
|
|
Loading…
Reference in New Issue
Block a user