mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-08-03 03:40:09 +03:00
Change DictRow representation to match that of dict
This commit is contained in:
parent
6becf0ef55
commit
3bdd1ed043
|
@ -175,6 +175,9 @@ class DictRow(list):
|
||||||
x = self._index[x]
|
x = self._index[x]
|
||||||
super(DictRow, self).__setitem__(x, v)
|
super(DictRow, self).__setitem__(x, v)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return repr(dict(self))
|
||||||
|
|
||||||
def items(self):
|
def items(self):
|
||||||
g = super(DictRow, self).__getitem__
|
g = super(DictRow, self).__getitem__
|
||||||
return ((n, g(self._index[n])) for n in self._index)
|
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.itervalues()), list(r.itervalues()))
|
||||||
self.assertEqual(list(r1.iteritems()), list(r.iteritems()))
|
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):
|
class ExtrasDictCursorRealTests(_DictCursorBase):
|
||||||
def testDictCursorWithPlainCursorRealFetchOne(self):
|
def testDictCursorWithPlainCursorRealFetchOne(self):
|
||||||
|
@ -354,6 +359,12 @@ class ExtrasDictCursorRealTests(_DictCursorBase):
|
||||||
self.assertEqual(list(r1.itervalues()), list(r.itervalues()))
|
self.assertEqual(list(r1.itervalues()), list(r.itervalues()))
|
||||||
self.assertEqual(list(r1.iteritems()), list(r.iteritems()))
|
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):
|
class NamedTupleCursorTest(ConnectingTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user