summaryrefslogtreecommitdiff
path: root/test/engine
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2015-03-17 12:32:33 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2015-03-17 12:32:33 -0400
commitb7e151ac5cf5a0c13b9a30bc6841ed0cfe322536 (patch)
tree039e129fb13d3fbafd2dcc718c15a5a2ea85a49f /test/engine
parent2cadd768aa48d1180e24600cf133586a343ea10b (diff)
downloadsqlalchemy-b7e151ac5cf5a0c13b9a30bc6841ed0cfe322536.tar.gz
- The "auto close" for :class:`.ResultProxy` is now a "soft" close.
That is, after exhausing all rows using the fetch methods, the DBAPI cursor is released as before and the object may be safely discarded, but the fetch methods may continue to be called for which they will return an end-of-result object (None for fetchone, empty list for fetchmany and fetchall). Only if :meth:`.ResultProxy.close` is called explicitly will these methods raise the "result is closed" error. fixes #3330 fixes #3329
Diffstat (limited to 'test/engine')
-rw-r--r--test/engine/test_execute.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/test/engine/test_execute.py b/test/engine/test_execute.py
index 730ef4446..b0256d325 100644
--- a/test/engine/test_execute.py
+++ b/test/engine/test_execute.py
@@ -1070,6 +1070,47 @@ class AlternateResultProxyTest(fixtures.TestBase):
rows = r.fetchmany(6)
eq_(rows, [(i, "t_%d" % i) for i in range(1, 6)])
+ # result keeps going just fine with blank results...
+ eq_(r.fetchmany(2), [])
+
+ eq_(r.fetchmany(2), [])
+
+ eq_(r.fetchall(), [])
+
+ eq_(r.fetchone(), None)
+
+ # until we close
+ r.close()
+
+ self._assert_result_closed(r)
+
+ r = self.engine.execute(select([self.table]).limit(5))
+ eq_(r.first(), (1, "t_1"))
+ self._assert_result_closed(r)
+
+ r = self.engine.execute(select([self.table]).limit(5))
+ eq_(r.scalar(), 1)
+ self._assert_result_closed(r)
+
+ def _assert_result_closed(self, r):
+ assert_raises_message(
+ tsa.exc.ResourceClosedError,
+ "object is closed",
+ r.fetchone
+ )
+
+ assert_raises_message(
+ tsa.exc.ResourceClosedError,
+ "object is closed",
+ r.fetchmany, 2
+ )
+
+ assert_raises_message(
+ tsa.exc.ResourceClosedError,
+ "object is closed",
+ r.fetchall
+ )
+
def test_plain(self):
self._test_proxy(_result.ResultProxy)