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_init(configuration): """usage: cosmic-ray init [options] [--exclude-modules=P ...] (--timeout=T | --baseline=M) <session-name> <top-module> [-- <test-args> ...] Initialize a mutation testing run. The primarily creates 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 testing run will mutate <top-module> (and submodules) using the tests in <test-dir>. This 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-name argument identifies the run you're creating. Its most important role is that it's used to name the database file. options: --no-local-import Allow importing module from the current directory --test-runner=R Test-runner plugin to use [default: unittest] --exclude-modules=P Pattern of module names to exclude from mutation """ # 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, '') if configuration['--timeout'] is not None: timeout = float(configuration['--timeout']) else: baseline_mult = float(configuration['--baseline']) assert baseline_mult is not None with Timer() as t: handle_baseline(configuration) timeout = baseline_mult * t.elapsed.total_seconds() LOG.info('timeout = %f seconds', timeout) modules = set( cosmic_ray.modules.find_modules( cosmic_ray.modules.fixup_module_name( configuration['<top-module>']), configuration['--exclude-modules'])) LOG.info('Modules discovered: %s', [m.__name__ for m in modules]) db_name = _get_db_name(configuration['<session-name>']) with use_db(db_name) as db: cosmic_ray.commands.init(modules, db, configuration['--test-runner'], configuration['<test-args>'], timeout)