summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Eisentraut2012-05-02 18:09:03 +0000
committerPeter Eisentraut2012-05-02 18:09:03 +0000
commite6c2e8cb87846161033e1f215876c4b95f631df0 (patch)
treea78adc0f42d9ab816fa7d034db4ba48c83ba92ec
parent52aa334fcd5a9d230be7e8fb964d94c6c4e63dc7 (diff)
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).
-rw-r--r--src/pl/plpython/expected/plpython_do.out3
-rw-r--r--src/pl/plpython/expected/plpython_spi.out20
-rw-r--r--src/pl/plpython/sql/plpython_do.sql2
-rw-r--r--src/pl/plpython/sql/plpython_spi.sql15
4 files changed, 40 insertions, 0 deletions
diff --git a/src/pl/plpython/expected/plpython_do.out b/src/pl/plpython/expected/plpython_do.out
index 41b7a51138..d979cf811c 100644
--- a/src/pl/plpython/expected/plpython_do.out
+++ b/src/pl/plpython/expected/plpython_do.out
@@ -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):
diff --git a/src/pl/plpython/expected/plpython_spi.out b/src/pl/plpython/expected/plpython_spi.out
index 631a1a4425..671c24e33f 100644
--- a/src/pl/plpython/expected/plpython_spi.out
+++ b/src/pl/plpython/expected/plpython_spi.out
@@ -1,4 +1,24 @@
--
+-- 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
--
CREATE FUNCTION nested_call_one(a text) RETURNS text
diff --git a/src/pl/plpython/sql/plpython_do.sql b/src/pl/plpython/sql/plpython_do.sql
index 8596c39d37..beb443f95d 100644
--- a/src/pl/plpython/sql/plpython_do.sql
+++ b/src/pl/plpython/sql/plpython_do.sql
@@ -1,3 +1,5 @@
DO $$ plpy.notice("This is plpythonu.") $$ LANGUAGE plpythonu;
+DO $$ plpy.notice("This is plpython2u.") $$ LANGUAGE plpython2u;
+
DO $$ nonsense $$ LANGUAGE plpythonu;
diff --git a/src/pl/plpython/sql/plpython_spi.sql b/src/pl/plpython/sql/plpython_spi.sql
index ce218e93b6..7be2fbff71 100644
--- a/src/pl/plpython/sql/plpython_spi.sql
+++ b/src/pl/plpython/sql/plpython_spi.sql
@@ -1,4 +1,19 @@
--
+-- 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
--