# 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_,
)
        self.assertEqual(
            form_field(form['test_field'])['classes'], ('required',))

    def test_render_html_classes_correctly_for_empty_required_field(self):
        form = TestForm(data={})
        form.fields['test_field'].required = True
        self.assertEqual(
            set(form_field(form['test_field'])['classes']),
            set(['required', 'error']))

    def test_render_html_classes_correctly_for_non_required_field(self):
        form = TestForm()
        form.fields['test_field'].required = False
        self.assertEqual(
            form_field(form['test_field'])['classes'], ())


class FormFieldsetTestCase(TestCase):

    def test_generate_list_of_bound_fields_correctly(self):
        form = TestForm()
        self.assertEqual(
            [bound_field.field for bound_field in
                form_fieldset(form, fields='test_field')['fields']],
            [form.fields['test_field']])

    def test_raise_error_when_undefined_field(self):
        form = TestForm()
        self.assertRaises(
            KeyError,

# 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_,
)

        self.assertEqual(
            form_field(form['test_field'])['classes'], ('required',))

    def test_render_html_classes_correctly_for_empty_required_field(self):
        form = TestForm(data={})
        form.fields['test_field'].required = True
        self.assertEqual(
            set(form_field(form['test_field'])['classes']),
            set(['required', 'error']))

    def test_render_html_classes_correctly_for_non_required_field(self):
        form = TestForm()
        form.fields['test_field'].required = False
        self.assertEqual(
            form_field(form['test_field'])['classes'], ())


class FormFieldsetTestCase(TestCase):

    def test_generate_list_of_bound_fields_correctly(self):
        form = TestForm()
        self.assertEqual(
            [bound_field.field for bound_field in
                form_fieldset(form, fields='test_field')['fields']],
            [form.fields['test_field']])

    def test_raise_error_when_undefined_field(self):
        form = TestForm()
        self.assertRaises(
            KeyError,

            lambda: form_fieldset(form, fields='test_field undefined')),