Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e6c2e8c

Browse files
committed
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).
1 parent 52aa334 commit e6c2e8c

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

src/pl/plpython/expected/plpython_do.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
DO $$ plpy.notice("This is plpythonu.") $$ LANGUAGE plpythonu;
22
NOTICE: This is plpythonu.
33
CONTEXT: PL/Python anonymous code block
4+
DO $$ plpy.notice("This is plpython2u.") $$ LANGUAGE plpython2u;
5+
NOTICE: This is plpython2u.
6+
CONTEXT: PL/Python anonymous code block
47
DO $$ nonsense $$ LANGUAGE plpythonu;
58
ERROR: NameError: global name 'nonsense' is not defined
69
CONTEXT: Traceback (most recent call last):

src/pl/plpython/expected/plpython_spi.out

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
--
2+
-- result objects
3+
--
4+
CREATE FUNCTION test_resultobject_access() RETURNS void
5+
AS $$
6+
rv = plpy.execute("SELECT fname, lname, username FROM users ORDER BY username")
7+
plpy.info([row for row in rv])
8+
rv[1] = dict([(k, v*2) for (k, v) in rv[1].items()])
9+
plpy.info([row for row in rv])
10+
$$ LANGUAGE plpythonu;
11+
SELECT test_resultobject_access();
12+
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'}]
13+
CONTEXT: PL/Python function "test_resultobject_access"
14+
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'}]
15+
CONTEXT: PL/Python function "test_resultobject_access"
16+
test_resultobject_access
17+
--------------------------
18+
19+
(1 row)
20+
121
--
222
-- nested calls
323
--

src/pl/plpython/sql/plpython_do.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
DO $$ plpy.notice("This is plpythonu.") $$ LANGUAGE plpythonu;
22

3+
DO $$ plpy.notice("This is plpython2u.") $$ LANGUAGE plpython2u;
4+
35
DO $$ nonsense $$ LANGUAGE plpythonu;

src/pl/plpython/sql/plpython_spi.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
--
2+
-- result objects
3+
--
4+
5+
CREATE FUNCTION test_resultobject_access() RETURNS void
6+
AS $$
7+
rv = plpy.execute("SELECT fname, lname, username FROM users ORDER BY username")
8+
plpy.info([row for row in rv])
9+
rv[1] = dict([(k, v*2) for (k, v) in rv[1].items()])
10+
plpy.info([row for row in rv])
11+
$$ LANGUAGE plpythonu;
12+
13+
SELECT test_resultobject_access();
14+
15+
116
--
217
-- nested calls
318
--

0 commit comments

Comments
 (0)