postgresql/src/pl/plpython/expected/plpython_import.out
Andres Freund db23464715 plpython: Remove regression test infrastructure for Python 2.
Since 19252e8ec9 we reject Python 2 during build configuration. Now that the
dust on the buildfarm has settled, remove regression testing infrastructure
dealing with differing output between Python 2 / 3.

Reviewed-By: Peter Eisentraut <peter@eisentraut.org>
Reviewed-By: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/20211031184548.g4sxfe47n2kyi55r@alap3.anarazel.de
2022-03-07 18:20:51 -08:00

79 lines
1.9 KiB
Text

-- import python modules
CREATE FUNCTION import_fail() returns text
AS
'try:
import foosocket
except ImportError:
return "failed as expected"
return "succeeded, that wasn''t supposed to happen"'
LANGUAGE plpython3u;
CREATE FUNCTION import_succeed() returns text
AS
'try:
import array
import bisect
import calendar
import cmath
import errno
import math
import operator
import random
import re
import string
import time
except Exception as ex:
plpy.notice("import failed -- %s" % str(ex))
return "failed, that wasn''t supposed to happen"
return "succeeded, as expected"'
LANGUAGE plpython3u;
CREATE FUNCTION import_test_one(p text) RETURNS text
AS
'try:
import hashlib
digest = hashlib.sha1(p.encode("ascii"))
except ImportError:
import sha
digest = sha.new(p)
return digest.hexdigest()'
LANGUAGE plpython3u;
CREATE FUNCTION import_test_two(u users) RETURNS text
AS
'plain = u["fname"] + u["lname"]
try:
import hashlib
digest = hashlib.sha1(plain.encode("ascii"))
except ImportError:
import sha
digest = sha.new(plain);
return "sha hash of " + plain + " is " + digest.hexdigest()'
LANGUAGE plpython3u;
-- import python modules
--
SELECT import_fail();
import_fail
--------------------
failed as expected
(1 row)
SELECT import_succeed();
import_succeed
------------------------
succeeded, as expected
(1 row)
-- test import and simple argument handling
--
SELECT import_test_one('sha hash of this string');
import_test_one
------------------------------------------
a04e23cb9b1a09cd1051a04a7c571aae0f90346c
(1 row)
-- test import and tuple argument handling
--
select import_test_two(users) from users where fname = 'willem';
import_test_two
-------------------------------------------------------------------
sha hash of willemdoe is 3cde6b574953b0ca937b4d76ebc40d534d910759
(1 row)