# Path: django_core/forms/fields.py
# class CommaSeparatedIntegerListField(CommaSeparatedListField):
#     """Comma Separated Integer list field."""
#     # TODO: this should honor:
#     #    max_value (each item in the list can't be > this value)
#     #    min_value (each item in the list can't be < this value)
#     #    max_length (could be the number of items in the list)
# 
#     def to_python(self, value):
#         value = super(CommaSeparatedIntegerListField, self).to_python(value)
# 
#         if isinstance(value, (list, tuple)):
#             # Ensure all values are integers
#             try:
#                 value = [int(item) for item in value]
#             except:
#                 raise ValidationError('All values in list must be whole '
#                                       'numbers.')
#         return value
# 
# Path: django_core/forms/fields.py
# class CommaSeparatedListField(CharFieldStripped):
#     """Form field that takes a string and converts into a list of strings."""
# 
#     def __init__(self, max_list_length=None, max_list_length_error_msg=None,
#                  *args, **kwargs):
#         """
#         :params max_list_length: the max number of items in the list.  If None,
#             there is no limit.
#         :params max_list_length_error_msg: if the max limit is reached, this is
#             the error message that will display.  This can also be a formatted
#             string that contains one or more of the following values:
# 
#             - max_list_length: the max list length for the field
#             - actual_list_length: the current number of items
#         """
#         super(CommaSeparatedListField, self).__init__(*args, **kwargs)
#         self.max_list_length = max_list_length
#         self.max_list_length_error_msg = max_list_length_error_msg
# 
#         if max_list_length:
#             # add the data attribute to the widget so the max length is
#             # accessible in the dom
#             self.widget.attrs['data-max_list_length'] = max_list_length
# 
#     def validate(self, value):
#         super(CommaSeparatedListField, self).validate(value)
# 
#         if (self.max_list_length is not None and
#             len(value) > self.max_list_length):
# 
#             if self.max_list_length_error_msg:
#                 error_msg_kwargs = {}
# 
#                 if '{max_list_length}' in self.max_list_length_error_msg:
#                     error_msg_kwargs['max_list_length'] = self.max_list_length
# 
#                 if '{actual_list_length}' in self.max_list_length_error_msg:
#                     error_msg_kwargs['actual_list_length'] = len(value)
# 
#                 if error_msg_kwargs:
#                     raise ValidationError(self.max_list_length_error_msg.format(
#                         **error_msg_kwargs
#                     ))
# 
#                 raise ValidationError(self.max_list_length_error_msg)
# 
#             raise ValidationError(_(
#                 'Maximum number of items is {0}. There are currently {1} items '
#                 'listed.').format(self.max_list_length, len(value)))
# 
#     def to_python(self, value):
#         value = super(CharFieldStripped, self).to_python(value)
#         return [item.strip() for item in value.split(',') if item.strip()]


