def test_small_directory_tree(self): paths = [['a', '__init__.py'], ['a', 'b.py'], ['a', 'c', '__init__.py'], ['a', 'c', 'd.py']] paths = [ os.path.abspath(os.path.join(self.root, *path)) for path in paths ] [make_file(p) for p in paths] results = find_modules('a') self.assertListEqual(sorted(paths), sorted(map(lambda m: m.__file__, results)))
def test_small_directory_tree(self): paths = [['a', '__init__.py'], ['a', 'b.py'], ['a', 'c', '__init__.py'], ['a', 'c', 'd.py']] paths = [os.path.abspath(os.path.join(self.root, *path)) for path in paths] [make_file(p) for p in paths] results = find_modules('a') self.assertListEqual( sorted(paths), sorted(map(lambda m: m.__file__, results)))
def handle_run(configuration): """usage: cosmic-ray run [options] [--exclude-modules=P ...] (--timeout=T | --baseline=M) <top-module> <test-dir> options: --verbose Produce verbose output --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 --num-testers=N Number of concurrent testers to run (0 = os.cpu_count()) [default: 0] """ test_runner = plugins.test_runner( configuration['--test-runner'], configuration['<test-dir>']) if configuration['--timeout'] is not None: timeout = float(configuration['--timeout']) else: baseline_mult = float(configuration['--baseline']) assert baseline_mult is not None timeout = config.find_baseline(test_runner) * baseline_mult LOG.info('timeout = {} seconds'.format(timeout)) num_testers = config.get_num_testers(int(configuration['--num-testers'])) if not configuration['--no-local-import']: sys.path.insert(0, '') modules = config.filtered_modules( find_modules(configuration['<top-module>']), configuration['--exclude-modules']) operators = cosmic_ray.operators.all_operators() mutation_records = mutating.create_mutants(modules, operators) summarizer = Summarizer() cosmic_ray.processing.test_mutants( mutation_records, test_runner, num_testers, timeout, summarizer) total_count = sum(summarizer.outcomes.values()) if total_count > 0: print('Survival rate: {:0.2f}%'.format( 100 * summarizer.outcomes[Outcome.SURVIVED] / total_count)) else: print('No tests run (no mutations generated).') # pylint:disable=superfluous-parens
def handle_run(configuration): """usage: cosmic-ray run [options] [--exclude-modules=P ...] (--timeout=T | --baseline=M) <top-module> <test-dir> options: --verbose Produce verbose output --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 --num-testers=N Number of concurrent testers to run (0 = os.cpu_count()) [default: 0] """ test_runner = plugins.test_runner(configuration['--test-runner'], configuration['<test-dir>']) if configuration['--timeout'] is not None: timeout = float(configuration['--timeout']) else: baseline_mult = float(configuration['--baseline']) assert baseline_mult is not None timeout = config.find_baseline(test_runner) * baseline_mult LOG.info('timeout = {} seconds'.format(timeout)) num_testers = config.get_num_testers(int(configuration['--num-testers'])) if not configuration['--no-local-import']: sys.path.insert(0, '') modules = config.filtered_modules( find_modules(configuration['<top-module>']), configuration['--exclude-modules']) operators = cosmic_ray.operators.all_operators() mutation_records = mutating.create_mutants(modules, operators) summarizer = Summarizer() cosmic_ray.processing.test_mutants(mutation_records, test_runner, num_testers, timeout, summarizer) total_count = sum(summarizer.outcomes.values()) if total_count > 0: print('Survival rate: {:0.2f}%'.format( 100 * summarizer.outcomes[Outcome.SURVIVED] / total_count)) else: print('No tests run (no mutations generated).') # pylint:disable=superfluous-parens