def test_prepare_environment_throws_exception_when_cannot_run_maven(self): module_desc = BundledPluginsModulesDescription(False, self.plugins_utility, self.maven_creator) self.maven.__class__.__call__ = types.MethodType( lambda ignore, _: self.maven.executed() or 1, self.maven) self.assertRaises(MavenExecutionException, module_desc.prepare_environment, self.logger)
def test_prepare_environment_without_bundled_plugins_list_packages_project( self): self.plugins_utility.expect_bundled_plugins_list_ok([], toReturn=False) module_desc = BundledPluginsModulesDescription(False, self.plugins_utility, self.maven_creator) # when module_desc.prepare_environment(self.logger) # then self.assertTrue(self.maven.verify_executed(), 'Expected maven have been executed')
def test_prepare_environment_with_bundled_plugins_list_skips_packaging( self): # having module_desc = BundledPluginsModulesDescription(False, self.plugins_utility, self.maven_creator) self.plugins_utility.expect_bundled_plugins_list_ok([], toReturn=True) # when module_desc.prepare_environment(self.logger) # then self.assertFalse(self.maven.verify_executed(), 'Maven should not be called')
def test_checks_are_not_run_when_fast_mode_and_no_bp_list(self): #having self.plugins_utility.expect_bundled_plugins_list_ok([], toReturn=False) module_desc = BundledPluginsModulesDescription(True, self.plugins_utility, self.maven_creator) self.plugins_utility.expect_get_all_bundled_plugins_paths( toReturn=['plugin1', 'plugin2']) module_desc.prepare_environment(self.logger) #when modules = module_desc.measured_modules() #then self.assertListEqual(list(modules), [], 'There should be no modules in fast mode ') self.assertFalse(self.maven.verify_executed(), 'Expected maven have not executed')
def __call__(self, args, executor: CommandExecutor): def check_remotes(log): if len(self.git.get_remotes()) == 0: self.set_remote(log) return Callable.success executor.append(check_remotes) if not args.fast: executor.append( lambda log: Callable.success if self.git.fetch_notes('*') == 0 else log.error( 'FATAL: git: Failure to fetch notes from origin.') or Callable.do_not_proceed) if args.branch: def branch_check(logger): current_branch = self.git.current_branch() if not current_branch == args.branch: logger.error( 'Branch check failed. You seem to be on "%s"; switch to "%s" first!' % (current_branch, args.branch)) return Callable.do_not_proceed else: return Callable.success executor.append(branch_check) def check_workspace(log: Logger): if args.note or not args.non_interactive: if not self.git.is_clean_workspace(): if args.note: log.error( 'I cannot write notes with local changes. Commit your work first, so that notes can ' 'be attached to your commit.') return Callable.do_not_proceed else: log.warn( 'You have uncommitted changes - if engineering health metrics are increased, you will ' 'not be able to add an exclusion note for the build.' ) return Callable.success executor.append(check_workspace) def clean_logs(log: Logger): if self.fs.dir_exists(MetricsCollector.log_directory): log.debug('Removing directory: %s' % MetricsCollector.log_directory) self.fs.remove_dir(MetricsCollector.log_directory) return Callable.success executor.append(clean_logs) def record_commit(log: Logger): self.fs.write_lines( os.sep.join([ self.fs.existing_dir(MetricsCollector.log_directory), '.commit' ]), [self.git.current_commit()]) return Callable.success executor.append(record_commit) metrics = DataBean() modules_descriptions = [ JIRADirectoryScanModulesDescription(args.fast, file_utils=self.fs), BundledPluginsModulesDescription(args.fast), JIRATestsModulesDescription(args.fast) ] executor.append( self.metrics_processor.process_metrics(args, modules_descriptions, metrics)) executor.append( self.metrics_processor.generate_report(metrics, self.fs, self.git)) executor.append( self.metrics_processor.check_values(args, metrics, self.git, self.fs)) if args.note: executor.append(lambda log: self.git.set_user( 'jmake stats runner', '*****@*****.**')) executor.append(lambda log: self.git.put_notes( self.json_writer.as_str(metrics), STATS_REF_NAME, 'HEAD', True) ) executor.append(lambda log: self.git.push_notes(STATS_REF_NAME))