summaryrefslogtreecommitdiff
path: root/test/engine/test_processors.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2016-06-23 19:26:28 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2016-06-23 19:58:43 -0400
commit7c74d702a9632a8c7264d6972e46985de3fb2487 (patch)
tree9db49b27827f580b856671186aae2d40952d74f2 /test/engine/test_processors.py
parentbf03d4332ae35e2087b175f8a2e0291d2f4c9aa0 (diff)
downloadsqlalchemy-7c74d702a9632a8c7264d6972e46985de3fb2487.tar.gz
Make boolean processors consistent between Py/C; coerce to 1/0
The processing performed by the :class:`.Boolean` datatype for backends that only feature integer types has been made consistent between the pure Python and C-extension versions, in that the C-extension version will accept any integer value from the database as a boolean, not just zero and one; additionally, non-boolean integer values being sent to the database are coerced to exactly zero or one, instead of being passed as the original integer value. Change-Id: I01e647547fd7047bd549dd70e1fa202c51e8328b Fixes: #3730
Diffstat (limited to 'test/engine/test_processors.py')
-rw-r--r--test/engine/test_processors.py79
1 files changed, 79 insertions, 0 deletions
diff --git a/test/engine/test_processors.py b/test/engine/test_processors.py
index f4df7827c..47302af97 100644
--- a/test/engine/test_processors.py
+++ b/test/engine/test_processors.py
@@ -2,6 +2,85 @@ from sqlalchemy.testing import fixtures
from sqlalchemy.testing import assert_raises_message, eq_
+class _BooleanProcessorTest(fixtures.TestBase):
+ def test_int_to_bool_none(self):
+ eq_(
+ self.module.int_to_boolean(None),
+ None
+ )
+
+ def test_int_to_bool_zero(self):
+ eq_(
+ self.module.int_to_boolean(0),
+ False
+ )
+
+ def test_int_to_bool_one(self):
+ eq_(
+ self.module.int_to_boolean(1),
+ True
+ )
+
+ def test_int_to_bool_positive_int(self):
+ eq_(
+ self.module.int_to_boolean(12),
+ True
+ )
+
+ def test_int_to_bool_negative_int(self):
+ eq_(
+ self.module.int_to_boolean(-4),
+ True
+ )
+
+
+
+class PyBooleanProcessorTest(_BooleanProcessorTest):
+ @classmethod
+ def setup_class(cls):
+ from sqlalchemy import processors
+ cls.module = type(
+ "util", (object,),
+ dict(
+ (k, staticmethod(v))
+ for k, v in list(processors.py_fallback().items())
+ )
+ )
+
+ def test_bool_to_int_false(self):
+ from sqlalchemy import processors
+ eq_(processors.boolean_to_int(False), 0)
+
+ def test_bool_to_int_true(self):
+ from sqlalchemy import processors
+ eq_(processors.boolean_to_int(True), 1)
+
+ def test_bool_to_int_positive_int(self):
+ from sqlalchemy import processors
+ eq_(processors.boolean_to_int(5), 1)
+
+ def test_bool_to_int_negative_int(self):
+ from sqlalchemy import processors
+ eq_(processors.boolean_to_int(-10), 1)
+
+ def test_bool_to_int_zero(self):
+ from sqlalchemy import processors
+ eq_(processors.boolean_to_int(0), 0)
+
+ def test_bool_to_int_one(self):
+ from sqlalchemy import processors
+ eq_(processors.boolean_to_int(1), 1)
+
+
+class CBooleanProcessorTest(_BooleanProcessorTest):
+ __requires__ = ('cextensions',)
+
+ @classmethod
+ def setup_class(cls):
+ from sqlalchemy import cprocessors
+ cls.module = cprocessors
+
+
class _DateProcessorTest(fixtures.TestBase):
def test_date_no_string(self):
assert_raises_message(