import pytest
from pytest import mark, raises
from bottle import template

@mark.parametrize('expected, params', [
    ("""<div class="pure-u-1">
<label for="select-id">Choose: </label>
<select id="select-id" name="select-name" size="10" multiple="true" style="width: calc(100% - 1em); margin: 0 1em 1em">
  <option value="hint" disabled="true" >hint</option>
<optgroup label="Group">
  <option value="val1-to-backend"  >val1</option>
  <option value="val2" disabled="true" >val2</option>
</optgroup>
</select>
</div>""", {
    "id": "select-id", "label": "Choose: ", "name": "select-name",
    "hint": "hint", "multiple": True, "children": [{"optgroup": "Group", "options": [
    {
        "value": "val1-to-backend",
        "display": "val1",
    },
    {
        "value": "val2",
        "disabled": True,
    }, ]}, ]}),
    ("""<div class="pure-u-1">

<select id="select-unit-id" name="unit" size="10"  style="width: calc(100% - 1em); margin: 0 1em 1em">


  <option value="val1"  >val1</option>
  <option value="val2"  selected="true">val2</option>
</select>
</div>""",{
    "id": "select-unit-id", "name": "unit", "children": [{ "options": [
    {
        "value": "val1",
    },
    {
        "value": "val2",
        "selected": True,
    }, ]}, ]}),
    ("""<div class="pure-u-1">
<label for="select-id">Choose: </label>
<select id="select-id" name="select-name" size="10" multiple="true" style="width: calc(100% - 1em); margin: 0 1em 1em">
  <option value="hint" disabled="true" >hint</option>
<optgroup label="Group">
  <option value="val1-to-backend"  >val1</option>
  <option value="val2" disabled="true" >val2</option>
</optgroup>

  <option value="val1"  >val1</option>
  <option value="val2"  selected="true">val2</option>
</select>
</div>""",{
    "id": "select-id", "label": "Choose: ", "name": "select-name",
    "hint": "hint", "multiple": True, "children": [
        {"optgroup": "Group", "options": [
            {
                "value": "val1-to-backend",
                "display": "val1",
            },
            {
                "value": "val2",
                "disabled": True,
            }
        ]},
        { "options": [
            {
                "value": "val1",
            },
            {
                "value": "val2",
                "selected": True,
            },
        ]},
    ]})
])
def test_select_render_exact(expected, params):
    assert template('select', **params) == expected
