From 339416b821ed543f289fccff8f6fc9c44dbc9d23 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 15 Sep 2017 11:14:36 -0400 Subject: Add __next__(), next() to ResultProxy Added ``__next__()`` and ``next()`` methods to :class:`.ResultProxy`, so that the ``next()`` builtin function works on the object directly. :class:`.ResultProxy` has long had an ``__iter__()`` method which already allows it to respond to the ``iter()`` builtin. The implementation for ``__iter__()`` is unchanged, as performance testing has indicated that iteration using a ``__next__()`` method with ``StopIteration`` is about 20% slower in both Python 2.7 and 3.6. Change-Id: I70569a4c48ad85a3c21a7ad422f270a559926cfb Fixes: #4077 --- test/sql/test_resultset.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/sql/test_resultset.py') diff --git a/test/sql/test_resultset.py b/test/sql/test_resultset.py index 41092efe9..5c7108ca0 100644 --- a/test/sql/test_resultset.py +++ b/test/sql/test_resultset.py @@ -61,6 +61,23 @@ class ResultProxyTest(fixtures.TablesTest): rows.append(row) eq_(len(rows), 3) + def test_row_next(self): + users = self.tables.users + + users.insert().execute( + {'user_id': 7, 'user_name': 'jack'}, + {'user_id': 8, 'user_name': 'ed'}, + {'user_id': 9, 'user_name': 'fred'}, + ) + r = users.select().execute() + rows = [] + while True: + row = next(r, 'foo') + if row == 'foo': + break + rows.append(row) + eq_(len(rows), 3) + @testing.requires.subqueries def test_anonymous_rows(self): users = self.tables.users -- cgit v1.2.1