mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-28 20:03:43 +03:00
Fixed RealDictCursor.pop()
Addresses #886, but there might be something else broken there.
This commit is contained in:
parent
7b31b39fed
commit
21d16b6f67
1
NEWS
1
NEWS
|
@ -4,6 +4,7 @@ Current release
|
||||||
What's new in psycopg 2.8.1
|
What's new in psycopg 2.8.1
|
||||||
---------------------------
|
---------------------------
|
||||||
|
|
||||||
|
- Fixed `RealDictRow.pop()` (:ticket:`#886`).
|
||||||
- Fixed "there's no async cursor" error polling a connection with no cursor
|
- Fixed "there's no async cursor" error polling a connection with no cursor
|
||||||
(:ticket:`#887`).
|
(:ticket:`#887`).
|
||||||
|
|
||||||
|
|
|
@ -290,6 +290,13 @@ class RealDictRow(dict):
|
||||||
def items(self):
|
def items(self):
|
||||||
return ((k, self[k]) for k in self._column_mapping)
|
return ((k, self[k]) for k in self._column_mapping)
|
||||||
|
|
||||||
|
def pop(self, key, *args):
|
||||||
|
found = key in self
|
||||||
|
rv = super(RealDictRow, self).pop(key, *args)
|
||||||
|
if found:
|
||||||
|
self._column_mapping.remove(key)
|
||||||
|
return rv
|
||||||
|
|
||||||
if PY2:
|
if PY2:
|
||||||
iterkeys = keys
|
iterkeys = keys
|
||||||
itervalues = values
|
itervalues = values
|
||||||
|
|
|
@ -221,6 +221,12 @@ class ExtrasDictCursorTests(_DictCursorBase):
|
||||||
|
|
||||||
|
|
||||||
class ExtrasDictCursorRealTests(_DictCursorBase):
|
class ExtrasDictCursorRealTests(_DictCursorBase):
|
||||||
|
def testRealMeansReal(self):
|
||||||
|
curs = self.conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
|
||||||
|
curs.execute("SELECT * FROM ExtrasDictCursorTests")
|
||||||
|
row = curs.fetchone()
|
||||||
|
self.assert_(isinstance(row, dict))
|
||||||
|
|
||||||
def testDictCursorWithPlainCursorRealFetchOne(self):
|
def testDictCursorWithPlainCursorRealFetchOne(self):
|
||||||
self._testWithPlainCursorReal(lambda curs: curs.fetchone())
|
self._testWithPlainCursorReal(lambda curs: curs.fetchone())
|
||||||
|
|
||||||
|
@ -358,6 +364,19 @@ 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 test_pop(self):
|
||||||
|
curs = self.conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
|
||||||
|
curs.execute("select 1 as a, 2 as b, 3 as c")
|
||||||
|
r = curs.fetchone()
|
||||||
|
self.assertEqual(r.pop('b'), 2)
|
||||||
|
self.assertEqual(list(r), ['a', 'c'])
|
||||||
|
self.assertEqual(list(r.keys()), ['a', 'c'])
|
||||||
|
self.assertEqual(list(r.values()), [1, 3])
|
||||||
|
self.assertEqual(list(r.items()), [('a', 1), ('c', 3)])
|
||||||
|
|
||||||
|
self.assertEqual(r.pop('b', None), None)
|
||||||
|
self.assertRaises(KeyError, r.pop, 'b')
|
||||||
|
|
||||||
|
|
||||||
class NamedTupleCursorTest(ConnectingTestCase):
|
class NamedTupleCursorTest(ConnectingTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user