Added python_type for choice and color types
This commit is contained in:
@@ -40,6 +40,10 @@ class ChoiceType(types.TypeDecorator, ScalarCoercible):
|
||||
if impl:
|
||||
self.impl = impl
|
||||
|
||||
@property
|
||||
def python_type(self):
|
||||
return self.impl.python_type
|
||||
|
||||
def _coerce(self, value):
|
||||
if value is None:
|
||||
return value
|
||||
|
@@ -17,6 +17,7 @@ class ColorType(types.TypeDecorator, ScalarCoercible):
|
||||
"""
|
||||
STORE_FORMAT = u'hex'
|
||||
impl = types.Unicode(20)
|
||||
python_type = colour.Color
|
||||
|
||||
def __init__(self, max_length=20, *args, **kwargs):
|
||||
# Fail if colour is not found.
|
||||
|
@@ -40,6 +40,7 @@ class CountryType(types.TypeDecorator, ScalarCoercible):
|
||||
"""
|
||||
|
||||
impl = types.String(2)
|
||||
python_type = Country
|
||||
|
||||
def process_bind_param(self, value, dialect):
|
||||
if isinstance(value, Country):
|
||||
|
@@ -32,6 +32,10 @@ class TestChoiceType(TestCase):
|
||||
|
||||
self.User = User
|
||||
|
||||
def test_python_type(self):
|
||||
type_ = self.User.__table__.c.type.type
|
||||
assert type_.python_type
|
||||
|
||||
def test_parameter_processing(self):
|
||||
user = self.User(
|
||||
type=u'admin'
|
||||
|
@@ -18,6 +18,10 @@ class TestColorType(TestCase):
|
||||
|
||||
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):
|
||||
from colour import Color
|
||||
|
||||
|
Reference in New Issue
Block a user