def testInitMissingRequiredArgs(self):
     """Tests that GitBisector raises error when missing required arguments."""
     options = cros_test_lib.EasyAttr()
     with self.assertRaises(common.MissingRequiredOptionsException) as cm:
         git_bisector.GitBisector(options, self.builder, self.evaluator)
     exception_message = str(cm.exception)
     self.assertIn('Missing command line', exception_message)
     self.assertIn('GitBisector', exception_message)
     for arg in git_bisector.GitBisector.REQUIRED_ARGS:
         self.assertIn(arg, exception_message)
    def testLabelBuildSkipNoScore(self):
        """Tests LabelBuild()."""
        self.options.skip_failed_commit = True
        self.bisector = git_bisector.GitBisector(self.options, self.builder,
                                                 self.evaluator)

        # Inject good(100), bad(80) score and threshold.
        self.setDefaultCommitInfo()
        self.bisector.threshold = self.THRESHOLD

        # No score, skip.
        self.assertEqual('skip', self.bisector.LabelBuild(None))
        self.assertEqual('skip', self.bisector.LabelBuild(common.Score()))
    def testBuildDeployEvalRaiseNoScore(self):
        """Tests BuildDeployEval() without score with eval_raise_on_error set."""
        self.options.eval_raise_on_error = True
        self.bisector = git_bisector.GitBisector(self.options, self.builder,
                                                 self.evaluator)

        mocks = self.PatchObjectForBuildDeployEval()

        # Inject this as UpdateCurrentCommit's side effect.
        self.bisector.current_commit = copy.deepcopy(self.GOOD_COMMIT_INFO)

        mocks['CheckLastEvaluate'].return_value = common.Score()
        mocks['Evaluate'].return_value = common.Score()

        self.assertRaises(Exception, self.bisector.BuildDeployEval)
        self.assertFalse(self.bisector.current_commit.score)
        self.AssertBuildDeployEvalMocksAllCalled(mocks)
    def setUp(self):
        """Sets up test case."""
        self.options = cros_test_lib.EasyAttr(base_dir=self.tempdir,
                                              board=self.BOARD,
                                              reuse_repo=True,
                                              good=self.GOOD_COMMIT_SHA1,
                                              bad=self.BAD_COMMIT_SHA1,
                                              remote=self.DUT,
                                              eval_repeat=self.REPEAT,
                                              auto_threshold=False,
                                              reuse_eval=False,
                                              eval_raise_on_error=False,
                                              skip_failed_commit=False)

        self.evaluator = evaluator_module.Evaluator(self.options)
        self.builder = builder_module.Builder(self.options)
        self.bisector = git_bisector.GitBisector(self.options, self.builder,
                                                 self.evaluator)
        self.repo_dir = os.path.join(self.tempdir,
                                     builder_module.Builder.DEFAULT_REPO_DIR)