Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2cfb1c6

Browse files
committed
PL/Python: Adjust the regression tests for Python 3.3
The string representation of ImportError changed. Remove printingthat; it's not necessary for the test.The order in which members of a dict are printed changed. But thiswas always implementation-dependent, so we have just been lucky for along time. Do the printing the hard way to ensure sorted order.
1 parent63fecc9 commit2cfb1c6

File tree

6 files changed

+38
-16
lines changed

6 files changed

+38
-16
lines changed

‎src/pl/plpython/expected/plpython_import.out

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ CREATE FUNCTION import_fail() returns text
33
AS
44
'try:
55
import foosocket
6-
except Exception, ex:
7-
plpy.notice("import socket failed -- %s" % str(ex))
6+
except ImportError:
87
return "failed as expected"
98
return "succeeded, that wasn''t supposed to happen"'
109
LANGUAGE plpythonu;
@@ -51,8 +50,6 @@ return "sha hash of " + plain + " is " + digest.hexdigest()'
5150
-- import python modules
5251
--
5352
SELECT import_fail();
54-
NOTICE: import socket failed -- No module named foosocket
55-
CONTEXT: PL/Python function "import_fail"
5653
import_fail
5754
--------------------
5855
failed as expected

‎src/pl/plpython/expected/plpython_params.out

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ return True
1111
$$ LANGUAGE plpythonu;
1212
CREATE FUNCTION test_param_names2(u users) RETURNS text AS $$
1313
assert u == args[0]
14-
return str(u)
14+
if isinstance(u, dict):
15+
# stringify dict the hard way because otherwise the order is implementation-dependent
16+
u_keys = list(u.keys())
17+
u_keys.sort()
18+
s = '{' + ', '.join([repr(k) + ': ' + repr(u[k]) for k in u_keys]) + '}'
19+
else:
20+
s = str(u)
21+
return s
1522
$$ LANGUAGE plpythonu;
1623
-- use deliberately wrong parameter names
1724
CREATE FUNCTION test_param_names3(a0 integer) RETURNS boolean AS $$
@@ -37,10 +44,10 @@ SELECT test_param_names1(1,'text');
3744
SELECT test_param_names2(users) from users;
3845
test_param_names2
3946
-----------------------------------------------------------------------
40-
{'lname': 'doe', 'username': 'j_doe', 'userid': 1, 'fname': 'jane'}
41-
{'lname': 'doe', 'username': 'johnd', 'userid': 2, 'fname': 'john'}
42-
{'lname': 'doe', 'username': 'w_doe', 'userid': 3, 'fname': 'willem'}
43-
{'lname': 'smith', 'username': 'slash', 'userid': 4, 'fname': 'rick'}
47+
{'fname': 'jane', 'lname': 'doe', 'userid': 1, 'username': 'j_doe'}
48+
{'fname': 'john', 'lname': 'doe', 'userid': 2, 'username': 'johnd'}
49+
{'fname': 'willem', 'lname': 'doe', 'userid': 3, 'username': 'w_doe'}
50+
{'fname': 'rick', 'lname': 'smith', 'userid': 4, 'username': 'slash'}
4451
(4 rows)
4552

4653
SELECT test_param_names2(NULL);

‎src/pl/plpython/expected/plpython_trigger.out

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,14 @@ if 'relid' in TD:
7575
skeys = list(TD.keys())
7676
skeys.sort()
7777
for key in skeys:
78-
val = TD[key]
79-
plpy.notice("TD[" + key + "] => " + str(val))
78+
val = TD[key]
79+
if not isinstance(val, dict):
80+
plpy.notice("TD[" + key + "] => " + str(val))
81+
else:
82+
# print dicts the hard way because otherwise the order is implementation-dependent
83+
valkeys = list(val.keys())
84+
valkeys.sort()
85+
plpy.notice("TD[" + key + "] => " + '{' + ', '.join([repr(k) + ': ' + repr(val[k]) for k in valkeys]) + '}')
8086

8187
return None
8288

‎src/pl/plpython/sql/plpython_import.sql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ CREATE FUNCTION import_fail() returns text
44
AS
55
'try:
66
import foosocket
7-
except Exception, ex:
8-
plpy.notice("import socket failed -- %s" % str(ex))
7+
except ImportError:
98
return "failed as expected"
109
return "succeeded, that wasn''t supposed to happen"'
1110
LANGUAGE plpythonu;

‎src/pl/plpython/sql/plpython_params.sql

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ $$ LANGUAGE plpythonu;
1414

1515
CREATEFUNCTIONtest_param_names2(u users) RETURNStextAS $$
1616
assert u== args[0]
17-
return str(u)
17+
if isinstance(u, dict):
18+
# stringify dict the hard way because otherwise the order is implementation-dependent
19+
u_keys= list(u.keys())
20+
u_keys.sort()
21+
s='{'+','.join([repr(k)+':'+ repr(u[k]) for kin u_keys])+'}'
22+
else:
23+
s= str(u)
24+
return s
1825
$$ LANGUAGE plpythonu;
1926

2027
-- use deliberately wrong parameter names

‎src/pl/plpython/sql/plpython_trigger.sql

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,14 @@ if 'relid' in TD:
7575
skeys= list(TD.keys())
7676
skeys.sort()
7777
for keyin skeys:
78-
val= TD[key]
79-
plpy.notice("TD["+ key+"] =>"+ str(val))
78+
val= TD[key]
79+
if not isinstance(val, dict):
80+
plpy.notice("TD["+ key+"] =>"+ str(val))
81+
else:
82+
# print dicts the hard way because otherwise the order is implementation-dependent
83+
valkeys= list(val.keys())
84+
valkeys.sort()
85+
plpy.notice("TD["+ key+"] =>"+'{'+','.join([repr(k)+':'+ repr(val[k]) for kin valkeys])+'}')
8086

8187
return None
8288

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp