Commit 2cfb1c6f authored by Peter Eisentraut's avatar Peter Eisentraut

PL/Python: Adjust the regression tests for Python 3.3

The string representation of ImportError changed.  Remove printing
that; it's not necessary for the test.

The order in which members of a dict are printed changed.  But this
was always implementation-dependent, so we have just been lucky for a
long time.  Do the printing the hard way to ensure sorted order.
parent 63fecc91
...@@ -3,8 +3,7 @@ CREATE FUNCTION import_fail() returns text ...@@ -3,8 +3,7 @@ CREATE FUNCTION import_fail() returns text
AS AS
'try: 'try:
import foosocket import foosocket
except Exception, ex: except ImportError:
plpy.notice("import socket failed -- %s" % str(ex))
return "failed as expected" return "failed as expected"
return "succeeded, that wasn''t supposed to happen"' return "succeeded, that wasn''t supposed to happen"'
LANGUAGE plpythonu; LANGUAGE plpythonu;
...@@ -51,8 +50,6 @@ return "sha hash of " + plain + " is " + digest.hexdigest()' ...@@ -51,8 +50,6 @@ return "sha hash of " + plain + " is " + digest.hexdigest()'
-- import python modules -- import python modules
-- --
SELECT import_fail(); SELECT import_fail();
NOTICE: import socket failed -- No module named foosocket
CONTEXT: PL/Python function "import_fail"
import_fail import_fail
-------------------- --------------------
failed as expected failed as expected
......
...@@ -11,7 +11,14 @@ return True ...@@ -11,7 +11,14 @@ return True
$$ LANGUAGE plpythonu; $$ LANGUAGE plpythonu;
CREATE FUNCTION test_param_names2(u users) RETURNS text AS $$ CREATE FUNCTION test_param_names2(u users) RETURNS text AS $$
assert u == args[0] assert u == args[0]
return str(u) if isinstance(u, dict):
# stringify dict the hard way because otherwise the order is implementation-dependent
u_keys = list(u.keys())
u_keys.sort()
s = '{' + ', '.join([repr(k) + ': ' + repr(u[k]) for k in u_keys]) + '}'
else:
s = str(u)
return s
$$ LANGUAGE plpythonu; $$ LANGUAGE plpythonu;
-- use deliberately wrong parameter names -- use deliberately wrong parameter names
CREATE FUNCTION test_param_names3(a0 integer) RETURNS boolean AS $$ CREATE FUNCTION test_param_names3(a0 integer) RETURNS boolean AS $$
...@@ -37,10 +44,10 @@ SELECT test_param_names1(1,'text'); ...@@ -37,10 +44,10 @@ SELECT test_param_names1(1,'text');
SELECT test_param_names2(users) from users; SELECT test_param_names2(users) from users;
test_param_names2 test_param_names2
----------------------------------------------------------------------- -----------------------------------------------------------------------
{'lname': 'doe', 'username': 'j_doe', 'userid': 1, 'fname': 'jane'} {'fname': 'jane', 'lname': 'doe', 'userid': 1, 'username': 'j_doe'}
{'lname': 'doe', 'username': 'johnd', 'userid': 2, 'fname': 'john'} {'fname': 'john', 'lname': 'doe', 'userid': 2, 'username': 'johnd'}
{'lname': 'doe', 'username': 'w_doe', 'userid': 3, 'fname': 'willem'} {'fname': 'willem', 'lname': 'doe', 'userid': 3, 'username': 'w_doe'}
{'lname': 'smith', 'username': 'slash', 'userid': 4, 'fname': 'rick'} {'fname': 'rick', 'lname': 'smith', 'userid': 4, 'username': 'slash'}
(4 rows) (4 rows)
SELECT test_param_names2(NULL); SELECT test_param_names2(NULL);
......
...@@ -75,8 +75,14 @@ if 'relid' in TD: ...@@ -75,8 +75,14 @@ if 'relid' in TD:
skeys = list(TD.keys()) skeys = list(TD.keys())
skeys.sort() skeys.sort()
for key in skeys: for key in skeys:
val = TD[key] val = TD[key]
plpy.notice("TD[" + key + "] => " + str(val)) if not isinstance(val, dict):
plpy.notice("TD[" + key + "] => " + str(val))
else:
# print dicts the hard way because otherwise the order is implementation-dependent
valkeys = list(val.keys())
valkeys.sort()
plpy.notice("TD[" + key + "] => " + '{' + ', '.join([repr(k) + ': ' + repr(val[k]) for k in valkeys]) + '}')
return None return None
......
...@@ -4,8 +4,7 @@ CREATE FUNCTION import_fail() returns text ...@@ -4,8 +4,7 @@ CREATE FUNCTION import_fail() returns text
AS AS
'try: 'try:
import foosocket import foosocket
except Exception, ex: except ImportError:
plpy.notice("import socket failed -- %s" % str(ex))
return "failed as expected" return "failed as expected"
return "succeeded, that wasn''t supposed to happen"' return "succeeded, that wasn''t supposed to happen"'
LANGUAGE plpythonu; LANGUAGE plpythonu;
......
...@@ -14,7 +14,14 @@ $$ LANGUAGE plpythonu; ...@@ -14,7 +14,14 @@ $$ LANGUAGE plpythonu;
CREATE FUNCTION test_param_names2(u users) RETURNS text AS $$ CREATE FUNCTION test_param_names2(u users) RETURNS text AS $$
assert u == args[0] assert u == args[0]
return str(u) if isinstance(u, dict):
# stringify dict the hard way because otherwise the order is implementation-dependent
u_keys = list(u.keys())
u_keys.sort()
s = '{' + ', '.join([repr(k) + ': ' + repr(u[k]) for k in u_keys]) + '}'
else:
s = str(u)
return s
$$ LANGUAGE plpythonu; $$ LANGUAGE plpythonu;
-- use deliberately wrong parameter names -- use deliberately wrong parameter names
......
...@@ -75,8 +75,14 @@ if 'relid' in TD: ...@@ -75,8 +75,14 @@ if 'relid' in TD:
skeys = list(TD.keys()) skeys = list(TD.keys())
skeys.sort() skeys.sort()
for key in skeys: for key in skeys:
val = TD[key] val = TD[key]
plpy.notice("TD[" + key + "] => " + str(val)) if not isinstance(val, dict):
plpy.notice("TD[" + key + "] => " + str(val))
else:
# print dicts the hard way because otherwise the order is implementation-dependent
valkeys = list(val.keys())
valkeys.sort()
plpy.notice("TD[" + key + "] => " + '{' + ', '.join([repr(k) + ': ' + repr(val[k]) for k in valkeys]) + '}')
return None return None
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment