mirror of
https://git.postgresql.org/git/postgresql.git
synced 2026-02-09 00:17:36 +08:00
Split the plpython regression test into test cases arranged by topic, instead
of the previous monolithic setup-create-run sequence, that was apparently inherited from a previous test infrastructure, but makes working with the tests and adding new ones weird.
This commit is contained in:
@ -1,151 +1,21 @@
|
||||
-- first some tests of basic functionality
|
||||
--
|
||||
-- better succeed
|
||||
--
|
||||
|
||||
-- really stupid function just to get the module loaded
|
||||
CREATE FUNCTION stupid() RETURNS text AS 'return "zarkon"' LANGUAGE plpythonu;
|
||||
|
||||
select stupid();
|
||||
|
||||
-- check static and global data
|
||||
--
|
||||
SELECT static_test();
|
||||
SELECT static_test();
|
||||
SELECT global_test_one();
|
||||
SELECT global_test_two();
|
||||
|
||||
-- import python modules
|
||||
--
|
||||
SELECT import_fail();
|
||||
SELECT import_succeed();
|
||||
|
||||
-- test import and simple argument handling
|
||||
--
|
||||
SELECT import_test_one('sha hash of this string');
|
||||
|
||||
-- test import and tuple argument handling
|
||||
--
|
||||
select import_test_two(users) from users where fname = 'willem';
|
||||
|
||||
-- test multiple arguments
|
||||
--
|
||||
CREATE FUNCTION argument_test_one(u users, a1 text, a2 text) RETURNS text
|
||||
AS
|
||||
'keys = u.keys()
|
||||
keys.sort()
|
||||
out = []
|
||||
for key in keys:
|
||||
out.append("%s: %s" % (key, u[key]))
|
||||
words = a1 + " " + a2 + " => {" + ", ".join(out) + "}"
|
||||
return words'
|
||||
LANGUAGE plpythonu;
|
||||
|
||||
select argument_test_one(users, fname, lname) from users where lname = 'doe' order by 1;
|
||||
|
||||
|
||||
-- spi and nested calls
|
||||
--
|
||||
select nested_call_one('pass this along');
|
||||
select spi_prepared_plan_test_one('doe');
|
||||
select spi_prepared_plan_test_one('smith');
|
||||
select spi_prepared_plan_test_nested('smith');
|
||||
|
||||
-- quick peek at the table
|
||||
--
|
||||
SELECT * FROM users;
|
||||
|
||||
-- should fail
|
||||
--
|
||||
UPDATE users SET fname = 'william' WHERE fname = 'willem';
|
||||
|
||||
-- should modify william to willem and create username
|
||||
--
|
||||
INSERT INTO users (fname, lname) VALUES ('william', 'smith');
|
||||
INSERT INTO users (fname, lname, username) VALUES ('charles', 'darwin', 'beagle');
|
||||
|
||||
SELECT * FROM users;
|
||||
|
||||
|
||||
SELECT join_sequences(sequences) FROM sequences;
|
||||
SELECT join_sequences(sequences) FROM sequences
|
||||
WHERE join_sequences(sequences) ~* '^A';
|
||||
SELECT join_sequences(sequences) FROM sequences
|
||||
WHERE join_sequences(sequences) ~* '^B';
|
||||
|
||||
-- error in trigger
|
||||
--
|
||||
|
||||
--
|
||||
-- Check Universal Newline Support
|
||||
--
|
||||
|
||||
SELECT newline_lf();
|
||||
SELECT newline_cr();
|
||||
SELECT newline_crlf();
|
||||
|
||||
-- Tests for functions returning void
|
||||
SELECT test_void_func1(), test_void_func1() IS NULL AS "is null";
|
||||
SELECT test_void_func2(); -- should fail
|
||||
SELECT test_return_none(), test_return_none() IS NULL AS "is null";
|
||||
|
||||
-- Test for functions with named and nameless parameters
|
||||
SELECT test_param_names0(2,7);
|
||||
SELECT test_param_names1(1,'text');
|
||||
SELECT test_param_names2(users) from users;
|
||||
SELECT test_param_names3(1);
|
||||
|
||||
-- Test set returning functions
|
||||
SELECT test_setof_as_list(0, 'list');
|
||||
SELECT test_setof_as_list(1, 'list');
|
||||
SELECT test_setof_as_list(2, 'list');
|
||||
SELECT test_setof_as_list(2, null);
|
||||
|
||||
SELECT test_setof_as_tuple(0, 'tuple');
|
||||
SELECT test_setof_as_tuple(1, 'tuple');
|
||||
SELECT test_setof_as_tuple(2, 'tuple');
|
||||
SELECT test_setof_as_tuple(2, null);
|
||||
|
||||
SELECT test_setof_as_iterator(0, 'list');
|
||||
SELECT test_setof_as_iterator(1, 'list');
|
||||
SELECT test_setof_as_iterator(2, 'list');
|
||||
SELECT test_setof_as_iterator(2, null);
|
||||
|
||||
-- Test tuple returning functions
|
||||
SELECT * FROM test_table_record_as('dict', null, null, false);
|
||||
SELECT * FROM test_table_record_as('dict', 'one', null, false);
|
||||
SELECT * FROM test_table_record_as('dict', null, 2, false);
|
||||
SELECT * FROM test_table_record_as('dict', 'three', 3, false);
|
||||
SELECT * FROM test_table_record_as('dict', null, null, true);
|
||||
|
||||
SELECT * FROM test_table_record_as('tuple', null, null, false);
|
||||
SELECT * FROM test_table_record_as('tuple', 'one', null, false);
|
||||
SELECT * FROM test_table_record_as('tuple', null, 2, false);
|
||||
SELECT * FROM test_table_record_as('tuple', 'three', 3, false);
|
||||
SELECT * FROM test_table_record_as('tuple', null, null, true);
|
||||
|
||||
SELECT * FROM test_table_record_as('list', null, null, false);
|
||||
SELECT * FROM test_table_record_as('list', 'one', null, false);
|
||||
SELECT * FROM test_table_record_as('list', null, 2, false);
|
||||
SELECT * FROM test_table_record_as('list', 'three', 3, false);
|
||||
SELECT * FROM test_table_record_as('list', null, null, true);
|
||||
|
||||
SELECT * FROM test_table_record_as('obj', null, null, false);
|
||||
SELECT * FROM test_table_record_as('obj', 'one', null, false);
|
||||
SELECT * FROM test_table_record_as('obj', null, 2, false);
|
||||
SELECT * FROM test_table_record_as('obj', 'three', 3, false);
|
||||
SELECT * FROM test_table_record_as('obj', null, null, true);
|
||||
|
||||
SELECT * FROM test_type_record_as('dict', null, null, false);
|
||||
SELECT * FROM test_type_record_as('dict', 'one', null, false);
|
||||
SELECT * FROM test_type_record_as('dict', null, 2, false);
|
||||
SELECT * FROM test_type_record_as('dict', 'three', 3, false);
|
||||
SELECT * FROM test_type_record_as('dict', null, null, true);
|
||||
|
||||
SELECT * FROM test_type_record_as('tuple', null, null, false);
|
||||
SELECT * FROM test_type_record_as('tuple', 'one', null, false);
|
||||
SELECT * FROM test_type_record_as('tuple', null, 2, false);
|
||||
SELECT * FROM test_type_record_as('tuple', 'three', 3, false);
|
||||
SELECT * FROM test_type_record_as('tuple', null, null, true);
|
||||
|
||||
SELECT * FROM test_type_record_as('list', null, null, false);
|
||||
SELECT * FROM test_type_record_as('list', 'one', null, false);
|
||||
SELECT * FROM test_type_record_as('list', null, 2, false);
|
||||
SELECT * FROM test_type_record_as('list', 'three', 3, false);
|
||||
SELECT * FROM test_type_record_as('list', null, null, true);
|
||||
|
||||
SELECT * FROM test_type_record_as('obj', null, null, false);
|
||||
SELECT * FROM test_type_record_as('obj', 'one', null, false);
|
||||
SELECT * FROM test_type_record_as('obj', null, 2, false);
|
||||
SELECT * FROM test_type_record_as('obj', 'three', 3, false);
|
||||
SELECT * FROM test_type_record_as('obj', null, null, true);
|
||||
|
||||
SELECT * FROM test_in_out_params('test_in');
|
||||
-- this doesn't work yet :-(
|
||||
SELECT * FROM test_in_out_params_multi('test_in');
|
||||
SELECT * FROM test_inout_params('test_in');
|
||||
|
||||
Reference in New Issue
Block a user