From 9d9848668fd868a4e51f3a3f22c2807ff0e46582 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Wed, 12 Aug 2009 16:37:26 +0000
Subject: 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.

---
 src/pl/plpython/sql/plpython_import.sql | 63 +++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)
 create mode 100644 src/pl/plpython/sql/plpython_import.sql

(limited to 'src/pl/plpython/sql/plpython_import.sql')

diff --git a/src/pl/plpython/sql/plpython_import.sql b/src/pl/plpython/sql/plpython_import.sql
new file mode 100644
index 0000000000..7830dd7362
--- /dev/null
+++ b/src/pl/plpython/sql/plpython_import.sql
@@ -0,0 +1,63 @@
+-- import python modules
+
+CREATE FUNCTION import_fail() returns text
+    AS
+'try:
+	import foosocket
+except Exception, ex:
+	plpy.notice("import socket failed -- %s" % str(ex))
+	return "failed as expected"
+return "succeeded, that wasn''t supposed to happen"'
+    LANGUAGE plpythonu;
+
+
+CREATE FUNCTION import_succeed() returns text
+	AS
+'try:
+  import array
+  import bisect
+  import calendar
+  import cmath
+  import errno
+  import math
+  import md5
+  import operator
+  import random
+  import re
+  import sha
+  import string
+  import time
+except Exception, ex:
+	plpy.notice("import failed -- %s" % str(ex))
+	return "failed, that wasn''t supposed to happen"
+return "succeeded, as expected"'
+    LANGUAGE plpythonu;
+
+CREATE FUNCTION import_test_one(p text) RETURNS text
+	AS
+'import sha
+digest = sha.new(p)
+return digest.hexdigest()'
+	LANGUAGE plpythonu;
+
+CREATE FUNCTION import_test_two(u users) RETURNS text
+	AS
+'import sha
+plain = u["fname"] + u["lname"]
+digest = sha.new(plain);
+return "sha hash of " + plain + " is " + digest.hexdigest()'
+	LANGUAGE plpythonu;
+
+
+-- 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';
-- 
cgit v1.2.1

