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

Commit9d98486

Browse files
committed
Split the plpython regression test into test cases arranged by topic, instead
of the previous monolithic setup-create-run sequence, that was apparentlyinherited from a previous test infrastructure, but makes working with thetests and adding new ones weird.
1 parentef7574e commit9d98486

34 files changed

+1927
-1800
lines changed

‎src/pl/plpython/Makefile

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $PostgreSQL: pgsql/src/pl/plpython/Makefile,v 1.32 2009/01/15 13:49:56 petere Exp $
1+
# $PostgreSQL: pgsql/src/pl/plpython/Makefile,v 1.33 2009/08/12 16:37:25 petere Exp $
22

33
subdir = src/pl/plpython
44
top_builddir = ../../..
@@ -57,7 +57,22 @@ endif
5757
SHLIB_LINK =$(python_libspec)$(python_additional_libs)$(filter -lintl,$(LIBS))
5858

5959
REGRESS_OPTS = --dbname=$(PL_TESTDB) --load-language=plpythonu
60-
REGRESS = plpython_schema plpython_populate plpython_function plpython_test plpython_error plpython_drop
60+
REGRESS =\
61+
plpython_schema\
62+
plpython_populate\
63+
plpython_test\
64+
plpython_global\
65+
plpython_import\
66+
plpython_spi\
67+
plpython_newline\
68+
plpython_void\
69+
plpython_params\
70+
plpython_setof\
71+
plpython_record\
72+
plpython_trigger\
73+
plpython_error\
74+
plpython_unicode\
75+
plpython_drop
6176
# where to find psql for running the tests
6277
PSQLDIR =$(bindir)
6378

‎src/pl/plpython/expected/README

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Guide to alternative expected files:
2+
3+
plpython_error_2.outPython 2.2, 2.3, 2.4
4+
plpython_error.outPython 2.5, 2.6
5+
6+
plpython_unicode_2.outPython 2.2
7+
plpython_unicode_3.outPython 2.3, 2.4
8+
plpython_unicode.outPython 2.5, 2.6

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

