# Path: yatsm/config_parser.py
# def parse_config_file(config_file):
# def convert_config(cfg):
# def _parse_dataset_config(cfg):
# def _parse_YATSM_config(cfg):
# def _find_pickle(pickle, cfg):
# def _unpickle_predictor(pickle):
# def expand_envvars(d):
#     def check_envvar(k, v):
# 
# Path: yatsm/regression/packaged.py
# def find_packaged_regressor(name):


import os
import pytest
from yatsm import config_parser
from yatsm.regression.packaged import packaged_regressions


# YATSM: SECTION PARSING
@pytest.fixture(scope='function')
def YATSM_cfg(request):
    cfg = {
        'YATSM': {
            'prediction': packaged_regressions[0],
            'refit': {
                'prefix': [reg for reg in packaged_regressions],
                'prediction': [reg for reg in packaged_regressions]
            }
        }
    }
    return cfg


def test_parse_YATSM_config_1(YATSM_cfg):
    """ Test retrieval of packaged estimators
    """
    for estimator in packaged_regressions:
        YATSM_cfg['YATSM']['prediction'] = estimator
        config_parser._parse_YATSM_config(YATSM_cfg)


def test_parse_YATSM_config_2(YATSM_cfg):
    """ Test retrieval of packaged estimators that don't exist
    """
    with pytest.raises(KeyError):
        YATSM_cfg['YATSM']['prediction'] = 'not_an_estimator'

# Path: yatsm/config_parser.py
# def parse_config_file(config_file):
# def convert_config(cfg):
# def _parse_dataset_config(cfg):
# def _parse_YATSM_config(cfg):
# def _find_pickle(pickle, cfg):
# def _unpickle_predictor(pickle):
# def expand_envvars(d):
#     def check_envvar(k, v):
# 
# Path: yatsm/regression/packaged.py
# def find_packaged_regressor(name):


# Path: tests/test_config_parser.py
import os
import pytest
from yatsm import config_parser
from yatsm.regression.packaged import packaged_regressions



# YATSM: SECTION PARSING
@pytest.fixture(scope='function')
def YATSM_cfg(request):
    cfg = {
        'YATSM': {
            'prediction': packaged_regressions[0],
            'refit': {
                'prefix': [reg for reg in packaged_regressions],
                'prediction': [reg for reg in packaged_regressions]
            }
        }
    }
    return cfg


def test_parse_YATSM_config_1(YATSM_cfg):
    """ Test retrieval of packaged estimators
    """
    for estimator in packaged_regressions:
        YATSM_cfg['YATSM']['prediction'] = estimator
        config_parser._parse_YATSM_config(YATSM_cfg)


def test_parse_YATSM_config_2(YATSM_cfg):
    """ Test retrieval of packaged estimators that don't exist
    """
    with pytest.raises(KeyError):
        YATSM_cfg['YATSM']['prediction'] = 'not_an_estimator'

        config_parser._parse_YATSM_config(YATSM_cfg)