# Path: djangocodemirror/fields.py
# class CodeMirrorField(forms.CharField):
#     """
#     A CharField that comes with CodeMirrorWidget.
# 
#     Arguments:
#         config_name (string): A Codemirror config name available in
#             ``settings.CODEMIRROR_SETTINGS``. Default is ``empty``.
#     """
#     def __init__(self, *args, **kwargs):
#         self.config_name = kwargs.pop('config_name', 'empty')
#         # Add Codemirror widget to the field
#         kwargs.update({'widget': CodeMirrorWidget})
# 
#         # Initialize widget with given config name if the field has been
#         # bounded.
#         widget = kwargs.get('widget', None) or self.widget
#         if isinstance(widget, type):
#             kwargs['widget'] = widget(config_name=self.config_name)
# 
#         super(CodeMirrorField, self).__init__(*args, **kwargs)
# 
# Path: tests/utils.py
# def assert_and_parse_html(html):
#     """
#     Shortand to use Django HTML parsing as object to use in assert
#     """
#     dom = parse_html(html)
#     return dom


import pytest
from djangocodemirror.fields import CodeMirrorField
from tests.utils import assert_and_parse_html
"""
Tests against form fields
"""




def test_field_basic():
    """Basic field usage"""
    field = CodeMirrorField(label="Foo", required=True,
                                  config_name="basic",
                                  initial='Hello World!')

    rendered = field.widget.render("foo", "bar")

    expected = ("""<textarea id="id_foo" name="foo" rows="10" cols="40">"""
                """bar</textarea>""")


# Path: djangocodemirror/fields.py
# class CodeMirrorField(forms.CharField):
#     """
#     A CharField that comes with CodeMirrorWidget.
# 
#     Arguments:
#         config_name (string): A Codemirror config name available in
#             ``settings.CODEMIRROR_SETTINGS``. Default is ``empty``.
#     """
#     def __init__(self, *args, **kwargs):
#         self.config_name = kwargs.pop('config_name', 'empty')
#         # Add Codemirror widget to the field
#         kwargs.update({'widget': CodeMirrorWidget})
# 
#         # Initialize widget with given config name if the field has been
#         # bounded.
#         widget = kwargs.get('widget', None) or self.widget
#         if isinstance(widget, type):
#             kwargs['widget'] = widget(config_name=self.config_name)
# 
#         super(CodeMirrorField, self).__init__(*args, **kwargs)
# 
# Path: tests/utils.py
# def assert_and_parse_html(html):
#     """
#     Shortand to use Django HTML parsing as object to use in assert
#     """
#     dom = parse_html(html)
#     return dom


# Path: tests/002_forms/test_002_fields.py
import pytest
from djangocodemirror.fields import CodeMirrorField
from tests.utils import assert_and_parse_html

"""
Tests against form fields
"""




def test_field_basic():
    """Basic field usage"""
    field = CodeMirrorField(label="Foo", required=True,
                                  config_name="basic",
                                  initial='Hello World!')

    rendered = field.widget.render("foo", "bar")

    expected = ("""<textarea id="id_foo" name="foo" rows="10" cols="40">"""
                """bar</textarea>""")


    assert assert_and_parse_html(rendered) == assert_and_parse_html(expected)