]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
postgresql tests
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 26 May 2013 20:39:50 +0000 (16:39 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 26 May 2013 20:39:50 +0000 (16:39 -0400)
lib/sqlalchemy/dialects/postgresql/base.py
lib/sqlalchemy/dialects/postgresql/hstore.py
test/dialect/test_postgresql.py

index cd5d9772d7c388505341402789a5621064a2717d..00d0acc2c9e93ee25ce26e9509a840251229e395 100644 (file)
@@ -1569,14 +1569,13 @@ class PGDialect(default.DefaultDialect):
         """
         rp = connection.execute(s)
         # what about system tables?
-# start Py3K
-        schema_names = [row[0] for row in rp \
+
+        if util.py2k:
+            schema_names = [row[0].decode(self.encoding) for row in rp \
+                        if not row[0].startswith('pg_')]
+        else:
+            schema_names = [row[0] for row in rp \
                         if not row[0].startswith('pg_')]
-# end Py3K
-# start Py2K
-#        schema_names = [row[0].decode(self.encoding) for row in rp \
-#                        if not row[0].startswith('pg_')]
-# end Py2K
         return schema_names
 
     @reflection.cache
@@ -1610,13 +1609,12 @@ class PGDialect(default.DefaultDialect):
           AND '%(schema)s' = (select nspname from pg_namespace n
           where n.oid = c.relnamespace)
         """ % dict(schema=current_schema)
-# start Py3K
-        view_names = [row[0] for row in connection.execute(s)]
-# end Py3K
-# start Py2K
-#        view_names = [row[0].decode(self.encoding)
-#                            for row in connection.execute(s)]
-# end Py2K
+
+        if util.py2k:
+            view_names = [row[0].decode(self.encoding)
+                            for row in connection.execute(s)]
+        else:
+            view_names = [row[0] for row in connection.execute(s)]
         return view_names
 
     @reflection.cache
@@ -1633,12 +1631,10 @@ class PGDialect(default.DefaultDialect):
         rp = connection.execute(sql.text(s),
                                 view_name=view_name, schema=current_schema)
         if rp:
-# start Py3K
-            view_def = rp.scalar()
-# end Py3K
-# start Py2K
-#            view_def = rp.scalar().decode(self.encoding)
-# end Py2K
+            if util.py2k:
+                view_def = rp.scalar().decode(self.encoding)
+            else:
+                view_def = rp.scalar()
             return view_def
 
     @reflection.cache
index d7fd34d051e8fb24a9ef7ae1cf8dd142e226b4b6..adfb82da76142e5a252ad91b78a92c53c2b43717 100644 (file)
@@ -10,6 +10,8 @@ from .base import ARRAY, ischema_names
 from ... import types as sqltypes
 from ...sql import functions as sqlfunc
 from ...sql.operators import custom_op
+from ... import util
+
 
 __all__ = ('HSTORE', 'hstore')
 
@@ -96,7 +98,7 @@ def _serialize_hstore(val):
     def esc(s, position):
         if position == 'value' and s is None:
             return 'NULL'
-        elif isinstance(s, str):
+        elif isinstance(s, util.string_types):
             return '"%s"' % s.replace('"', r'\"')
         else:
             raise ValueError("%r in %s position is not a string." %
index 8568f6addfd7e0f67e91dcbcf1bcb6cd2d0afa20..286628d5e4d6abcb9f4d3b1333adcc80cafe7458 100644 (file)
@@ -1478,7 +1478,7 @@ class ReflectionTest(fixtures.TestBase):
         meta1.create_all()
         meta2 = MetaData(testing.db)
         subject = Table('subject', meta2, autoload=True)
-        eq_(list(subject.primary_key.columns.keys()), ['p2', 'p1'])
+        eq_(subject.primary_key.columns.keys(), ['p2', 'p1'])
 
     @testing.provide_metadata
     def test_pg_weirdchar_reflection(self):
@@ -2205,15 +2205,15 @@ class ArrayTest(fixtures.TablesTest, AssertsExecutionResults):
     def test_array_subtype_resultprocessor(self):
         arrtable = self.tables.arrtable
         arrtable.insert().execute(intarr=[4, 5, 6],
-                                  strarr=[[util.u('m\xe4\xe4')], [
-                                    util.u('m\xf6\xf6')]])
+                                  strarr=[[util.ue('m\xe4\xe4')], [
+                                    util.ue('m\xf6\xf6')]])
         arrtable.insert().execute(intarr=[1, 2, 3], strarr=[
-                        util.u('m\xe4\xe4'), util.u('m\xf6\xf6')])
+                        util.ue('m\xe4\xe4'), util.ue('m\xf6\xf6')])
         results = \
             arrtable.select(order_by=[arrtable.c.intarr]).execute().fetchall()
         eq_(len(results), 2)
-        eq_(results[0]['strarr'], [util.u('m\xe4\xe4'), util.u('m\xf6\xf6')])
-        eq_(results[1]['strarr'], [[util.u('m\xe4\xe4')], [util.u('m\xf6\xf6')]])
+        eq_(results[0]['strarr'], [util.ue('m\xe4\xe4'), util.ue('m\xf6\xf6')])
+        eq_(results[1]['strarr'], [[util.ue('m\xe4\xe4')], [util.ue('m\xf6\xf6')]])
 
     def test_array_literal(self):
         eq_(