import pytest
import pygal
from pygal.etree import etree
from . import get_data


@pytest.fixture
def etreefx(request):
    if request.param == 'etree':
        etree.to_etree()
    if request.param == 'lxml':
        etree.to_lxml()


def pytest_generate_tests(metafunc):
    if etree._lxml_etree:
        metafunc.fixturenames.append('etreefx')
        metafunc.parametrize('etreefx', ['lxml', 'etree'], indirect=True)

    if "Chart" in metafunc.funcargnames:
        metafunc.parametrize("Chart", pygal.CHARTS)
    if "datas" in metafunc.funcargnames:
        metafunc.parametrize(
            "datas",
            [
                [("Serie %d" % i, get_data(i)) for i in range(s)]
                for s in (5, 1, 0)
            ])
