]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- test_types, test_compiler, with sqlite at least
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 28 Apr 2013 18:44:21 +0000 (14:44 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 28 Apr 2013 18:44:21 +0000 (14:44 -0400)
lib/sqlalchemy/engine/base.py
lib/sqlalchemy/sql/expression.py
lib/sqlalchemy/types.py
test/sql/test_compiler.py
test/sql/test_types.py

index dbc1ff8206e247af0c4b282163aaafd03591a633..d4ced4cca9b49bfea4236549a7e331b5bcd8ccc7 100644 (file)
@@ -734,7 +734,9 @@ class Connection(Connectable):
 
         distilled_params = _distill_params(multiparams, params)
         if distilled_params:
-            keys = list(distilled_params[0])
+            # need list() + keys() here to suit
+            # both dict and RowProxy
+            keys = list(distilled_params[0].keys())
         else:
             keys = []
 
index aff5512d313e7b614b4c41d573b4c152afe39c8d..2c7b91fe60f5b83a32204a0ea98f00d30828097d 100644 (file)
@@ -2204,7 +2204,7 @@ class _DefaultColumnComparator(operators.ColumnOperators):
     def _check_literal(self, expr, operator, other):
         if isinstance(other, (ColumnElement, TextClause)):
             if isinstance(other, BindParameter) and \
-                isinstance(other.type, sqltypes.NullType):
+                    isinstance(other.type, sqltypes.NullType):
                 # TODO: perhaps we should not mutate the incoming
                 # bindparam() here and instead make a copy of it.
                 # this might be the only place that we're mutating
@@ -3116,7 +3116,6 @@ class Executable(Generative):
 
     def execute(self, *multiparams, **params):
         """Compile and execute this :class:`.Executable`."""
-
         e = self.bind
         if e is None:
             label = getattr(self, 'description', self.__class__.__name__)
index 4fbadcb0c54b4c874df35da831775437cbca89a6..ffcd793c6aaf4854081a98681665a432c4a3f6e1 100644 (file)
@@ -1115,12 +1115,7 @@ class String(Concatenable, TypeEngine):
                 self.convert_unicode != 'force':
                 if self._warn_on_bytestring:
                     def process(value):
-# start Py3K
-                        if isinstance(value, bytes):
-# end Py3K
-# start Py2K
-#                        if isinstance(value, str):
-# end Py2K
+                        if isinstance(value, util.binary_type):
                             util.warn("Unicode type received non-unicode bind "
                                       "param value.")
                         return value
@@ -1132,7 +1127,7 @@ class String(Concatenable, TypeEngine):
                 warn_on_bytestring = self._warn_on_bytestring
 
                 def process(value):
-                    if isinstance(value, str):
+                    if isinstance(value, util.text_type):
                         return encoder(value, self.unicode_error)[0]
                     elif warn_on_bytestring and value is not None:
                         util.warn("Unicode type received non-unicode bind "
@@ -1173,7 +1168,7 @@ class String(Concatenable, TypeEngine):
     @property
     def python_type(self):
         if self.convert_unicode:
-            return str
+            return util.text_type
         else:
             return str
 
@@ -1744,7 +1739,7 @@ class _Binary(TypeEngine):
     def coerce_compared_value(self, op, value):
         """See :meth:`.TypeEngine.coerce_compared_value` for a description."""
 
-        if isinstance(value, str):
+        if isinstance(value, util.string_types):
             return self
         else:
             return super(_Binary, self).coerce_compared_value(op, value)
@@ -2001,7 +1996,7 @@ class Enum(String, SchemaType):
         convert_unicode = kw.pop('convert_unicode', None)
         if convert_unicode is None:
             for e in enums:
-                if isinstance(e, str):
+                if isinstance(e, util.string_types):
                     convert_unicode = True
                     break
             else:
@@ -2454,13 +2449,6 @@ BOOLEANTYPE = Boolean()
 STRINGTYPE = String()
 
 _type_map = {
-    str: String(),
-# start Py3K
-    bytes: LargeBinary(),
-# end Py3K
-# start Py2K
-#    unicode: Unicode(),
-# end Py2K
     int: Integer(),
     float: Numeric(),
     bool: BOOLEANTYPE,
@@ -2471,3 +2459,12 @@ _type_map = {
     dt.timedelta: Interval(),
     NoneType: NULLTYPE
 }
+
+if util.py3k:
+    _type_map[bytes] = LargeBinary()
+    _type_map[str] = Unicode()
+else:
+    _type_map[unicode] = Unicode()
+    _type_map[str] = String()
+
+
index 329d7543e59a74bfdeb07ee919f40cd3ee30c494..e3f7df70261fb917df7701dcfc4690d01ef63f4f 100644 (file)
@@ -734,13 +734,14 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL):
                             'JOIN myothertable ON mytable.myid = '
                             'myothertable.otherid')
 
-    def test_label_comparison(self):
+    def test_label_comparison_one(self):
         x = func.lala(table1.c.myid).label('foo')
         self.assert_compile(select([x], x == 5),
                             'SELECT lala(mytable.myid) AS foo FROM '
                             'mytable WHERE lala(mytable.myid) = '
                             ':param_1')
 
+    def test_label_comparison_two(self):
         self.assert_compile(
                 label('bar', column('foo', type_=String)) + 'foo',
                 'foo || :param_1')
index f44ee9286bb261e04a8e7eb7e69a4a690fce14f6..a47bff3ab984f43eba9275ceb4df33e2dca65eea 100644 (file)
@@ -141,24 +141,14 @@ class AdaptTest(fixtures.TestBase):
         eq_(types.Integer().python_type, int)
         eq_(types.Numeric().python_type, decimal.Decimal)
         eq_(types.Numeric(asdecimal=False).python_type, float)
-# start Py3K
-        eq_(types.LargeBinary().python_type, bytes)
-# end Py3K
-# start Py2K
-#        eq_(types.LargeBinary().python_type, str)
-# end Py2K
+        eq_(types.LargeBinary().python_type, util.binary_type)
         eq_(types.Float().python_type, float)
         eq_(types.Interval().python_type, datetime.timedelta)
         eq_(types.Date().python_type, datetime.date)
         eq_(types.DateTime().python_type, datetime.datetime)
-# start Py3K
         eq_(types.String().python_type, str)
-# end Py3K
-# start Py2K
-#        eq_(types.String().python_type, str)
-# end Py2K
-        eq_(types.Unicode().python_type, str)
-        eq_(types.String(convert_unicode=True).python_type, str)
+        eq_(types.Unicode().python_type, util.text_type)
+        eq_(types.String(convert_unicode=True).python_type, util.text_type)
 
         assert_raises(
             NotImplementedError,
@@ -259,14 +249,14 @@ class UserDefinedTest(fixtures.TablesTest, AssertsCompiledSQL):
     def test_processing(self):
         users = self.tables.users
         users.insert().execute(
-            user_id=2, goofy='jack', goofy2='jack', goofy4='jack',
-            goofy7='jack', goofy8=12, goofy9=12)
+            user_id=2, goofy='jack', goofy2='jack', goofy4=util.u('jack'),
+            goofy7=util.u('jack'), goofy8=12, goofy9=12)
         users.insert().execute(
-            user_id=3, goofy='lala', goofy2='lala', goofy4='lala',
-            goofy7='lala', goofy8=15, goofy9=15)
+            user_id=3, goofy='lala', goofy2='lala', goofy4=util.u('lala'),
+            goofy7=util.u('lala'), goofy8=15, goofy9=15)
         users.insert().execute(
-            user_id=4, goofy='fred', goofy2='fred', goofy4='fred',
-            goofy7='fred', goofy8=9, goofy9=9)
+            user_id=4, goofy='fred', goofy2='fred', goofy4=util.u('fred'),
+            goofy7=util.u('fred'), goofy8=9, goofy9=9)
 
         l = users.select().order_by(users.c.user_id).execute().fetchall()
         for assertstr, assertint, assertint2, row in zip(
@@ -280,7 +270,7 @@ class UserDefinedTest(fixtures.TablesTest, AssertsCompiledSQL):
             eq_(row[5], assertint)
             eq_(row[6], assertint2)
             for col in row[3], row[4]:
-                assert isinstance(col, str)
+                assert isinstance(col, util.text_type)
 
     def test_typedecorator_impl(self):
         for impl_, exp, kw in [
@@ -717,9 +707,9 @@ class UnicodeTest(fixtures.TestBase):
                 expected
             )
 
-    data = "Alors vous imaginez ma surprise, au lever du jour, quand "\
+    data = util.u("Alors vous imaginez ma surprise, au lever du jour, quand "\
             "une drôle de petite voix m’a réveillé. "\
-            "Elle disait: « S’il vous plaît… dessine-moi un mouton! »"
+            "Elle disait: « S’il vous plaît… dessine-moi un mouton! »")
 
     def test_unicode_warnings_typelevel_native_unicode(self):
 
@@ -728,14 +718,12 @@ class UnicodeTest(fixtures.TestBase):
         dialect = default.DefaultDialect()
         dialect.supports_unicode_binds = True
         uni = u.dialect_impl(dialect).bind_processor(dialect)
-# start Py3K
-        assert_raises(exc.SAWarning, uni, b'x')
-        assert isinstance(uni(unicodedata), str)
-# end Py3K
-# start Py2K
-#        assert_raises(exc.SAWarning, uni, 'x')
-#        assert isinstance(uni(unicodedata), unicode)
-# end Py2K
+        if util.py3k:
+            assert_raises(exc.SAWarning, uni, b'x')
+            assert isinstance(uni(unicodedata), str)
+        else:
+            assert_raises(exc.SAWarning, uni, 'x')
+            assert isinstance(uni(unicodedata), unicode)
 
     def test_unicode_warnings_typelevel_sqla_unicode(self):
         unicodedata = self.data
@@ -743,14 +731,8 @@ class UnicodeTest(fixtures.TestBase):
         dialect = default.DefaultDialect()
         dialect.supports_unicode_binds = False
         uni = u.dialect_impl(dialect).bind_processor(dialect)
-# start Py3K
-        assert_raises(exc.SAWarning, uni, b'x')
-        assert isinstance(uni(unicodedata), bytes)
-# end Py3K
-# start Py2K
-#        assert_raises(exc.SAWarning, uni, 'x')
-#        assert isinstance(uni(unicodedata), str)
-# end Py2K
+        assert_raises(exc.SAWarning, uni, util.b('x'))
+        assert isinstance(uni(unicodedata), util.binary_type)
 
         eq_(uni(unicodedata), unicodedata.encode('utf-8'))
 
@@ -763,15 +745,9 @@ class UnicodeTest(fixtures.TestBase):
 
         s = String()
         uni = s.dialect_impl(dialect).bind_processor(dialect)
-        # this is not the unicode type - no warning
-# start Py3K
-        uni(b'x')
-        assert isinstance(uni(unicodedata), bytes)
-# end Py3K
-# start Py2K
-#        uni('x')
-#        assert isinstance(uni(unicodedata), str)
-# end Py2K
+
+        uni(util.b('x'))
+        assert isinstance(uni(unicodedata), util.binary_type)
 
         eq_(uni(unicodedata), unicodedata.encode('utf-8'))