# Path: keras_image_captioning/config.py
# def active_config(new_active_config=None):
#     if new_active_config:
#         global _active_config
#         _active_config = new_active_config
#     return _active_config
# 
# class FileConfigBuilder(ConfigBuilderBase):
#     def __init__(self, yaml_path):
#         self._yaml_path = yaml_path
# 
#     def build_config(self):
#         with open(self._yaml_path) as yaml_file:
#             config_dict = yaml.load(yaml_file)
# 
#         # For backward compatibility
#         for field in Config._fields:
#             config_dict.setdefault(field, None)
# 
#         config_dict['time_limit'] = parse_timedelta(config_dict['time_limit'])
#         return Config(**config_dict)
# 
# Path: keras_image_captioning/io_utils.py
# def path_from_var_dir(*paths):
#     return os.path.join(_VAR_ROOT_DIR, *paths)
# 
# Path: keras_image_captioning/hyperparam_search.py
# class HyperparamSearch(object):
# class TrainingCommand(object):
#     def __init__(self,
#                  training_label_prefix,
#                  dataset_name=None,
#                  epochs=None,
#                  time_limit=None,
#                  num_gpus=None):
#     def training_label_prefix(self):
#     def num_gpus(self):
#     def running_commands(self):
#     def lock(self):
#     def run(self):
#     def stop(self):
#     def training_label(self, search_index):
#     def _validate_training_label_prefix(self):
#     def _create_done_callback(self, gpu_index):
#         def done_callback(cmd, success, exit_code):
#     def _remove_finished_commands(self):
#     def _wait_running_commands(self):
#     def __init__(self,
#                  training_label,
#                  config,
#                  gpu_index,
#                  background=False,
#                  done_callback=None):
#     def training_label(self):
#     def config(self):
#     def gpu_index(self):
#     def config_filepath(self):
#     def execute(self):
#     def _init_config_filepath(self):
#     def _init_log_filepath(self):
# def main(training_label_prefix,
#          dataset_name=None,
#          epochs=None,
#          time_limit=None,
#          num_gpus=None):
#     def handler(signum, frame):
#     COMMAND = sh.python.bake('-m', 'keras_image_captioning.training')
#         LOG_FILENAME = 'training-log.txt'


import os
import pytest
import sh
import shutil
from .config import active_config, FileConfigBuilder
from .io_utils import path_from_var_dir
from .hyperparam_search import (itertools, main, HyperparamSearch,
                                TrainingCommand)
            finished.append(True)

        training_command._done_callback = done_callback

        if DRY_RUN:
            training_command._config_filepath = NOT_EXISTING_PATH
            running_command = training_command.execute()
            with pytest.raises(sh.ErrorReturnCode_1):
                running_command.wait()
        else:
            running_command = training_command.execute()
            running_command.wait()

        assert len(finished) == 1 and finished[0]

    def test__init_config_filepath(self, training_command, config_used):
        training_command._init_config_filepath()
        config_builder = FileConfigBuilder(training_command._config_filepath)
        config = config_builder.build_config()
        assert config == config_used

    def test__init_log_filepath(self, training_command):
        training_command._init_log_filepath()
        assert training_command._log_filepath.find(
                                        training_command.training_label) != -1


@pytest.mark.usefixtures('clean_up_training_result_dir')
def test_main(mocker):
    if DRY_RUN:

# Path: keras_image_captioning/config.py
# def active_config(new_active_config=None):
#     if new_active_config:
#         global _active_config
#         _active_config = new_active_config
#     return _active_config
# 
# class FileConfigBuilder(ConfigBuilderBase):
#     def __init__(self, yaml_path):
#         self._yaml_path = yaml_path
# 
#     def build_config(self):
#         with open(self._yaml_path) as yaml_file:
#             config_dict = yaml.load(yaml_file)
# 
#         # For backward compatibility
#         for field in Config._fields:
#             config_dict.setdefault(field, None)
# 
#         config_dict['time_limit'] = parse_timedelta(config_dict['time_limit'])
#         return Config(**config_dict)
# 
# Path: keras_image_captioning/io_utils.py
# def path_from_var_dir(*paths):
#     return os.path.join(_VAR_ROOT_DIR, *paths)
# 
# Path: keras_image_captioning/hyperparam_search.py
# class HyperparamSearch(object):
# class TrainingCommand(object):
#     def __init__(self,
#                  training_label_prefix,
#                  dataset_name=None,
#                  epochs=None,
#                  time_limit=None,
#                  num_gpus=None):
#     def training_label_prefix(self):
#     def num_gpus(self):
#     def running_commands(self):
#     def lock(self):
#     def run(self):
#     def stop(self):
#     def training_label(self, search_index):
#     def _validate_training_label_prefix(self):
#     def _create_done_callback(self, gpu_index):
#         def done_callback(cmd, success, exit_code):
#     def _remove_finished_commands(self):
#     def _wait_running_commands(self):
#     def __init__(self,
#                  training_label,
#                  config,
#                  gpu_index,
#                  background=False,
#                  done_callback=None):
#     def training_label(self):
#     def config(self):
#     def gpu_index(self):
#     def config_filepath(self):
#     def execute(self):
#     def _init_config_filepath(self):
#     def _init_log_filepath(self):
# def main(training_label_prefix,
#          dataset_name=None,
#          epochs=None,
#          time_limit=None,
#          num_gpus=None):
#     def handler(signum, frame):
#     COMMAND = sh.python.bake('-m', 'keras_image_captioning.training')
#         LOG_FILENAME = 'training-log.txt'


# Path: keras_image_captioning/hyperparam_search_test.py
import os
import pytest
import sh
import shutil
from .config import active_config, FileConfigBuilder
from .io_utils import path_from_var_dir
from .hyperparam_search import (itertools, main, HyperparamSearch,
                                TrainingCommand)

            finished.append(True)

        training_command._done_callback = done_callback

        if DRY_RUN:
            training_command._config_filepath = NOT_EXISTING_PATH
            running_command = training_command.execute()
            with pytest.raises(sh.ErrorReturnCode_1):
                running_command.wait()
        else:
            running_command = training_command.execute()
            running_command.wait()

        assert len(finished) == 1 and finished[0]

    def test__init_config_filepath(self, training_command, config_used):
        training_command._init_config_filepath()
        config_builder = FileConfigBuilder(training_command._config_filepath)
        config = config_builder.build_config()
        assert config == config_used

    def test__init_log_filepath(self, training_command):
        training_command._init_log_filepath()
        assert training_command._log_filepath.find(
                                        training_command.training_label) != -1


@pytest.mark.usefixtures('clean_up_training_result_dir')
def test_main(mocker):
    if DRY_RUN:

        mocker.patch.object(TrainingCommand, 'config_filepath',