diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-05-26 16:39:50 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-05-26 16:39:50 -0400 |
| commit | b3654ee37abe7af3d83098cd8de1980369a3fcba (patch) | |
| tree | c8b1543d9d4b872481988d0a3fa405509a2e6c0d | |
| parent | f939abe83034840b6c304df5ea4dfda5e9dc4633 (diff) | |
| download | sqlalchemy-b3654ee37abe7af3d83098cd8de1980369a3fcba.tar.gz | |
postgresql tests
| -rw-r--r-- | lib/sqlalchemy/dialects/postgresql/base.py | 36 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/postgresql/hstore.py | 4 | ||||
| -rw-r--r-- | test/dialect/test_postgresql.py | 12 |
3 files changed, 25 insertions, 27 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index cd5d9772d..00d0acc2c 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -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 diff --git a/lib/sqlalchemy/dialects/postgresql/hstore.py b/lib/sqlalchemy/dialects/postgresql/hstore.py index d7fd34d05..adfb82da7 100644 --- a/lib/sqlalchemy/dialects/postgresql/hstore.py +++ b/lib/sqlalchemy/dialects/postgresql/hstore.py @@ -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." % diff --git a/test/dialect/test_postgresql.py b/test/dialect/test_postgresql.py index 8568f6add..286628d5e 100644 --- a/test/dialect/test_postgresql.py +++ b/test/dialect/test_postgresql.py @@ -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_( |