Lines changed: 103 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,124 @@
11
-- test error handling, i forgot to restore Warn_restart in
22
-- the trigger handler once. the errors and subsequent core dump were
33
-- interesting.
4+
/* Flat out syntax error
5+
*/
6+
CREATE FUNCTION sql_syntax_error() RETURNS text
7+
AS
8+
'plpy.execute("syntax error")'
9+
LANGUAGE plpythonu;
10+
SELECT sql_syntax_error();
11+
WARNING: PL/Python: <class 'plpy.SPIError'>: unrecognized error in PLy_spi_execute_query
12+
CONTEXT: PL/Python function "sql_syntax_error"
13+
ERROR: syntax error at or near "syntax"
14+
LINE 1: syntax error
15+
^
16+
QUERY: syntax error
17+
CONTEXT: PL/Python function "sql_syntax_error"
18+
/* check the handling of uncaught python exceptions
19+
*/
20+
CREATE FUNCTION exception_index_invalid(text) RETURNS text
21+
AS
22+
'return args[1]'
23+
LANGUAGE plpythonu;
24+
SELECT exception_index_invalid('test');
25+
ERROR: PL/Python: PL/Python function "exception_index_invalid" failed
26+
DETAIL: <type 'exceptions.IndexError'>: list index out of range
27+
CONTEXT: PL/Python function "exception_index_invalid"
28+
/* check handling of nested exceptions
29+
*/
30+
CREATE FUNCTION exception_index_invalid_nested() RETURNS text
31+
AS
32+
'rv = plpy.execute("SELECT test5(''foo'')")
33+
return rv[0]'
34+
LANGUAGE plpythonu;
35+
SELECT exception_index_invalid_nested();
36+
WARNING: PL/Python: <class 'plpy.SPIError'>: unrecognized error in PLy_spi_execute_query
37+
CONTEXT: PL/Python function "exception_index_invalid_nested"
38+
ERROR: function test5(unknown) does not exist
39+
LINE 1: SELECT test5('foo')
40+
^
41+
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
42+
QUERY: SELECT test5('foo')
43+
CONTEXT: PL/Python function "exception_index_invalid_nested"
44+
/* a typo
45+
*/
46+
CREATE FUNCTION invalid_type_uncaught(a text) RETURNS text
47+
AS
48+
'if not SD.has_key("plan"):
49+
q = "SELECT fname FROM users WHERE lname = $1"
50+
SD["plan"] = plpy.prepare(q, [ "test" ])
51+
rv = plpy.execute(SD["plan"], [ a ])
52+
if len(rv):
53+
return rv[0]["fname"]
54+
return None
55+
'
56+
LANGUAGE plpythonu;
457
SELECT invalid_type_uncaught('rick');
5-
WARNING: PL/Python: plpy.SPIError: unrecognized error in PLy_spi_prepare
58+
WARNING: PL/Python:<class 'plpy.SPIError'>: unrecognized error in PLy_spi_prepare
659
CONTEXT: PL/Python function "invalid_type_uncaught"
760
ERROR: type "test" does not exist
861
CONTEXT: PL/Python function "invalid_type_uncaught"
62+
/* for what it's worth catch the exception generated by
63+
* the typo, and return None
64+
*/
65+
CREATE FUNCTION invalid_type_caught(a text) RETURNS text
66+
AS
67+
'if not SD.has_key("plan"):
68+
q = "SELECT fname FROM users WHERE lname = $1"
69+
try:
70+
SD["plan"] = plpy.prepare(q, [ "test" ])
71+
except plpy.SPIError, ex:
72+
plpy.notice(str(ex))
73+
return None
74+
rv = plpy.execute(SD["plan"], [ a ])
75+
if len(rv):
76+
return rv[0]["fname"]
77+
return None
78+
'
79+
LANGUAGE plpythonu;
980
SELECT invalid_type_caught('rick');
10-
WARNING: PL/Python: plpy.SPIError: unrecognized error in PLy_spi_prepare
81+
WARNING: PL/Python:<class 'plpy.SPIError'>: unrecognized error in PLy_spi_prepare
1182
CONTEXT: PL/Python function "invalid_type_caught"
1283
ERROR: type "test" does not exist
1384
CONTEXT: PL/Python function "invalid_type_caught"
85+
/* for what it's worth catch the exception generated by
86+
* the typo, and reraise it as a plain error
87+
*/
88+
CREATE FUNCTION invalid_type_reraised(a text) RETURNS text
89+
AS
90+
'if not SD.has_key("plan"):
91+
q = "SELECT fname FROM users WHERE lname = $1"
92+
try:
93+
SD["plan"] = plpy.prepare(q, [ "test" ])
94+
except plpy.SPIError, ex:
95+
plpy.error(str(ex))
96+
rv = plpy.execute(SD["plan"], [ a ])
97+
if len(rv):
98+
return rv[0]["fname"]
99+
return None
100+
'
101+
LANGUAGE plpythonu;
14102
SELECT invalid_type_reraised('rick');
15-
WARNING: PL/Python: plpy.SPIError: unrecognized error in PLy_spi_prepare
103+
WARNING: PL/Python:<class 'plpy.SPIError'>: unrecognized error in PLy_spi_prepare
16104
CONTEXT: PL/Python function "invalid_type_reraised"
17105
ERROR: type "test" does not exist
18106
CONTEXT: PL/Python function "invalid_type_reraised"
107+
/* no typo no messing about
108+
*/
109+
CREATE FUNCTION valid_type(a text) RETURNS text
110+
AS
111+
'if not SD.has_key("plan"):
112+
SD["plan"] = plpy.prepare("SELECT fname FROM users WHERE lname = $1", [ "text" ])
113+
rv = plpy.execute(SD["plan"], [ a ])
114+
if len(rv):
115+
return rv[0]["fname"]
116+
return None
117+
'
118+
LANGUAGE plpythonu;
19119
SELECT valid_type('rick');
20120
valid_type
21121
------------
22122

23123
(1 row)
24124

