def create_test_suite(self, mutant_module): suite = unittest.TestSuite() utils.InjectImporter(mutant_module).install() self.remove_loaded_modules() for test_module, target_test in self.test_loader.load(): suite.addTests(self.get_test_suite(test_module, target_test)) utils.InjectImporter.uninstall() return suite
def create_test_suite(self, mutant_module): if not issubclass(self.test_suite_cls, BaseTestSuite): raise ValueError('{0} is not a subclass of {1}'.format(self.test_suite_cls, BaseTestSuite)) suite = self.create_empty_test_suite() injector = utils.ModuleInjector(mutant_module) for test_module, target_test in self.test_loader.load(): injector.inject_to(test_module) suite.add_tests(test_module, target_test) importer = utils.InjectImporter(mutant_module) importer.install() return suite
def create_test_suite(self, mutant_module): if not issubclass(self.test_suite_cls, BaseTestSuite): raise ValueError('{0} is not a subclass of {1}'.format( self.test_suite_cls, BaseTestSuite)) suite = self.create_empty_test_suite() utils.InjectImporter(mutant_module).install() self.remove_loaded_modules() for test_module, target_test in self.test_loader.load(): suite.add_tests(test_module, target_test) utils.InjectImporter.uninstall() return suite
def test_inject(self): target_module_content = utils.f(""" def x(): import source return source """) target_module = types.ModuleType('target') source_module_before = types.ModuleType('source') source_module_before.__file__ = 'source.py' source_module_after = types.ModuleType('source') sys.modules['source'] = source_module_before importer = utils.InjectImporter(source_module_after) eval(compile(target_module_content, 'target.py', 'exec'), target_module.__dict__) importer.install() source_module = target_module.x() self.assertEqual(source_module, source_module_after) self.assertEqual(source_module.__loader__, importer) del sys.modules['source'] importer.uninstall()