"""
Pytest feature: Parametrization
===============================

**Module:** ``tests.poc.test_parametrize_with_generator``

We are using a pytest feature heavily: Parametrization. These tests make sure this feature works still as expected.

Tests in this module run in a predefined order!
"""

from string import ascii_letters
from typing import Generator, List, Type

import pytest

from .conftest import CheapCounter


def data_generator() -> Generator[List[str], None, None]:
    """
    Helper method: Create Test Data, but keep them as a generator

    This helper is used by :meth:`~tests.poc.test_parametrize_with_generator.test_2_generator_parametrize`.

    :returns: A bunch of test data as generator
    """

    for val_a in ascii_letters[0:5]:
        for val_b in ascii_letters[5:10]:
            yield [val_a, val_b, f"{val_a}-{val_b}"]


@pytest.mark.order(1)
@pytest.mark.parametrize(
    ["val_a", "val_b", "val_c"],
    [
        ["a", "b", "a:b"],
        ["c", "d", "c:d"],
    ],
)
def test_1_simple_parametrize(val_a: str, val_b: str, val_c: str, cheap_counter: Type[CheapCounter]) -> None:
    """
    Test the simple parametrization from pytest.

    :param val_a: Test value A
    :param val_b: Test value B
    :param val_c: Test value C
    :param cheap_counter: Fixture :meth:`~tests.poc.conftest.cheap_counter`
    """

    assert f"{val_a}:{val_b}" == val_c
    cheap_counter.increment("simple")


@pytest.mark.order(2)
@pytest.mark.parametrize(
    ["val_a", "val_b", "val_c"],
    data_generator(),
)
def test_2_generator_parametrize(val_a: str, val_b: str, val_c: str, cheap_counter: Type[CheapCounter]) -> None:
    """
    Test the generator parametrization from pytest.

    :param val_a: Test value A
    :param val_b: Test value B
    :param val_c: Test value C
    :param cheap_counter: Fixture :meth:`~tests.poc.conftest.cheap_counter`
    """

    assert f"{val_a}-{val_b}" == val_c
    cheap_counter.increment("generator")


@pytest.mark.order(3)
def test_3_evaluation(cheap_counter: Type[CheapCounter]) -> None:
    """
    Evaluate the values of the :meth:`~tests.poc.conftest.cheap_counter` fixture.

    :param cheap_counter: Fixture :meth:`~tests.poc.conftest.cheap_counter`
    """

    assert cheap_counter.get_value("simple") == 2
    assert cheap_counter.get_value("generator") == 25
