mirror of
https://github.com/postgres/postgres.git
synced 2025-06-14 18:42:34 +03:00
Simplify some SPI tests of PL/Python
These tests relied on both next() and __next__(), but only the former is needed since Python 2 support has been removed, so let's simplify a bit the tests. Author: Erik Wienhold Discussion: https://postgr.es/m/173209043143.2092749.13692266486972491694@wrigleys.postgresql.org
This commit is contained in:
@ -319,12 +319,9 @@ assert len(res.fetch(3)) == 1
|
|||||||
assert len(res.fetch(3)) == 0
|
assert len(res.fetch(3)) == 0
|
||||||
assert len(res.fetch(3)) == 0
|
assert len(res.fetch(3)) == 0
|
||||||
try:
|
try:
|
||||||
# use next() or __next__(), the method name changed in
|
# use next() and not __next__(), the method name changed in
|
||||||
# http://www.python.org/dev/peps/pep-3114/
|
# http://www.python.org/dev/peps/pep-3114/
|
||||||
try:
|
next(res)
|
||||||
res.next()
|
|
||||||
except AttributeError:
|
|
||||||
res.__next__()
|
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
@ -334,11 +331,7 @@ CREATE FUNCTION cursor_mix_next_and_fetch() RETURNS int AS $$
|
|||||||
res = plpy.cursor("select fname, lname from users order by fname")
|
res = plpy.cursor("select fname, lname from users order by fname")
|
||||||
assert len(res.fetch(2)) == 2
|
assert len(res.fetch(2)) == 2
|
||||||
|
|
||||||
item = None
|
item = next(res)
|
||||||
try:
|
|
||||||
item = res.next()
|
|
||||||
except AttributeError:
|
|
||||||
item = res.__next__()
|
|
||||||
assert item['fname'] == 'rick'
|
assert item['fname'] == 'rick'
|
||||||
|
|
||||||
assert len(res.fetch(2)) == 1
|
assert len(res.fetch(2)) == 1
|
||||||
@ -357,10 +350,7 @@ CREATE FUNCTION next_after_close() RETURNS int AS $$
|
|||||||
res = plpy.cursor("select fname, lname from users")
|
res = plpy.cursor("select fname, lname from users")
|
||||||
res.close()
|
res.close()
|
||||||
try:
|
try:
|
||||||
try:
|
next(res)
|
||||||
res.next()
|
|
||||||
except AttributeError:
|
|
||||||
res.__next__()
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
@ -370,10 +360,7 @@ CREATE FUNCTION cursor_fetch_next_empty() RETURNS int AS $$
|
|||||||
res = plpy.cursor("select fname, lname from users where false")
|
res = plpy.cursor("select fname, lname from users where false")
|
||||||
assert len(res.fetch(1)) == 0
|
assert len(res.fetch(1)) == 0
|
||||||
try:
|
try:
|
||||||
try:
|
next(res)
|
||||||
res.next()
|
|
||||||
except AttributeError:
|
|
||||||
res.__next__()
|
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
@ -218,12 +218,9 @@ assert len(res.fetch(3)) == 1
|
|||||||
assert len(res.fetch(3)) == 0
|
assert len(res.fetch(3)) == 0
|
||||||
assert len(res.fetch(3)) == 0
|
assert len(res.fetch(3)) == 0
|
||||||
try:
|
try:
|
||||||
# use next() or __next__(), the method name changed in
|
# use next() and not __next__(), the method name changed in
|
||||||
# http://www.python.org/dev/peps/pep-3114/
|
# http://www.python.org/dev/peps/pep-3114/
|
||||||
try:
|
next(res)
|
||||||
res.next()
|
|
||||||
except AttributeError:
|
|
||||||
res.__next__()
|
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
@ -234,11 +231,7 @@ CREATE FUNCTION cursor_mix_next_and_fetch() RETURNS int AS $$
|
|||||||
res = plpy.cursor("select fname, lname from users order by fname")
|
res = plpy.cursor("select fname, lname from users order by fname")
|
||||||
assert len(res.fetch(2)) == 2
|
assert len(res.fetch(2)) == 2
|
||||||
|
|
||||||
item = None
|
item = next(res)
|
||||||
try:
|
|
||||||
item = res.next()
|
|
||||||
except AttributeError:
|
|
||||||
item = res.__next__()
|
|
||||||
assert item['fname'] == 'rick'
|
assert item['fname'] == 'rick'
|
||||||
|
|
||||||
assert len(res.fetch(2)) == 1
|
assert len(res.fetch(2)) == 1
|
||||||
@ -259,10 +252,7 @@ CREATE FUNCTION next_after_close() RETURNS int AS $$
|
|||||||
res = plpy.cursor("select fname, lname from users")
|
res = plpy.cursor("select fname, lname from users")
|
||||||
res.close()
|
res.close()
|
||||||
try:
|
try:
|
||||||
try:
|
next(res)
|
||||||
res.next()
|
|
||||||
except AttributeError:
|
|
||||||
res.__next__()
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
@ -273,10 +263,7 @@ CREATE FUNCTION cursor_fetch_next_empty() RETURNS int AS $$
|
|||||||
res = plpy.cursor("select fname, lname from users where false")
|
res = plpy.cursor("select fname, lname from users where false")
|
||||||
assert len(res.fetch(1)) == 0
|
assert len(res.fetch(1)) == 0
|
||||||
try:
|
try:
|
||||||
try:
|
next(res)
|
||||||
res.next()
|
|
||||||
except AttributeError:
|
|
||||||
res.__next__()
|
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
Reference in New Issue
Block a user