# Path: brasilcomvc/common/templatetags/form_utils.py
# @register.inclusion_tag('widgets/form_field.html')
# def form_field(field):
#     '''
#     Render a single field
#     '''
#     form = field.form
# 
#     # Prepare field HTML classes
#     classes = tuple(filter(None, [
#         'required' if field.field.required else None,
#         'error' if field.errors else None,
#     ]))
# 
#     return {
#         'classes': classes,
#         'field': field,
#         'form_id': form.prefix or type(form).__name__.lower(),
#     }
# 
# @register.inclusion_tag('widgets/form_fieldset.html')
# def form_fieldset(form, legend=None, fields=None):
#     '''
#     Render a <fieldset> from `form` with provided space-separated fields
#     '''
#     return {
#         'fields': list(map(lambda field: form[field], fields.split())),
#         'legend': legend,
#     }
# 
# @register.filter('type')
# def type_(obj):
#     '''
#     Retrieve the class name of an object
#     '''
#     return str(type(obj).__name__)


from django import forms
from django.test import TestCase
from ...templatetags.form_utils import (
    form_field,
    form_fieldset,
    type_,
)



class TestForm(forms.Form):
    test_field = forms.CharField(max_length=40)


class TypeTestCase(TestCase):

    def test_type_filter_should_return_correct_class_name(self):
        self.assertEqual(type_([]), 'list')
        form = TestForm()

# Path: brasilcomvc/common/templatetags/form_utils.py
# @register.inclusion_tag('widgets/form_field.html')
# def form_field(field):
#     '''
#     Render a single field
#     '''
#     form = field.form
# 
#     # Prepare field HTML classes
#     classes = tuple(filter(None, [
#         'required' if field.field.required else None,
#         'error' if field.errors else None,
#     ]))
# 
#     return {
#         'classes': classes,
#         'field': field,
#         'form_id': form.prefix or type(form).__name__.lower(),
#     }
# 
# @register.inclusion_tag('widgets/form_fieldset.html')
# def form_fieldset(form, legend=None, fields=None):
#     '''
#     Render a <fieldset> from `form` with provided space-separated fields
#     '''
#     return {
#         'fields': list(map(lambda field: form[field], fields.split())),
#         'legend': legend,
#     }
# 
# @register.filter('type')
# def type_(obj):
#     '''
#     Retrieve the class name of an object
#     '''
#     return str(type(obj).__name__)


# Path: brasilcomvc/common/tests/templatetags/test_form_utils.py
from django import forms
from django.test import TestCase
from ...templatetags.form_utils import (
    form_field,
    form_fieldset,
    type_,
)




class TestForm(forms.Form):
    test_field = forms.CharField(max_length=40)


class TypeTestCase(TestCase):

    def test_type_filter_should_return_correct_class_name(self):
        self.assertEqual(type_([]), 'list')
        form = TestForm()

        self.assertEqual(type_(form['test_field'].field.widget), 'TextInput')