# Path: tests/common.py
# class DummyPostData(dict):
#     def getlist(self, key):
#         v = self[key]
#         if not isinstance(v, (list, tuple)):
#             v = [v]
#         return v


import pytest
from markupsafe import Markup
from tests.common import DummyPostData
from wtforms import meta
from wtforms import validators
from wtforms.fields import Field
from wtforms.fields import StringField
from wtforms.form import Form
def test_check_validators():
    v1 = "Not callable"
    v2 = validators.DataRequired

    with pytest.raises(
        TypeError,
        match=fr"{v1} is not a valid validator because it is not callable",
    ):
        Field(validators=[v1])

    with pytest.raises(
        TypeError,
        match=r"{} is not a valid validator because "
        "it is a class, it should be an "
        "instance".format(v2),
    ):
        Field(validators=[v2])


def test_custom_name():
    class F(Form):
        foo = StringField(name="bar", default="default")
        x = StringField()

    class ObjFoo:
        foo = "obj"

    class ObjBar:
        bar = "obj"


# Path: tests/common.py
# class DummyPostData(dict):
#     def getlist(self, key):
#         v = self[key]
#         if not isinstance(v, (list, tuple)):
#             v = [v]
#         return v


# Path: tests/fields/test_field.py
import pytest
from markupsafe import Markup
from tests.common import DummyPostData
from wtforms import meta
from wtforms import validators
from wtforms.fields import Field
from wtforms.fields import StringField
from wtforms.form import Form

def test_check_validators():
    v1 = "Not callable"
    v2 = validators.DataRequired

    with pytest.raises(
        TypeError,
        match=fr"{v1} is not a valid validator because it is not callable",
    ):
        Field(validators=[v1])

    with pytest.raises(
        TypeError,
        match=r"{} is not a valid validator because "
        "it is a class, it should be an "
        "instance".format(v2),
    ):
        Field(validators=[v2])


def test_custom_name():
    class F(Form):
        foo = StringField(name="bar", default="default")
        x = StringField()

    class ObjFoo:
        foo = "obj"

    class ObjBar:
        bar = "obj"


    f = F(DummyPostData(foo="data"))