def handle_init(args): """usage: cosmic-ray init <config-file> <session-file> Initialize a mutation testing session from a configuration. This primarily creates a session - a database of "work to be done" - which describes all of the mutations and test runs that need to be executed for a full mutation testing run. The configuration specifies the top-level module to mutate, the tests to run, and how to run them. This command doesn't actually run any tests. Instead, it scans the modules-under-test and simply generates the work order which can be executed with other commands. The `session-file` is the filename for the database in which the work order will be stored. """ config_file = args['<config-file>'] config = load_config(config_file) modules = set(cosmic_ray.modules.find_modules(Path(config['module-path']))) log.info('Modules discovered: %s', [m for m in modules]) db_name = get_db_name(args['<session-file>']) with use_db(db_name) as database: cosmic_ray.commands.init(modules, database, config) return ExitCode.OK
def handle_init(args): """usage: cosmic-ray init <config-file> <session-file> Initialize a mutation testing session from a configuration. This primarily creates a session - a database of "work to be done" - which describes all of the mutations and test runs that need to be executed for a full mutation testing run. The configuration specifies the top-level module to mutate, the tests to run, and how to run them. This command doesn't actually run any tests. Instead, it scans the modules-under-test and simply generates the work order which can be executed with other commands. The `session-file` is the filename for the database in which the work order will be stored. """ # This lets us import modules from the current directory. Should # probably be optional, and needs to also be applied to workers! sys.path.insert(0, '') config_file = args['<config-file>'] config = load_config(config_file) if 'timeout' in config: timeout = config['timeout'] elif 'baseline' in config: baseline_mult = config['baseline'] command = 'cosmic-ray baseline {}'.format(args['<config-file>']) # We run the baseline in a subprocess to more closely emulate the # runtime of a worker subprocess. with Timer() as timer: subprocess.check_call(command.split()) timeout = baseline_mult * timer.elapsed.total_seconds() else: raise ConfigValueError( "Config must specify either baseline or timeout") log.info('timeout = %f seconds', timeout) modules = set( cosmic_ray.modules.find_modules( cosmic_ray.modules.fixup_module_name(config['module']), config.get('exclude-modules', default=None))) log.info('Modules discovered: %s', [m.__name__ for m in modules]) db_name = get_db_name(args['<session-file>']) with use_db(db_name) as database: cosmic_ray.commands.init(modules, database, config, timeout) return ExitCode.OK
def handle_exec(args): """usage: cosmic-ray exec <session-file> Perform the remaining work to be done in the specified session. This requires that the rest of your mutation testing infrastructure (e.g. worker processes) are already running. """ session_file = get_db_name(args.get('<session-file>')) cosmic_ray.commands.execute(session_file) return ExitCode.OK
def handle_config(args): """usage: cosmic-ray config <session-file> Show the configuration for in a session. """ session_file = get_db_name(args['<session-file>']) with use_db(session_file) as database: config = database.get_config() print(serialize_config(config)) return ExitCode.OK
def handle_config(args): """usage: cosmic-ray config <session-file> Show the configuration for in a session. """ session_file = get_db_name(args['<session-file>']) with use_db(session_file) as database: config, _ = database.get_config() print(json.dumps(config)) return os.EX_OK
def handle_dump(args): """usage: cosmic-ray dump <session-file> JSON dump of session data. This output is typically run through other programs to produce reports. """ session_file = get_db_name(args['<session-file>']) with use_db(session_file, WorkDB.Mode.open) as database: for record in database.work_items: print(json.dumps(record)) return os.EX_OK
def handle_dump(args): """usage: cosmic-ray dump <session-file> JSON dump of session data. This output is typically run through other programs to produce reports. Each line of output is a list with two elements: a WorkItem and a WorkResult, both JSON-serialized. The WorkResult can be null, indicating a WorkItem with no results. """ session_file = get_db_name(args['<session-file>']) with use_db(session_file, WorkDB.Mode.open) as database: for work_item, result in database.completed_work_items: print(json.dumps((work_item, result), cls=WorkItemJsonEncoder)) for work_item in database.pending_work_items: print(json.dumps((work_item, None), cls=WorkItemJsonEncoder)) return ExitCode.OK