from django.core.exceptions import ValidationError
from django.test.testcases import TestCase
from django_core.forms.fields import CommaSeparatedIntegerListField
from django_core.forms.fields import CommaSeparatedListField
        cleaned value.
        """
        words = ['hello', 'world', 'test']
        field = CommaSeparatedListField()
        self.assertIsNone(field.validate(words))

    def test_comma_separated_list_field_invalid_max_length(self):
        """Tests that the comma separated list field correctly validates a list
        that's too long.
        """
        words = ['hello', 'world', 'test']
        field = CommaSeparatedListField(max_list_length=2)

        with self.assertRaises(ValidationError):
            self.assertIsNone(field.validate(words))

    def test_comma_separated_integer_list_field_valid(self):
        """Test the CommaSeparatedIntegerListField correctly cleans a list of
        integers.
        """
        int_list = [1, 4, 2, 5]
        ints_string = '{0},{1}, {2}  ,   {3}'.format(*int_list)
        field = CommaSeparatedIntegerListField()
        self.assertEqual(int_list, field.to_python(ints_string))

    def test_comma_separated_integer_list_field_invalid(self):
        """Test the CommaSeparatedIntegerListField correctly throws an error
        when a list of non-integers is passed.
        """
        non_ints = '1, 4, hello, 5'

# Path: django_core/forms/fields.py
# class CommaSeparatedIntegerListField(CommaSeparatedListField):
#     """Comma Separated Integer list field."""
#     # TODO: this should honor:
#     #    max_value (each item in the list can't be > this value)
#     #    min_value (each item in the list can't be < this value)
#     #    max_length (could be the number of items in the list)
# 
#     def to_python(self, value):
#         value = super(CommaSeparatedIntegerListField, self).to_python(value)
# 
#         if isinstance(value, (list, tuple)):
#             # Ensure all values are integers
#             try:
#                 value = [int(item) for item in value]
#             except:
#                 raise ValidationError('All values in list must be whole '
#                                       'numbers.')
#         return value
# 
# Path: django_core/forms/fields.py
# class CommaSeparatedListField(CharFieldStripped):
#     """Form field that takes a string and converts into a list of strings."""
# 
#     def __init__(self, max_list_length=None, max_list_length_error_msg=None,
#                  *args, **kwargs):
#         """
#         :params max_list_length: the max number of items in the list.  If None,
#             there is no limit.
#         :params max_list_length_error_msg: if the max limit is reached, this is
#             the error message that will display.  This can also be a formatted
#             string that contains one or more of the following values:
# 
#             - max_list_length: the max list length for the field
#             - actual_list_length: the current number of items
#         """
#         super(CommaSeparatedListField, self).__init__(*args, **kwargs)
#         self.max_list_length = max_list_length
#         self.max_list_length_error_msg = max_list_length_error_msg
# 
#         if max_list_length:
#             # add the data attribute to the widget so the max length is
#             # accessible in the dom
#             self.widget.attrs['data-max_list_length'] = max_list_length
# 
#     def validate(self, value):
#         super(CommaSeparatedListField, self).validate(value)
# 
#         if (self.max_list_length is not None and
#             len(value) > self.max_list_length):
# 
#             if self.max_list_length_error_msg:
#                 error_msg_kwargs = {}
# 
#                 if '{max_list_length}' in self.max_list_length_error_msg:
#                     error_msg_kwargs['max_list_length'] = self.max_list_length
# 
#                 if '{actual_list_length}' in self.max_list_length_error_msg:
#                     error_msg_kwargs['actual_list_length'] = len(value)
# 
#                 if error_msg_kwargs:
#                     raise ValidationError(self.max_list_length_error_msg.format(
#                         **error_msg_kwargs
#                     ))
# 
#                 raise ValidationError(self.max_list_length_error_msg)
# 
#             raise ValidationError(_(
#                 'Maximum number of items is {0}. There are currently {1} items '
#                 'listed.').format(self.max_list_length, len(value)))
# 
#     def to_python(self, value):
#         value = super(CharFieldStripped, self).to_python(value)
#         return [item.strip() for item in value.split(',') if item.strip()]


# Path: tests/test_form_fields.py
from django.core.exceptions import ValidationError
from django.test.testcases import TestCase
from django_core.forms.fields import CommaSeparatedIntegerListField
from django_core.forms.fields import CommaSeparatedListField

        cleaned value.
        """
        words = ['hello', 'world', 'test']
        field = CommaSeparatedListField()
        self.assertIsNone(field.validate(words))

    def test_comma_separated_list_field_invalid_max_length(self):
        """Tests that the comma separated list field correctly validates a list
        that's too long.
        """
        words = ['hello', 'world', 'test']
        field = CommaSeparatedListField(max_list_length=2)

        with self.assertRaises(ValidationError):
            self.assertIsNone(field.validate(words))

    def test_comma_separated_integer_list_field_valid(self):
        """Test the CommaSeparatedIntegerListField correctly cleans a list of
        integers.
        """
        int_list = [1, 4, 2, 5]
        ints_string = '{0},{1}, {2}  ,   {3}'.format(*int_list)
        field = CommaSeparatedIntegerListField()
        self.assertEqual(int_list, field.to_python(ints_string))

    def test_comma_separated_integer_list_field_invalid(self):
        """Test the CommaSeparatedIntegerListField correctly throws an error
        when a list of non-integers is passed.
        """
        non_ints = '1, 4, hello, 5'

        field = CommaSeparatedIntegerListField()