Пример #1
0
 def current_progress(self, tmp_path, test_config, test_progress):
     paths.OUTPUT_DIR = tmp_path.as_posix()
     progress = Progress(config_file=test_config,
                         progress_file=test_progress,
                         load_progress=True)
     progress.progress_xml_file = op.join(paths.OUTPUT_DIR, "progress.xml")
     copyfile(test_progress, progress.progress_xml_file)
     return progress
Пример #2
0
def set_progress(args):
    config_file = op.abspath(args['file'])
    if not args.get('progress') is None:
        progress = Progress(progress_file=args['progress'], config_file=config_file, load_progress=True)
        log_dir = progress.get_output_dir()
    else:
        log_dir = op.join(op.dirname(config_file), 'output/%s/' % time.strftime('%Y.%m.%d_%H%M%S'))
        progress = None
    return progress, log_dir
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('file')
    parser.add_argument('--progress', default=argparse.SUPPRESS)
    args = vars(parser.parse_args())

    config_file = op.abspath(args['file'])
    paths.CONFIG_DIR = op.dirname(config_file)
    paths.ORIGINAL_CONFIG_DIR = config_file
    if 'progress' in args:
        progress = Progress(progress_file=args['progress'], config_file=config_file, load_progress=True)
        log_dir = progress.get_output_dir()
    else:
        log_dir = op.join(paths.CONFIG_DIR, 'output/%s/' % time.strftime('%Y.%m.%d_%H%M%S'))
        progress = None

    makedirs(log_dir)
    paths.OUTPUT_DIR = log_dir
    paths.BASE_OUTPUT_DIR = log_dir
    log_filename = op.join(log_dir, 'experiment.log')

    logger = logging.getLogger()
    logger.setLevel(logging.DEBUG)

    file_logger = logging.FileHandler(log_filename)
    file_logger.setLevel(logging.DEBUG)
    file_logger.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s:%(message)s'))
    logger.addHandler(file_logger)

    stdout_logger = logging.StreamHandler(sys.stdout)
    stdout_logger.setLevel(logging.INFO)
    stdout_logger.setFormatter(logging.Formatter('%(name)s: %(message)s'))
    logger.addHandler(stdout_logger)

    sys.path.append(op.join(paths.ROOT_DIR, 'ExperimentRunner'))
    progress_file = ' No progress file created'
    try:
        experiment = ExperimentFactory.from_json(config_file, progress)
        progress_file = experiment.get_progress_xml_file()
        experiment.start()
    except Exception, e:
        logger.error('%s: %s' % (e.__class__.__name__, e.message))
        logger.error('An error occurred, the experiment has been stopped. '
                     'To continue, add progress file argument to experiment startup: '
                     '--progress {}'.format(progress_file))
Пример #4
0
 def test_progress_init_resume(self, check_hash_mock, tmp_path, test_config,
                               test_progress):
     check_hash_mock.return_value = None
     progress = Progress(config_file=test_config,
                         progress_file=test_progress,
                         load_progress=True)
     with open(test_progress, 'r') as f:
         expected_xml = f.read()
     expected_lxml = et.fromstring(expected_xml)
     current_lxml = progress.progress_xml_content
     assert self.elements_equal(current_lxml, expected_lxml)
Пример #5
0
    def test_progress_init(self, build_progress_mock, write_to_file_mock,
                           tmp_path, test_config, test_progress):
        with open(test_progress, 'r') as f:
            expected_xml = f.read()
        paths.OUTPUT_DIR = tmp_path.as_posix()
        build_progress_mock.return_value = et.fromstring(expected_xml)
        mock_manager = Mock()
        mock_manager.attach_mock(build_progress_mock, 'managed_build_progress')
        mock_manager.attach_mock(write_to_file_mock, 'managed_write_to_file')

        progress = Progress(config_file=test_config,
                            config=load_json(test_config))

        expected_calls = [
            call.managed_build_progress(load_json(test_config), test_config),
            call.managed_write_to_file()
        ]
        assert mock_manager.mock_calls == expected_calls
        expected_lxml = et.fromstring(expected_xml)
        current_lxml = progress.progress_xml_content
        assert self.elements_equal(current_lxml, expected_lxml)