Added python_type for choice and color types

This commit is contained in:
Konsta Vesterinen
2013-10-24 16:48:58 +03:00
parent d57ccd6ecb
commit 7760d87fdb
5 changed files with 14 additions and 0 deletions

View File

@@ -40,6 +40,10 @@ class ChoiceType(types.TypeDecorator, ScalarCoercible):
if impl: if impl:
self.impl = impl self.impl = impl
@property
def python_type(self):
return self.impl.python_type
def _coerce(self, value): def _coerce(self, value):
if value is None: if value is None:
return value return value

View File

@@ -17,6 +17,7 @@ class ColorType(types.TypeDecorator, ScalarCoercible):
""" """
STORE_FORMAT = u'hex' STORE_FORMAT = u'hex'
impl = types.Unicode(20) impl = types.Unicode(20)
python_type = colour.Color
def __init__(self, max_length=20, *args, **kwargs): def __init__(self, max_length=20, *args, **kwargs):
# Fail if colour is not found. # Fail if colour is not found.

View File

@@ -40,6 +40,7 @@ class CountryType(types.TypeDecorator, ScalarCoercible):
""" """
impl = types.String(2) impl = types.String(2)
python_type = Country
def process_bind_param(self, value, dialect): def process_bind_param(self, value, dialect):
if isinstance(value, Country): if isinstance(value, Country):

View File

@@ -32,6 +32,10 @@ class TestChoiceType(TestCase):
self.User = User self.User = User
def test_python_type(self):
type_ = self.User.__table__.c.type.type
assert type_.python_type
def test_parameter_processing(self): def test_parameter_processing(self):
user = self.User( user = self.User(
type=u'admin' type=u'admin'

View File

@@ -18,6 +18,10 @@ class TestColorType(TestCase):
self.Document = Document self.Document = Document
def test_python_type(self):
type_ = self.Document.__table__.c.bg_color.type
assert type_.python_type == color.colour.Color
def test_color_parameter_processing(self): def test_color_parameter_processing(self):
from colour import Color from colour import Color