diff options
Diffstat (limited to 'test/sql')
| -rw-r--r-- | test/sql/test_quote.py | 49 | ||||
| -rw-r--r-- | test/sql/test_unicode.py | 32 |
2 files changed, 70 insertions, 11 deletions
diff --git a/test/sql/test_quote.py b/test/sql/test_quote.py index d7219b12d..aba6a0204 100644 --- a/test/sql/test_quote.py +++ b/test/sql/test_quote.py @@ -1,3 +1,5 @@ +#!coding: utf-8 + from sqlalchemy import CheckConstraint from sqlalchemy import Column from sqlalchemy import column @@ -11,6 +13,7 @@ from sqlalchemy import select from sqlalchemy import sql from sqlalchemy import Table from sqlalchemy import testing +from sqlalchemy import util from sqlalchemy.engine import default from sqlalchemy.sql import compiler from sqlalchemy.sql.elements import _anonymous_label @@ -18,6 +21,7 @@ from sqlalchemy.sql.elements import quoted_name from sqlalchemy.testing import AssertsCompiledSQL from sqlalchemy.testing import eq_ from sqlalchemy.testing import fixtures +from sqlalchemy.testing import is_ from sqlalchemy.testing.util import picklers @@ -250,6 +254,14 @@ class QuoteTest(fixtures.TestBase, AssertsCompiledSQL): ') AS "LaLa"', ) + def test_repr_unicode(self): + name = quoted_name(u"姓名", None) + + if util.py2k: + eq_(repr(name), "'\u59d3\u540d'") + else: + eq_(repr(name), repr(u"姓名")) + def test_lower_case_names(self): # Create table with quote defaults metadata = MetaData() @@ -988,3 +1000,40 @@ class QuotedIdentTest(fixtures.TestBase): def _assert_not_quoted(self, value): assert not isinstance(value, quoted_name) + + +class NameNormalizeTest(fixtures.TestBase): + dialect = default.DefaultDialect() + + @testing.combinations( + ("NAME", "name", False), + ("NA ME", "NA ME", False), + ("NaMe", "NaMe", False), + (u"姓名", u"姓名", False), + ("name", "name", True), # an all-lower case name needs quote forced + ) + def test_name_normalize(self, original, normalized, is_quote): + orig_norm = self.dialect.normalize_name(original) + + eq_(orig_norm, normalized) + if is_quote: + is_(orig_norm.quote, True) + else: + assert not isinstance(orig_norm, quoted_name) + + @testing.combinations( + ("name", "NAME", False), + ("NA ME", "NA ME", False), + ("NaMe", "NaMe", False), + (u"姓名", u"姓名", False), + (quoted_name("name", quote=True), "name", True), + ) + def test_name_denormalize(self, original, denormalized, is_quote): + orig_denorm = self.dialect.denormalize_name(original) + + eq_(orig_denorm, denormalized) + + if is_quote: + is_(orig_denorm.quote, True) + else: + assert not isinstance(orig_denorm, quoted_name) diff --git a/test/sql/test_unicode.py b/test/sql/test_unicode.py index 5b51644e6..dd7cad6b2 100644 --- a/test/sql/test_unicode.py +++ b/test/sql/test_unicode.py @@ -6,6 +6,7 @@ from sqlalchemy import ForeignKey from sqlalchemy import Integer from sqlalchemy import MetaData from sqlalchemy import testing +from sqlalchemy import util from sqlalchemy.testing import engines from sqlalchemy.testing import eq_ from sqlalchemy.testing import fixtures @@ -190,14 +191,23 @@ class UnicodeSchemaTest(fixtures.TestBase): ue("\u6e2c\u8a66"), m, Column(ue("\u6e2c\u8a66_id"), Integer) ) - # I hardly understand what's going on with the backslashes in - # this one on py2k vs. py3k - eq_( - repr(t), - ( - "Table('\\u6e2c\\u8a66', MetaData(bind=None), " - "Column('\\u6e2c\\u8a66_id', Integer(), " - "table=<\u6e2c\u8a66>), " - "schema=None)" - ), - ) + if util.py2k: + eq_( + repr(t), + ( + "Table('\\u6e2c\\u8a66', MetaData(bind=None), " + "Column('\\u6e2c\\u8a66_id', Integer(), " + "table=<\u6e2c\u8a66>), " + "schema=None)" + ), + ) + else: + eq_( + repr(t), + ( + "Table('測試', MetaData(bind=None), " + "Column('測試_id', Integer(), " + "table=<測試>), " + "schema=None)" + ), + ) |
