]> granicus.if.org Git - postgresql/commitdiff
PL/Python: Improve test coverage
authorPeter Eisentraut <peter_e@gmx.net>
Wed, 2 May 2012 18:09:03 +0000 (21:09 +0300)
committerPeter Eisentraut <peter_e@gmx.net>
Wed, 2 May 2012 18:09:03 +0000 (21:09 +0300)
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).

src/pl/plpython/expected/plpython_do.out
src/pl/plpython/expected/plpython_spi.out
src/pl/plpython/sql/plpython_do.sql
src/pl/plpython/sql/plpython_spi.sql

index 41b7a5113875d897e11f3eef74bcb0fd706c0833..d979cf811c7a97f807b35cfe973f82e7cba0e04a 100644 (file)
@@ -1,6 +1,9 @@
 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):
index 631a1a4425553077f8cce1b094c6d9d2f90a031e..671c24e33f75b5c18e84c696fd4698445d80d572 100644 (file)
@@ -1,3 +1,23 @@
+--
+-- 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
 --
index 8596c39d37a98ce126ae9826ed0ad71eac095be3..beb443f95d1b4e2705a37a74d14fcf2451a87241 100644 (file)
@@ -1,3 +1,5 @@
 DO $$ plpy.notice("This is plpythonu.") $$ LANGUAGE plpythonu;
 
+DO $$ plpy.notice("This is plpython2u.") $$ LANGUAGE plpython2u;
+
 DO $$ nonsense $$ LANGUAGE plpythonu;
index ce218e93b6d2a9651860cccae2605fc527c808bc..7be2fbff716c01159ad870eb26773c408eabb79c 100644 (file)
@@ -1,3 +1,18 @@
+--
+-- 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
 --