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


from tests.common import DummyPostData
from wtforms.fields import StringField
from wtforms.form import Form



class F(Form):
    a = StringField(default=" hello", filters=[lambda x: x.strip()])
    b = StringField(default="42", filters=[int, lambda x: -x])


def test_working():
    form = F()
    assert form.a.data == "hello"
    assert form.b.data == -42
    assert form.validate()


def test_failure():

# 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_filters.py
from tests.common import DummyPostData
from wtforms.fields import StringField
from wtforms.form import Form




class F(Form):
    a = StringField(default=" hello", filters=[lambda x: x.strip()])
    b = StringField(default="42", filters=[int, lambda x: -x])


def test_working():
    form = F()
    assert form.a.data == "hello"
    assert form.b.data == -42
    assert form.validate()


def test_failure():

    form = F(DummyPostData(a=["  foo bar  "], b=["hi"]))