Commit e6c2e8cb authored by Peter Eisentraut's avatar Peter Eisentraut

PL/Python: Improve test coverage

Add test cases for inline handler of plython2u (when using that
language name), and for result object element assignment.  There is
now at least one test case for every top-level functionality, except
plpy.Fatal (annoying to use in regression tests) and result object
slice retrieval and slice assignment (which are somewhat broken).
parent 52aa334f
DO $$ plpy.notice("This is plpythonu.") $$ LANGUAGE plpythonu;
NOTICE: This is plpythonu.
CONTEXT: PL/Python anonymous code block
DO $$ plpy.notice("This is plpython2u.") $$ LANGUAGE plpython2u;
NOTICE: This is plpython2u.
CONTEXT: PL/Python anonymous code block
DO $$ nonsense $$ LANGUAGE plpythonu;
ERROR: NameError: global name 'nonsense' is not defined
CONTEXT: Traceback (most recent call last):
......
--
-- result objects
--
CREATE FUNCTION test_resultobject_access() RETURNS void
AS $$
rv = plpy.execute("SELECT fname, lname, username FROM users ORDER BY username")
plpy.info([row for row in rv])
rv[1] = dict([(k, v*2) for (k, v) in rv[1].items()])
plpy.info([row for row in rv])
$$ LANGUAGE plpythonu;
SELECT test_resultobject_access();
INFO: [{'lname': 'doe', 'username': 'j_doe', 'fname': 'jane'}, {'lname': 'doe', 'username': 'johnd', 'fname': 'john'}, {'lname': 'smith', 'username': 'slash', 'fname': 'rick'}, {'lname': 'doe', 'username': 'w_doe', 'fname': 'willem'}]
CONTEXT: PL/Python function "test_resultobject_access"
INFO: [{'lname': 'doe', 'username': 'j_doe', 'fname': 'jane'}, {'lname': 'doedoe', 'username': 'johndjohnd', 'fname': 'johnjohn'}, {'lname': 'smith', 'username': 'slash', 'fname': 'rick'}, {'lname': 'doe', 'username': 'w_doe', 'fname': 'willem'}]
CONTEXT: PL/Python function "test_resultobject_access"
test_resultobject_access
--------------------------
(1 row)
--
-- nested calls
--
......
DO $$ plpy.notice("This is plpythonu.") $$ LANGUAGE plpythonu;
DO $$ plpy.notice("This is plpython2u.") $$ LANGUAGE plpython2u;
DO $$ nonsense $$ LANGUAGE plpythonu;
--
-- result objects
--
CREATE FUNCTION test_resultobject_access() RETURNS void
AS $$
rv = plpy.execute("SELECT fname, lname, username FROM users ORDER BY username")
plpy.info([row for row in rv])
rv[1] = dict([(k, v*2) for (k, v) in rv[1].items()])
plpy.info([row for row in rv])
$$ LANGUAGE plpythonu;
SELECT test_resultobject_access();
--
-- nested calls
--
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment