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

Commitcfe380a

Browse files
committed
Augment test coverage in PL/Python, especially for error conditions.
1 parent5012551 commitcfe380a

14 files changed

+573
-34
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ SELECT test_param_names2(users) from users;
4343
{'lname': 'smith', 'username': 'slash', 'userid': 4, 'fname': 'rick'}
4444
(4 rows)
4545

46+
SELECT test_param_names2(NULL);
47+
test_param_names2
48+
-------------------
49+
None
50+
(1 row)
51+
4652
SELECT test_param_names3(1);
4753
test_param_names3
4854
-------------------

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
--
22
-- Test returning tuples
33
--
4+
CREATE TABLE table_record (
5+
first text,
6+
second int4
7+
) ;
8+
CREATE TYPE type_record AS (
9+
first text,
10+
second int4
11+
) ;
412
CREATE FUNCTION test_table_record_as(typ text, first text, second integer, retnull boolean) RETURNS table_record AS $$
513
if retnull:
614
return None
@@ -298,3 +306,26 @@ SELECT * FROM test_inout_params('test_in');
298306
test_in_inout
299307
(1 row)
300308

309+
-- errors cases
310+
CREATE FUNCTION test_type_record_error1() RETURNS type_record AS $$
311+
return { 'first': 'first' }
312+
$$ LANGUAGE plpythonu;
313+
SELECT * FROM test_type_record_error1();
314+
ERROR: key "second" not found in mapping
315+
HINT: To return null in a column, add the value None to the mapping with the key named after the column.
316+
CONTEXT: PL/Python function "test_type_record_error1"
317+
CREATE FUNCTION test_type_record_error2() RETURNS type_record AS $$
318+
return [ 'first' ]
319+
$$ LANGUAGE plpythonu;
320+
SELECT * FROM test_type_record_error2();
321+
ERROR: length of returned sequence did not match number of columns in row
322+
CONTEXT: PL/Python function "test_type_record_error2"
323+
CREATE FUNCTION test_type_record_error3() RETURNS type_record AS $$
324+
class type_record: pass
325+
type_record.first = 'first'
326+
return type_record
327+
$$ LANGUAGE plpythonu;
328+
SELECT * FROM test_type_record_error3();
329+
ERROR: attribute "second" does not exist in Python object
330+
HINT: To return null in a column, let the returned object have an attribute named after column with value None.
331+
CONTEXT: PL/Python function "test_type_record_error3"

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,3 @@ CREATE TABLE xsequences (
4141
sequence text not null
4242
) ;
4343
CREATE INDEX xsequences_pid_idx ON xsequences(pid) ;
44-
CREATE TABLE table_record (
45-
first text,
46-
second int4
47-
) ;
48-
CREATE TYPE type_record AS (
49-
first text,
50-
second int4
51-
) ;

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
--
22
-- Test returning SETOF
33
--
4+
CREATE FUNCTION test_setof_error() RETURNS SETOF text AS $$
5+
return 37
6+
$$ LANGUAGE plpythonu;
7+
SELECT test_setof_error();
8+
ERROR: returned object cannot be iterated
9+
DETAIL: PL/Python set-returning functions must return an iterable object.
10+
CONTEXT: PL/Python function "test_setof_error"
411
CREATE FUNCTION test_setof_as_list(count integer, content text) RETURNS SETOF text AS $$
512
return [ content ]*count
613
$$ LANGUAGE plpythonu;

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,27 @@ select argument_test_one(users, fname, lname) from users where lname = 'doe' ord
2626
willem doe => {fname: willem, lname: doe, userid: 3, username: w_doe}
2727
(3 rows)
2828

29+
CREATE FUNCTION elog_test() RETURNS void
30+
AS $$
31+
plpy.debug('debug')
32+
plpy.log('log')
33+
plpy.info('info')
34+
plpy.info(37)
35+
plpy.info('info', 37, [1, 2, 3])
36+
plpy.notice('notice')
37+
plpy.warning('warning')
38+
plpy.error('error')
39+
$$ LANGUAGE plpythonu;
40+
SELECT elog_test();
41+
INFO: ('info',)
42+
CONTEXT: PL/Python function "elog_test"
43+
INFO: (37,)
44+
CONTEXT: PL/Python function "elog_test"
45+
INFO: ('info', 37, [1, 2, 3])
46+
CONTEXT: PL/Python function "elog_test"
47+
NOTICE: ('notice',)
48+
CONTEXT: PL/Python function "elog_test"
49+
WARNING: ('warning',)
50+
CONTEXT: PL/Python function "elog_test"
51+
ERROR: ('error',)
52+
CONTEXT: PL/Python function "elog_test"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp