diff options
author | Peter Eisentraut <peter_e@gmx.net> | 2012-05-11 23:01:15 +0300 |
---|---|---|
committer | Peter Eisentraut <peter_e@gmx.net> | 2012-05-11 23:04:47 +0300 |
commit | 2cfb1c6f77734db81b6e74bcae630f93b94f69be (patch) | |
tree | 57db3ab48931ffe5a906998f2418a1d9f5b3ab48 | |
parent | 63fecc91770f3d494b6fe993bdc198a9faf6fe2d (diff) | |
download | postgresql-2cfb1c6f77734db81b6e74bcae630f93b94f69be.tar.gz postgresql-2cfb1c6f77734db81b6e74bcae630f93b94f69be.zip |
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.
-rw-r--r-- | src/pl/plpython/expected/plpython_import.out | 5 | ||||
-rw-r--r-- | src/pl/plpython/expected/plpython_params.out | 17 | ||||
-rw-r--r-- | src/pl/plpython/expected/plpython_trigger.out | 10 | ||||
-rw-r--r-- | src/pl/plpython/sql/plpython_import.sql | 3 | ||||
-rw-r--r-- | src/pl/plpython/sql/plpython_params.sql | 9 | ||||
-rw-r--r-- | src/pl/plpython/sql/plpython_trigger.sql | 10 |
6 files changed, 38 insertions, 16 deletions
diff --git a/src/pl/plpython/expected/plpython_import.out b/src/pl/plpython/expected/plpython_import.out index b91ecc69619..1d981eacf12 100644 --- a/src/pl/plpython/expected/plpython_import.out +++ b/src/pl/plpython/expected/plpython_import.out @@ -3,8 +3,7 @@ CREATE FUNCTION import_fail() returns text AS 'try: import foosocket -except Exception, ex: - plpy.notice("import socket failed -- %s" % str(ex)) +except ImportError: return "failed as expected" return "succeeded, that wasn''t supposed to happen"' LANGUAGE plpythonu; @@ -51,8 +50,6 @@ return "sha hash of " + plain + " is " + digest.hexdigest()' -- import python modules -- SELECT import_fail(); -NOTICE: import socket failed -- No module named foosocket -CONTEXT: PL/Python function "import_fail" import_fail -------------------- failed as expected diff --git a/src/pl/plpython/expected/plpython_params.out b/src/pl/plpython/expected/plpython_params.out index 3ec3396dc68..8dc38025130 100644 --- a/src/pl/plpython/expected/plpython_params.out +++ b/src/pl/plpython/expected/plpython_params.out @@ -11,7 +11,14 @@ return True $$ LANGUAGE plpythonu; CREATE FUNCTION test_param_names2(u users) RETURNS text AS $$ 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; -- use deliberately wrong parameter names CREATE FUNCTION test_param_names3(a0 integer) RETURNS boolean AS $$ @@ -37,10 +44,10 @@ SELECT test_param_names1(1,'text'); SELECT test_param_names2(users) from users; test_param_names2 ----------------------------------------------------------------------- - {'lname': 'doe', 'username': 'j_doe', 'userid': 1, 'fname': 'jane'} - {'lname': 'doe', 'username': 'johnd', 'userid': 2, 'fname': 'john'} - {'lname': 'doe', 'username': 'w_doe', 'userid': 3, 'fname': 'willem'} - {'lname': 'smith', 'username': 'slash', 'userid': 4, 'fname': 'rick'} + {'fname': 'jane', 'lname': 'doe', 'userid': 1, 'username': 'j_doe'} + {'fname': 'john', 'lname': 'doe', 'userid': 2, 'username': 'johnd'} + {'fname': 'willem', 'lname': 'doe', 'userid': 3, 'username': 'w_doe'} + {'fname': 'rick', 'lname': 'smith', 'userid': 4, 'username': 'slash'} (4 rows) SELECT test_param_names2(NULL); diff --git a/src/pl/plpython/expected/plpython_trigger.out b/src/pl/plpython/expected/plpython_trigger.out index 58aa24b62cb..4c46b2b8f21 100644 --- a/src/pl/plpython/expected/plpython_trigger.out +++ b/src/pl/plpython/expected/plpython_trigger.out @@ -75,8 +75,14 @@ if 'relid' in TD: skeys = list(TD.keys()) skeys.sort() for key in skeys: - val = TD[key] - plpy.notice("TD[" + key + "] => " + str(val)) + val = TD[key] + 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 diff --git a/src/pl/plpython/sql/plpython_import.sql b/src/pl/plpython/sql/plpython_import.sql index 477af328d18..d4a4a24af4f 100644 --- a/src/pl/plpython/sql/plpython_import.sql +++ b/src/pl/plpython/sql/plpython_import.sql @@ -4,8 +4,7 @@ CREATE FUNCTION import_fail() returns text AS 'try: import foosocket -except Exception, ex: - plpy.notice("import socket failed -- %s" % str(ex)) +except ImportError: return "failed as expected" return "succeeded, that wasn''t supposed to happen"' LANGUAGE plpythonu; diff --git a/src/pl/plpython/sql/plpython_params.sql b/src/pl/plpython/sql/plpython_params.sql index d97e0b85490..f580abe53d0 100644 --- a/src/pl/plpython/sql/plpython_params.sql +++ b/src/pl/plpython/sql/plpython_params.sql @@ -14,7 +14,14 @@ $$ LANGUAGE plpythonu; CREATE FUNCTION test_param_names2(u users) RETURNS text AS $$ 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; -- use deliberately wrong parameter names diff --git a/src/pl/plpython/sql/plpython_trigger.sql b/src/pl/plpython/sql/plpython_trigger.sql index f60565cde6b..2a4859f2aa2 100644 --- a/src/pl/plpython/sql/plpython_trigger.sql +++ b/src/pl/plpython/sql/plpython_trigger.sql @@ -75,8 +75,14 @@ if 'relid' in TD: skeys = list(TD.keys()) skeys.sort() for key in skeys: - val = TD[key] - plpy.notice("TD[" + key + "] => " + str(val)) + val = TD[key] + 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 |