# Path: crispy_forms/templatetags/crispy_forms_field.py
# @register.simple_tag()
# def crispy_addon(field, append="", prepend="", form_show_labels=True):
#     """
#     Renders a form field using bootstrap's prepended or appended text::
# 
#         {% crispy_addon form.my_field prepend="$" append=".00" %}
# 
#     You can also just prepend or append like so
# 
#         {% crispy_addon form.my_field prepend="$" %}
#         {% crispy_addon form.my_field append=".00" %}
#     """
#     if field:
#         context = Context({"field": field, "form_show_errors": True, "form_show_labels": form_show_labels})
#         template = loader.get_template("%s/layout/prepended_appended_text.html" % get_template_pack())
#         context["crispy_prepended_text"] = prepend
#         context["crispy_appended_text"] = append
# 
#         if not prepend and not append:
#             raise TypeError("Expected a prepend and/or append argument")
# 
#         context = context.flatten()
# 
#     return template.render(context)
# 
# Path: crispy_forms/tests/forms.py
# class SampleForm(forms.Form):
#     is_company = forms.CharField(label="company", required=False, widget=forms.CheckboxInput())
#     email = forms.EmailField(
#         label="email", max_length=30, required=True, widget=forms.TextInput(), help_text="Insert your email"
#     )
#     password1 = forms.CharField(label="password", max_length=30, required=True, widget=forms.PasswordInput())
#     password2 = forms.CharField(label="re-enter password", max_length=30, required=True, widget=forms.PasswordInput())
#     first_name = forms.CharField(label="first name", max_length=5, required=True, widget=forms.TextInput())
#     last_name = forms.CharField(label="last name", max_length=5, required=True, widget=forms.TextInput())
#     datetime_field = forms.SplitDateTimeField(label="date time", widget=forms.SplitDateTimeWidget())
# 
#     def clean(self):
#         super().clean()
#         password1 = self.cleaned_data.get("password1", None)
#         password2 = self.cleaned_data.get("password2", None)
#         if not password1 and not password2 or password1 != password2:
#             raise forms.ValidationError("Passwords dont match")
# 
#         return self.cleaned_data


import pytest
from django.forms.boundfield import BoundField
from django.forms.formsets import formset_factory
from django.template import Context, Template
from crispy_forms.exceptions import CrispyError
from crispy_forms.templatetags.crispy_forms_field import crispy_addon
from .forms import SampleForm
    test_form = SampleForm()
    test_form.fields["email"].widget.attrs.update({"class": "email-fields"})
    c = Context({"testField": test_form.fields["email"]})
    html = template.render(c)
    assert "email-fields" in html


def test_crispy_field_and_class_converters():
    template = Template(
        """
        {% load crispy_forms_field %}
        {% crispy_field testField 'class' 'error' %}
    """
    )
    test_form = SampleForm()
    field_instance = test_form.fields["email"]
    bound_field = BoundField(test_form, field_instance, "email")

    c = Context({"testField": bound_field})
    html = template.render(c)
    assert "error" in html
    assert "inputtext" in html


def test_crispy_addon(settings):
    test_form = SampleForm()
    field_instance = test_form.fields["email"]
    bound_field = BoundField(test_form, field_instance, "email")

    if settings.CRISPY_TEMPLATE_PACK == "bootstrap3":

# Path: crispy_forms/templatetags/crispy_forms_field.py
# @register.simple_tag()
# def crispy_addon(field, append="", prepend="", form_show_labels=True):
#     """
#     Renders a form field using bootstrap's prepended or appended text::
# 
#         {% crispy_addon form.my_field prepend="$" append=".00" %}
# 
#     You can also just prepend or append like so
# 
#         {% crispy_addon form.my_field prepend="$" %}
#         {% crispy_addon form.my_field append=".00" %}
#     """
#     if field:
#         context = Context({"field": field, "form_show_errors": True, "form_show_labels": form_show_labels})
#         template = loader.get_template("%s/layout/prepended_appended_text.html" % get_template_pack())
#         context["crispy_prepended_text"] = prepend
#         context["crispy_appended_text"] = append
# 
#         if not prepend and not append:
#             raise TypeError("Expected a prepend and/or append argument")
# 
#         context = context.flatten()
# 
#     return template.render(context)
# 
# Path: crispy_forms/tests/forms.py
# class SampleForm(forms.Form):
#     is_company = forms.CharField(label="company", required=False, widget=forms.CheckboxInput())
#     email = forms.EmailField(
#         label="email", max_length=30, required=True, widget=forms.TextInput(), help_text="Insert your email"
#     )
#     password1 = forms.CharField(label="password", max_length=30, required=True, widget=forms.PasswordInput())
#     password2 = forms.CharField(label="re-enter password", max_length=30, required=True, widget=forms.PasswordInput())
#     first_name = forms.CharField(label="first name", max_length=5, required=True, widget=forms.TextInput())
#     last_name = forms.CharField(label="last name", max_length=5, required=True, widget=forms.TextInput())
#     datetime_field = forms.SplitDateTimeField(label="date time", widget=forms.SplitDateTimeWidget())
# 
#     def clean(self):
#         super().clean()
#         password1 = self.cleaned_data.get("password1", None)
#         password2 = self.cleaned_data.get("password2", None)
#         if not password1 and not password2 or password1 != password2:
#             raise forms.ValidationError("Passwords dont match")
# 
#         return self.cleaned_data


# Path: crispy_forms/tests/test_tags.py
import pytest
from django.forms.boundfield import BoundField
from django.forms.formsets import formset_factory
from django.template import Context, Template
from crispy_forms.exceptions import CrispyError
from crispy_forms.templatetags.crispy_forms_field import crispy_addon
from .forms import SampleForm

    test_form = SampleForm()
    test_form.fields["email"].widget.attrs.update({"class": "email-fields"})
    c = Context({"testField": test_form.fields["email"]})
    html = template.render(c)
    assert "email-fields" in html


def test_crispy_field_and_class_converters():
    template = Template(
        """
        {% load crispy_forms_field %}
        {% crispy_field testField 'class' 'error' %}
    """
    )
    test_form = SampleForm()
    field_instance = test_form.fields["email"]
    bound_field = BoundField(test_form, field_instance, "email")

    c = Context({"testField": bound_field})
    html = template.render(c)
    assert "error" in html
    assert "inputtext" in html


def test_crispy_addon(settings):
    test_form = SampleForm()
    field_instance = test_form.fields["email"]
    bound_field = BoundField(test_form, field_instance, "email")

    if settings.CRISPY_TEMPLATE_PACK == "bootstrap3":

        assert "input-group-addon" in crispy_addon(bound_field, prepend="Work", append="Primary")