Merge branch 'boolean-normalization' of github.com:kdeldycke/cqlengine into pull-152

This commit is contained in:
Blake Eggleston
2014-02-11 11:08:02 -08:00
4 changed files with 27 additions and 4 deletions

View File

@@ -6,5 +6,5 @@ Jon Haddad <jon@jonhaddad.com>
CONTRIBUTORS
Eric Scrivner - test environment, connection pooling
Kevin Deldycke

View File

@@ -1,6 +1,10 @@
CHANGELOG
0.11.0 (in progress)
0.11.1 (in progress)
* Normalize and unquote boolean values.
0.11.0
* support for USING TIMESTAMP <microseconds from epoch> via a .timestamp(timedelta(seconds=30)) syntax
- allows for long, timedelta, and datetime

View File

@@ -442,11 +442,17 @@ class Boolean(Column):
def __str__(self):
return 'true' if self.value else 'false'
def to_python(self, value):
def validate(self, value):
""" Always returns a Python boolean. """
if isinstance(value, self.Quoter):
value = value.value
return bool(value)
def to_python(self, value):
return self.validate(value)
def to_database(self, value):
return self.Quoter(bool(value))
return self.Quoter(self.validate(value))
class Float(Column):

View File

@@ -144,6 +144,19 @@ class TestBooleanIO(BaseColumnIOTest):
pkey_val = True
data_val = False
def comparator_converter(self, val):
return val.value if isinstance(val, columns.Boolean.Quoter) else val
class TestBooleanQuoter(BaseColumnIOTest):
column = columns.Boolean
pkey_val = True
data_val = columns.Boolean.Quoter(False)
def comparator_converter(self, val):
return val.value if isinstance(val, columns.Boolean.Quoter) else val
class TestFloatIO(BaseColumnIOTest):
column = columns.Float