25-
--
26-
-- Test Unicode error handling.
27-
--
28-
SELECT unicode_return_error();
29-
ERROR: PL/Python: could not create string representation of Python object, while creating return value
30-
DETAIL: exceptions.UnicodeEncodeError: 'ascii' codec can't encode character u'\x80' in position 0: ordinal not in range(128)
31-
CONTEXT: PL/Python function "unicode_return_error"
32-
INSERT INTO unicode_test (testvalue) VALUES ('test');
33-
ERROR: PL/Python: could not compute string representation of Python object, while modifying trigger row
34-
DETAIL: exceptions.UnicodeEncodeError: 'ascii' codec can't encode character u'\x80' in position 0: ordinal not in range(128)
35-
CONTEXT: PL/Python function "unicode_trigger_error"
36-
SELECT unicode_plan_error1();
37-
WARNING: PL/Python: plpy.Error: unrecognized error in PLy_spi_execute_plan
38-
CONTEXT: PL/Python function "unicode_plan_error1"
39-
ERROR: PL/Python: could not execute plan
40-
DETAIL: exceptions.UnicodeEncodeError: 'ascii' codec can't encode character u'\x80' in position 0: ordinal not in range(128)
41-
CONTEXT: PL/Python function "unicode_plan_error1"
42-
SELECT unicode_plan_error2();
43-
ERROR: PL/Python: could not execute plan
44-
DETAIL: exceptions.UnicodeEncodeError: 'ascii' codec can't encode character u'\x80' in position 0: ordinal not in range(128)
45-
CONTEXT: PL/Python function "unicode_plan_error2"

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

Lines changed: 0 additions & 38 deletions
This file was deleted.

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

