#!/usr/bin/env python3 -u
# coding: utf-8

__author__ = ["mloning"]
__all__ = []

import numpy as np
import pytest

from sktime.base import BaseEstimator
from sktime.classification.base import BaseClassifier
from sktime.forecasting.base import BaseForecaster

from base_package.registry import get_estimators
import pandas as pd


class BaseEstimatorTestCollection:
    """"""

    def test_interface(self, estimator_class):
        assert hasattr(estimator_class, "fit") and callable(estimator_class.fit)


class ClassifierTestCollection:

    def test_fit(self, estimator_instance):
        X = np.random.normal(size=(5, 1, 10))
        y = np.random.choice([0, 1], size=(5,))
        assert estimator_instance.fit(X, y) is estimator_instance


class ForecasterTestCollection:

    def test_fit(self, estimator_instance):
        y = pd.Series(np.arange(10))
        assert estimator_instance.fit(y, fh=1) is estimator_instance


def configure_pytest_generate_tests(estimator_types=None):

    def pytest_generate_tests(metafunc):
        """Test parameterization routine for pytest.

        Fixtures parameterized
        ----------------------
        estimator_class: estimator inheriting from BaseObject
            ranges over all estimator classes not excluded by EXCLUDED_TESTS
        estimator_instance: instance of estimator inheriting from BaseObject
            ranges over all estimator classes not excluded by EXCLUDED_TESTS
            instances are generated by create_test_instance class method
        """
        estimator_classes = get_estimators(
            estimator_types=estimator_types, return_names=False)

        if "estimator_class" in metafunc.fixturenames:
            metafunc.parametrize("estimator_class", estimator_classes)

        # if estimator test, construct all instances for the test
        if "estimator_instance" in metafunc.fixturenames:
            estimator_instances = [estimator.create_test_instance()
                                   for estimator in estimator_classes]
            metafunc.parametrize("estimator_instance", estimator_instances)

    return pytest_generate_tests
