# Path: advanced_filters/form_helpers.py
# class CleanWhiteSpacesMixin:
#     """
#     This mixin, when added to any form subclass, adds a clean method which
#     strips repeating spaces in and around each string value of "clean_data".
#     """
#     def clean(self):
#         """
#         >>> import django.forms
#         >>> class MyForm(CleanWhiteSpacesMixin, django.forms.Form):
#         ...     some_field = django.forms.CharField()
#         >>>
#         >>> form = MyForm({'some_field': ' a   weird value  '})
#         >>> assert form.is_valid()
#         >>> assert form.cleaned_data == {'some_field': 'a weird value'}
#         """
#         cleaned_data = super().clean()
#         for k in self.cleaned_data:
#             if isinstance(self.cleaned_data[k], str):
#                 cleaned_data[k] = re.sub(extra_spaces_pattern, ' ',
#                                          self.cleaned_data[k] or '').strip()
#         return cleaned_data


from ..form_helpers import CleanWhiteSpacesMixin
import django.forms



class FormToTest(CleanWhiteSpacesMixin, django.forms.Form):
    some_field = django.forms.CharField()


def test_spaces_removed():
    form = FormToTest(data={'some_field': ' a   weird value  '})
    assert form.is_valid()
    assert form.cleaned_data == {'some_field': 'a weird value'}

    form = FormToTest(data={'some_field': ' \n\r \n  '})
    assert not form.is_valid()

# Path: advanced_filters/form_helpers.py
# class CleanWhiteSpacesMixin:
#     """
#     This mixin, when added to any form subclass, adds a clean method which
#     strips repeating spaces in and around each string value of "clean_data".
#     """
#     def clean(self):
#         """
#         >>> import django.forms
#         >>> class MyForm(CleanWhiteSpacesMixin, django.forms.Form):
#         ...     some_field = django.forms.CharField()
#         >>>
#         >>> form = MyForm({'some_field': ' a   weird value  '})
#         >>> assert form.is_valid()
#         >>> assert form.cleaned_data == {'some_field': 'a weird value'}
#         """
#         cleaned_data = super().clean()
#         for k in self.cleaned_data:
#             if isinstance(self.cleaned_data[k], str):
#                 cleaned_data[k] = re.sub(extra_spaces_pattern, ' ',
#                                          self.cleaned_data[k] or '').strip()
#         return cleaned_data


# Path: advanced_filters/tests/test_helpers.py
from ..form_helpers import CleanWhiteSpacesMixin
import django.forms




class FormToTest(CleanWhiteSpacesMixin, django.forms.Form):
    some_field = django.forms.CharField()


def test_spaces_removed():
    form = FormToTest(data={'some_field': ' a   weird value  '})
    assert form.is_valid()
    assert form.cleaned_data == {'some_field': 'a weird value'}

    form = FormToTest(data={'some_field': ' \n\r \n  '})
    assert not form.is_valid()

    assert form.cleaned_data == {}