summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-04-28 14:44:21 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2013-04-28 14:44:21 -0400
commitfc624dcfa40bf765bbfffa2fd964f73422e4dbe8 (patch)
tree4c60b035430dc65592c7dbefec5788538c438512
parent18370ac032a84da539c54640a425c0fca7613dc9 (diff)
downloadsqlalchemy-fc624dcfa40bf765bbfffa2fd964f73422e4dbe8.tar.gz
- test_types, test_compiler, with sqlite at least
-rw-r--r--lib/sqlalchemy/engine/base.py4
-rw-r--r--lib/sqlalchemy/sql/expression.py3
-rw-r--r--lib/sqlalchemy/types.py31
-rw-r--r--test/sql/test_compiler.py3
-rw-r--r--test/sql/test_types.py70
5 files changed, 43 insertions, 68 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py
index dbc1ff820..d4ced4cca 100644
--- a/lib/sqlalchemy/engine/base.py
+++ b/lib/sqlalchemy/engine/base.py
@@ -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 = []
diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py
index aff5512d3..2c7b91fe6 100644
--- a/lib/sqlalchemy/sql/expression.py
+++ b/lib/sqlalchemy/sql/expression.py
@@ -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__)
diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py
index 4fbadcb0c..ffcd793c6 100644
--- a/lib/sqlalchemy/types.py
+++ b/lib/sqlalchemy/types.py
@@ -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()
+
+
diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py
index 329d7543e..e3f7df702 100644
--- a/test/sql/test_compiler.py
+++ b/test/sql/test_compiler.py
@@ -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')
diff --git a/test/sql/test_types.py b/test/sql/test_types.py
index f44ee9286..a47bff3ab 100644
--- a/test/sql/test_types.py
+++ b/test/sql/test_types.py
@@ -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'))