# 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 tests.common import DummyPostData
from wtforms import validators
from wtforms.fields import SelectField
from wtforms.fields import SelectMultipleField
from wtforms.form import Form



def make_form(name="F", **fields):
    return type(str(name), (Form,), fields)


class F(Form):
    a = SelectMultipleField(
        choices=[("a", "hello"), ("b", "bye"), ("c", "something")], default=("a",)
    )
    b = SelectMultipleField(
        coerce=int, choices=[(1, "A"), (2, "B"), (3, "C")], default=("1", "3")
    )


def test_defaults():
    form = F()
    assert form.a.data == ["a"]
    assert form.b.data == [1, 3]
    # Test for possible regression with null data
    form.a.data = None
    assert form.validate()
    assert list(form.a.iter_choices()) == [(v, l, False) for v, l in form.a.choices]


def test_with_data():

# 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_selectmultiple.py
import pytest
from tests.common import DummyPostData
from wtforms import validators
from wtforms.fields import SelectField
from wtforms.fields import SelectMultipleField
from wtforms.form import Form




def make_form(name="F", **fields):
    return type(str(name), (Form,), fields)


class F(Form):
    a = SelectMultipleField(
        choices=[("a", "hello"), ("b", "bye"), ("c", "something")], default=("a",)
    )
    b = SelectMultipleField(
        coerce=int, choices=[(1, "A"), (2, "B"), (3, "C")], default=("1", "3")
    )


def test_defaults():
    form = F()
    assert form.a.data == ["a"]
    assert form.b.data == [1, 3]
    # Test for possible regression with null data
    form.a.data = None
    assert form.validate()
    assert list(form.a.iter_choices()) == [(v, l, False) for v, l in form.a.choices]


def test_with_data():

    form = F(DummyPostData(a=["a", "c"]))