summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2011-09-22 15:08:53 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2011-09-22 15:51:21 +0100
commite3054ac9f36b386121fb19b9da6fdb343c68dd56 (patch)
tree2919d191315201f9759f7d7427f24992c16aad1b /tests
parent6c8051907c5577b13da24f825716d9283ea2641e (diff)
downloadpsycopg2-e3054ac9f36b386121fb19b9da6fdb343c68dd56.tar.gz
Added new_array_type() function
Allows the creation of a generic array typecaster from Python.
Diffstat (limited to 'tests')
-rwxr-xr-xtests/types_basic.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/types_basic.py b/tests/types_basic.py
index 709907e..3686dec 100755
--- a/tests/types_basic.py
+++ b/tests/types_basic.py
@@ -285,6 +285,19 @@ class TypesBasicTests(unittest.TestCase):
l1 = self.execute("select -%s;", (-1L,))
self.assertEqual(1, l1)
+ def testGenericArray(self):
+ def caster(s, cur):
+ if s is None: return "nada"
+ return int(s) * 2
+ base = psycopg2.extensions.new_type((23,), "INT4", caster)
+ array = psycopg2.extensions.new_array_type((1007,), "INT4ARRAY", base)
+
+ psycopg2.extensions.register_type(array, self.conn)
+ a = self.execute("select '{1,2,3}'::int4[]")
+ self.assertEqual(a, [2,4,6])
+ a = self.execute("select '{1,2,NULL}'::int4[]")
+ self.assertEqual(a, [2,4,'nada'])
+
class AdaptSubclassTest(unittest.TestCase):
def test_adapt_subtype(self):