diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-04-04 12:02:51 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-04-04 12:02:51 -0400 |
| commit | ecd7b31d5eaed138e699293719f70260da3c978d (patch) | |
| tree | 9290647481a09b18e37a438428e68f379191baa8 /test/dialect/postgresql | |
| parent | ee40c7afaabe33e2080607de0045a9fd0a4748d8 (diff) | |
| download | sqlalchemy-ecd7b31d5eaed138e699293719f70260da3c978d.tar.gz | |
- Fixed a long-standing bug where the :class:`.Enum` type as used
with the psycopg2 dialect in conjunction with non-ascii values
and ``native_enum=False`` would fail to decode return results properly.
This stemmed from when the PG :class:`.postgresql.ENUM` type used
to be a standalone type without a "non native" option.
fixes #3354
- corrected the assertsql comparison rule to expect a non-ascii
SQL string
Diffstat (limited to 'test/dialect/postgresql')
| -rw-r--r-- | test/dialect/postgresql/test_types.py | 60 |
1 files changed, 50 insertions, 10 deletions
diff --git a/test/dialect/postgresql/test_types.py b/test/dialect/postgresql/test_types.py index 393ef43de..e26526ef3 100644 --- a/test/dialect/postgresql/test_types.py +++ b/test/dialect/postgresql/test_types.py @@ -171,8 +171,9 @@ class EnumTest(fixtures.TestBase, AssertsExecutionResults): (util.u('réveillé'), util.u('drôle'), util.u('S’il')) ) - def test_non_native_type(self): - metadata = MetaData() + @testing.provide_metadata + def test_non_native_enum(self): + metadata = self.metadata t1 = Table( 'foo', metadata, @@ -188,14 +189,53 @@ class EnumTest(fixtures.TestBase, AssertsExecutionResults): def go(): t1.create(testing.db) - try: - self.assert_sql( - testing.db, go, [ - ("CREATE TABLE foo (\tbar " - "VARCHAR(5), \tCONSTRAINT myenum CHECK " - "(bar IN ('one', 'two', 'three')))", {})]) - finally: - metadata.drop_all(testing.db) + self.assert_sql( + testing.db, go, [ + ("CREATE TABLE foo (\tbar " + "VARCHAR(5), \tCONSTRAINT myenum CHECK " + "(bar IN ('one', 'two', 'three')))", {})]) + with testing.db.begin() as conn: + conn.execute( + t1.insert(), {'bar': 'two'} + ) + eq_( + conn.scalar(select([t1.c.bar])), 'two' + ) + + @testing.provide_metadata + def test_non_native_enum_w_unicode(self): + metadata = self.metadata + t1 = Table( + 'foo', + metadata, + Column( + 'bar', + Enum('B', util.u('Ü'), name='myenum', native_enum=False))) + + def go(): + t1.create(testing.db) + + self.assert_sql( + testing.db, + go, + [ + ( + util.u( + "CREATE TABLE foo (\tbar " + "VARCHAR(1), \tCONSTRAINT myenum CHECK " + "(bar IN ('B', 'Ü')))" + ), + {} + ) + ]) + + with testing.db.begin() as conn: + conn.execute( + t1.insert(), {'bar': util.u('Ü')} + ) + eq_( + conn.scalar(select([t1.c.bar])), util.u('Ü') + ) @testing.provide_metadata def test_disable_create(self): |
