# Path: yatsm/cli/main.py
# @click_plugins.with_plugins(ep for ep in
#                             iter_entry_points('yatsm.cli'))
# @click.group(help='YATSM command line interface', context_settings=_context)
# @click.version_option(yatsm.__version__)
# @click.option('--num_threads', metavar='<threads>', default=1, type=int,
#               show_default=True, callback=options.valid_int_gt_zero,
#               help='Number of threads for OPENBLAS/MKL/OMP used in NumPy')
# @click.option('--verbose', '-v', is_flag=True, help='Be verbose')
# @click.option('--verbose-yatsm', is_flag=True,
#               help='Show verbose debugging messages in YATSM algorithm')
# @click.option('--quiet', '-q', is_flag=True, help='Be quiet')
# @click.pass_context
# def cli(ctx, num_threads, verbose, verbose_yatsm, quiet):
#     # Logging config
#     if verbose:
#         logger.setLevel(logging.DEBUG)
#     if verbose_yatsm:
#         logger_algo.setLevel(logging.DEBUG)
#     if quiet:
#         logger.setLevel(logging.WARNING)
#         logger_algo.setLevel(logging.WARNING)


import os
import numpy as np
from click.testing import CliRunner
from yatsm.cli.main import cli
def test_classify_pass_1(example_timeseries, example_results, modify_config):
    """ Correctly run classification script
    """
    mod_cfg = {'dataset': {'output': example_results['results_dir']}}
    with modify_config(example_timeseries['config'], mod_cfg) as cfg:
        runner = CliRunner()
        result = runner.invoke(
            cli, [
                '-v', 'classify',
                cfg,
                example_results['example_classify_pickle'],
                '1', '1'
            ]
        )
        assert result.exit_code == 0
        # Try opening & check that classes are in the files
        for result in os.listdir(example_results['results_dir']):
            z = np.load(os.path.join(example_results['results_dir'], result))
            assert 'classes' in z.files
            assert 'class' in z['record'].dtype.names


def test_classify_pass_2(example_timeseries, example_results, modify_config):
    """ Correctly run classification script with --resume option
    """
    mod_cfg = {'dataset':
               {'output': example_results['results_dir_classified']}}
    with modify_config(example_timeseries['config'], mod_cfg) as cfg:
        runner = CliRunner()
        result = runner.invoke(

# Path: yatsm/cli/main.py
# @click_plugins.with_plugins(ep for ep in
#                             iter_entry_points('yatsm.cli'))
# @click.group(help='YATSM command line interface', context_settings=_context)
# @click.version_option(yatsm.__version__)
# @click.option('--num_threads', metavar='<threads>', default=1, type=int,
#               show_default=True, callback=options.valid_int_gt_zero,
#               help='Number of threads for OPENBLAS/MKL/OMP used in NumPy')
# @click.option('--verbose', '-v', is_flag=True, help='Be verbose')
# @click.option('--verbose-yatsm', is_flag=True,
#               help='Show verbose debugging messages in YATSM algorithm')
# @click.option('--quiet', '-q', is_flag=True, help='Be quiet')
# @click.pass_context
# def cli(ctx, num_threads, verbose, verbose_yatsm, quiet):
#     # Logging config
#     if verbose:
#         logger.setLevel(logging.DEBUG)
#     if verbose_yatsm:
#         logger_algo.setLevel(logging.DEBUG)
#     if quiet:
#         logger.setLevel(logging.WARNING)
#         logger_algo.setLevel(logging.WARNING)


# Path: tests/cli/test_classify.py
import os
import numpy as np
from click.testing import CliRunner
from yatsm.cli.main import cli

def test_classify_pass_1(example_timeseries, example_results, modify_config):
    """ Correctly run classification script
    """
    mod_cfg = {'dataset': {'output': example_results['results_dir']}}
    with modify_config(example_timeseries['config'], mod_cfg) as cfg:
        runner = CliRunner()
        result = runner.invoke(
            cli, [
                '-v', 'classify',
                cfg,
                example_results['example_classify_pickle'],
                '1', '1'
            ]
        )
        assert result.exit_code == 0
        # Try opening & check that classes are in the files
        for result in os.listdir(example_results['results_dir']):
            z = np.load(os.path.join(example_results['results_dir'], result))
            assert 'classes' in z.files
            assert 'class' in z['record'].dtype.names


def test_classify_pass_2(example_timeseries, example_results, modify_config):
    """ Correctly run classification script with --resume option
    """
    mod_cfg = {'dataset':
               {'output': example_results['results_dir_classified']}}
    with modify_config(example_timeseries['config'], mod_cfg) as cfg:
        runner = CliRunner()
        result = runner.invoke(

            cli, [