Make sure column types with add'l init args are documented

This commit is contained in:
Adam Holmberg
2015-02-12 15:11:49 -06:00
parent 74fdfd76a8
commit 8f076e966a
4 changed files with 24 additions and 34 deletions

View File

@@ -318,24 +318,17 @@ class Text(Column):
""" """
Stores a UTF-8 encoded string Stores a UTF-8 encoded string
""" """
db_type = 'text' db_type = 'text'
min_length = None def __init__(self, min_length=None, max_length=None, **kwargs):
""" """
Sets the minimum length of this string, for validation purposes. :param int min_length: Sets the minimum length of this string, for validation purposes.
Defaults to 1 if this is a ``required`` column. Otherwise, None. Defaults to 1 if this is a ``required`` column. Otherwise, None.
:param int max_lemgth: Sets the maximum length of this string, for validation purposes.
""" """
self.min_length = min_length or (1 if kwargs.get('required', False) else None)
max_length = None self.max_length = max_length
""" super(Text, self).__init__(**kwargs)
Sets the maximum length of this string, for validation purposes.
"""
def __init__(self, *args, **kwargs):
self.min_length = kwargs.pop('min_length', 1 if kwargs.get('required', False) else None)
self.max_length = kwargs.pop('max_length', None)
super(Text, self).__init__(*args, **kwargs)
def validate(self, value): def validate(self, value):
value = super(Text, self).validate(value) value = super(Text, self).validate(value)
@@ -591,7 +584,7 @@ class Boolean(Column):
class Float(Column): class Float(Column):
""" """
Stores a 32-bit floating point value Stores a floating point value
""" """
db_type = 'double' db_type = 'double'
@@ -765,6 +758,9 @@ class List(BaseContainerColumn):
return bool(self.value) return bool(self.value)
def __init__(self, value_type, default=list, **kwargs): def __init__(self, value_type, default=list, **kwargs):
"""
:param value_type: a column class indicating the types of the value
"""
return super(List, self).__init__(value_type=value_type, default=default, **kwargs) return super(List, self).__init__(value_type=value_type, default=default, **kwargs)
def validate(self, value): def validate(self, value):

View File

@@ -50,7 +50,7 @@ Columns of all types are initialized by passing :class:`.Column` attributes to t
.. autoclass:: Boolean(**kwargs) .. autoclass:: Boolean(**kwargs)
.. autoclass:: Counter(**kwargs) .. autoclass:: Counter
.. autoclass:: Date(**kwargs) .. autoclass:: Date(**kwargs)
@@ -58,23 +58,17 @@ Columns of all types are initialized by passing :class:`.Column` attributes to t
.. autoclass:: Decimal(**kwargs) .. autoclass:: Decimal(**kwargs)
.. autoclass:: Float(**kwargs) .. autoclass:: Float
.. autoclass:: Integer(**kwargs) .. autoclass:: Integer(**kwargs)
.. autoclass:: List(**kwargs) .. autoclass:: List
.. autoclass:: Map(**kwargs) .. autoclass:: Map
.. autoclass:: Set(**kwargs) .. autoclass:: Set
.. autoclass:: Text(**kwargs) .. autoclass:: Text
In addition to the :class:Column attributes, ``Text`` columns accept the following attributes for validation:
.. autoattribute:: min_length
.. autoattribute:: max_length
.. autoclass:: TimeUUID(**kwargs) .. autoclass:: TimeUUID(**kwargs)

View File

@@ -55,7 +55,7 @@ version = cassandra.__version__
release = cassandra.__version__ release = cassandra.__version__
autodoc_member_order = 'bysource' autodoc_member_order = 'bysource'
autoclass_content = 'class' autoclass_content = 'both'
# The language for content autogenerated by Sphinx. Refer to documentation # The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages. # for a list of supported languages.

View File

@@ -288,14 +288,14 @@ class TestBigInt(BaseCassEngTestCase):
class TestText(BaseCassEngTestCase): class TestText(BaseCassEngTestCase):
def test_min_length(self): def test_min_length(self):
#min len defaults to 1 # not required defaults to 0
col = Text() col = Text()
col.validate('') col.validate('')
col.validate('b') col.validate('b')
#test not required defaults to 0 # required defaults to 1
Text(required=False).validate('') with self.assertRaises(ValidationError):
Text(required=True).validate('')
#test arbitrary lengths #test arbitrary lengths
Text(min_length=0).validate('') Text(min_length=0).validate('')