def test_load_file(self):
     path = os.path.abspath(__file__)
     args = {'required_param': 'yes', 'dummy': 1}
     loader = ExperimentLoader(experiment_args=args)
     experiments, commands = loader.load_from_file(path)
     self.assertEqual(len(experiments), 3)
     e_names = set(map(lambda e: e.id, experiments))
     self.assertEqual(
         e_names,
         set(['experiment_1', 'experiment_1_yes', 'experiment_2_yes']))
示例#2
0
def run(runner, commands, experiment_module, dry_run, skip_file_check, arg,
        prefix, methods, path, filters, rerun, tempdir, splits):
    """Run Raster Vision commands from experiments, using the
    experiment runner named RUNNER."""

    if tempdir:
        RVConfig.set_tmp_dir(tempdir)

    # Validate runner
    valid_runners = list(
        map(lambda x: x.lower(), rv.ExperimentRunner.list_runners()))
    if runner not in valid_runners:
        print_error('Invalid experiment runner: "{}". '
                    'Must be one of: "{}"'.format(runner,
                                                  '", "'.join(valid_runners)))
        sys.exit(1)

    runner = ExperimentRunner.get_runner(runner)

    if experiment_module and path:
        print_error('Must specify only one of experiment_module or path')
        sys.exit(1)

    if not commands:
        commands = rv.all_commands()
    else:
        commands = list(map(lambda x: x.upper(), commands))

    experiment_args = {}
    for k, v in arg:
        experiment_args[k] = v

    loader = ExperimentLoader(experiment_args=experiment_args,
                              experiment_method_prefix=prefix,
                              experiment_method_patterns=methods,
                              experiment_name_patterns=filters)
    try:
        if experiment_module:
            experiments, command_configs = loader.load_from_module(
                experiment_module)
        elif path:
            experiments, command_configs = loader.load_from_file(path)
        else:
            experiments, command_configs = loader.load_from_module('__main__')
    except LoaderError as e:
        print_error(str(e))
        sys.exit(1)

    if not experiments and not commands:
        if experiment_module:
            print_error(
                'No experiments found in {}.'.format(experiment_module))
        elif path:
            print_error('No experiments found in {}.'.format(path))
        else:
            print_error('No experiments found.')

    runner.run(experiments,
               command_configs=command_configs,
               commands_to_run=commands,
               rerun_commands=rerun,
               skip_file_check=skip_file_check,
               dry_run=dry_run,
               splits=splits)