Lines changed: 109 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,124 @@
11
-- test error handling, i forgot to restore Warn_restart in
22
-- the trigger handler once. the errors and subsequent core dump were
33
-- interesting.
4+
/* Flat out syntax error
5+
*/
6+
CREATE FUNCTION sql_syntax_error() RETURNS text
7+
AS
8+
'plpy.execute("syntax error")'
9+
LANGUAGE plpythonu;
10+
SELECT sql_syntax_error();
11+
WARNING: PL/Python: plpy.SPIError: unrecognized error in PLy_spi_execute_query
12+
CONTEXT: PL/Python function "sql_syntax_error"
13+
ERROR: syntax error at or near "syntax"
14+
LINE 1: syntax error
15+
^
16+
QUERY: syntax error
17+
CONTEXT: PL/Python function "sql_syntax_error"
18+
/* check the handling of uncaught python exceptions
19+
*/
20+
CREATE FUNCTION exception_index_invalid(text) RETURNS text
21+
AS
22+
'return args[1]'
23+
LANGUAGE plpythonu;
24+
SELECT exception_index_invalid('test');
25+
ERROR: PL/Python: PL/Python function "exception_index_invalid" failed
26+
DETAIL: exceptions.IndexError: list index out of range
27+
CONTEXT: PL/Python function "exception_index_invalid"
28+
/* check handling of nested exceptions
29+
*/
30+
CREATE FUNCTION exception_index_invalid_nested() RETURNS text
31+
AS
32+
'rv = plpy.execute("SELECT test5(''foo'')")
33+
return rv[0]'
34+
LANGUAGE plpythonu;
35+
SELECT exception_index_invalid_nested();
36+
WARNING: PL/Python: plpy.SPIError: unrecognized error in PLy_spi_execute_query
37+
CONTEXT: PL/Python function "exception_index_invalid_nested"
38+
ERROR: function test5(unknown) does not exist
39+
LINE 1: SELECT test5('foo')
40+
^
41+
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
42+
QUERY: SELECT test5('foo')
43+
CONTEXT: PL/Python function "exception_index_invalid_nested"
44+
/* a typo
45+
*/
46+
CREATE FUNCTION invalid_type_uncaught(a text) RETURNS text
47+
AS
48+
'if not SD.has_key("plan"):
49+
q = "SELECT fname FROM users WHERE lname = $1"
50+
SD["plan"] = plpy.prepare(q, [ "test" ])
51+
rv = plpy.execute(SD["plan"], [ a ])
52+
if len(rv):
53+
return rv[0]["fname"]
54+
return None
55+
'
56+
LANGUAGE plpythonu;
457
SELECT invalid_type_uncaught('rick');
5-
WARNING:plpython: in function invalid_type_uncaught:
6-
DETAIL:plpy.SPIError: Unknown error in PLy_spi_prepare
58+
WARNING:PL/Python: plpy.SPIError: unrecognized error in PLy_spi_prepare
59+
CONTEXT:PL/Python function "invalid_type_uncaught"
760
ERROR: type "test" does not exist
61+
CONTEXT: PL/Python function "invalid_type_uncaught"
62+
/* for what it's worth catch the exception generated by
63+
* the typo, and return None
64+
*/
65+
CREATE FUNCTION invalid_type_caught(a text) RETURNS text
66+
AS
67+
'if not SD.has_key("plan"):
68+
q = "SELECT fname FROM users WHERE lname = $1"
69+
try:
70+
SD["plan"] = plpy.prepare(q, [ "test" ])
71+
except plpy.SPIError, ex:
72+
plpy.notice(str(ex))
73+
return None
74+
rv = plpy.execute(SD["plan"], [ a ])
75+
if len(rv):
76+
return rv[0]["fname"]
77+
return None
78+
'
79+
LANGUAGE plpythonu;
880
SELECT invalid_type_caught('rick');
9-
WARNING:plpython: in function invalid_type_caught:
10-
DETAIL:plpy.SPIError: Unknown error in PLy_spi_prepare
81+
WARNING:PL/Python: plpy.SPIError: unrecognized error in PLy_spi_prepare
82+
CONTEXT:PL/Python function "invalid_type_caught"
1183
ERROR: type "test" does not exist
84+
CONTEXT: PL/Python function "invalid_type_caught"
85+
/* for what it's worth catch the exception generated by
86+
* the typo, and reraise it as a plain error
87+
*/
88+
CREATE FUNCTION invalid_type_reraised(a text) RETURNS text
89+
AS
90+
'if not SD.has_key("plan"):
91+
q = "SELECT fname FROM users WHERE lname = $1"
92+
try:
93+
SD["plan"] = plpy.prepare(q, [ "test" ])
94+
except plpy.SPIError, ex:
95+
plpy.error(str(ex))
96+
rv = plpy.execute(SD["plan"], [ a ])
97+
if len(rv):
98+
return rv[0]["fname"]
99+
return None
100+
'
101+
LANGUAGE plpythonu;
12102
SELECT invalid_type_reraised('rick');
13-
WARNING:plpython: in function invalid_type_reraised:
14-
DETAIL:plpy.SPIError: Unknown error in PLy_spi_prepare
103+
WARNING:PL/Python: plpy.SPIError: unrecognized error in PLy_spi_prepare
104+
CONTEXT:PL/Python function "invalid_type_reraised"
15105
ERROR: type "test" does not exist
106+
CONTEXT: PL/Python function "invalid_type_reraised"
107+
/* no typo no messing about
108+
*/
109+
CREATE FUNCTION valid_type(a text) RETURNS text
110+
AS
111+
'if not SD.has_key("plan"):
112+
SD["plan"] = plpy.prepare("SELECT fname FROM users WHERE lname = $1", [ "text" ])
113+
rv = plpy.execute(SD["plan"], [ a ])
114+
if len(rv):
115+
return rv[0]["fname"]
116+
return None
117+
'
118+
LANGUAGE plpythonu;
16119
SELECT valid_type('rick');
17120
valid_type
18121
------------
19122

20123
(1 row)
21124

22-
--
23-
-- Test Unicode error handling.
24-
--
25-
SELECT unicode_return_error();
26-
ERROR: plpython: function "unicode_return_error" could not create return value
27-
DETAIL: exceptions.UnicodeError: ASCII encoding error: ordinal not in range(128)
28-
INSERT INTO unicode_test (testvalue) VALUES ('test');
29-
ERROR: plpython: function "unicode_trigger_error" could not modify tuple
30-
DETAIL: exceptions.UnicodeError: ASCII encoding error: ordinal not in range(128)
31-
SELECT unicode_plan_error1();
32-
WARNING: plpython: in function unicode_plan_error1:
33-
DETAIL: plpy.Error: Unknown error in PLy_spi_execute_plan
34-
ERROR: plpython: function "unicode_plan_error1" could not execute plan
35-
DETAIL: exceptions.UnicodeError: ASCII encoding error: ordinal not in range(128)
36-
SELECT unicode_plan_error2();
37-
ERROR: plpython: function "unicode_plan_error2" could not execute plan
38-
DETAIL: exceptions.UnicodeError: ASCII encoding error: ordinal not in range(128)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp