Пример #1
0
    def testHasFatalFailure(self):
        """Tests the HasFatalFailure method."""
        exc_infos = self._CreateExceptInfos(KeyError)
        exc_infos.extend(self._CreateExceptInfos(ValueError))
        exc = failures_lib.CompoundFailure(exc_infos=exc_infos)
        self.assertTrue(exc.HasFatalFailure())
        self.assertTrue(exc.HasFatalFailure(whitelist=[KeyError]))
        self.assertFalse(exc.HasFatalFailure(whitelist=[KeyError, ValueError]))

        exc = failures_lib.CompoundFailure()
        self.assertFalse(exc.HasFatalFailure())
Пример #2
0
    def testHasAndMatchesFailureType(self):
        """Tests the HasFailureType and the MatchesFailureType methods."""
        # Create a CompoundFailure instance with mixed types of exceptions.
        exc_infos = self._CreateExceptInfos(KeyError)
        exc_infos.extend(self._CreateExceptInfos(ValueError))
        exc = failures_lib.CompoundFailure(exc_infos=exc_infos)
        self.assertTrue(exc.HasFailureType(KeyError))
        self.assertTrue(exc.HasFailureType(ValueError))
        self.assertFalse(exc.MatchesFailureType(KeyError))
        self.assertFalse(exc.MatchesFailureType(ValueError))

        # Create a CompoundFailure instance with a single type of exceptions.
        exc_infos = self._CreateExceptInfos(KeyError, num=5)
        exc = failures_lib.CompoundFailure(exc_infos=exc_infos)
        self.assertTrue(exc.HasFailureType(KeyError))
        self.assertFalse(exc.HasFailureType(ValueError))
        self.assertTrue(exc.MatchesFailureType(KeyError))
        self.assertFalse(exc.MatchesFailureType(ValueError))
 def testMessageContainsAllInfo(self):
   """Tests that by default, all information is included in the message."""
   exc_infos = self._CreateExceptInfos(KeyError, message='bar1',
                                       traceback='foo1')
   exc_infos.extend(self._CreateExceptInfos(ValueError, message='bar2',
                                            traceback='foo2'))
   exc = failures_lib.CompoundFailure(exc_infos=exc_infos)
   self.assertIn('bar1', str(exc))
   self.assertIn('bar2', str(exc))
   self.assertIn('KeyError', str(exc))
   self.assertIn('ValueError', str(exc))
   self.assertIn('foo1', str(exc))
   self.assertIn('foo2', str(exc))
  def testConvertToStageFailureMessage(self):
    """Test ConvertToStageFailureMessage."""
    exc_infos = self._CreateExceptInfos(KeyError, message='bar1',
                                        traceback='foo1')
    exc_infos.extend(self._CreateExceptInfos(failures_lib.StepFailure,
                                             message='bar2',
                                             traceback='foo2'))
    exc = failures_lib.CompoundFailure(message='compound failure',
                                       exc_infos=exc_infos)
    stage_failure_msg = exc.ConvertToStageFailureMessage(1, 'HWTest [sanity]')

    self.assertEqual(len(stage_failure_msg.inner_failures), 2)
    self.assertEqual(stage_failure_msg.stage_name, 'HWTest [sanity]')
    self.assertEqual(stage_failure_msg.stage_prefix_name, 'HWTest')
    self.assertEqual(stage_failure_msg.exception_type, 'CompoundFailure')
    self.assertEqual(stage_failure_msg.exception_category, 'unknown')
Пример #5
0
    def _RunVMTests(self, builder_run, board):
        """Run VM test stages for the specified board.

    Args:
      builder_run: BuilderRun object for stages.
      board: String containing board name.
    """
        config = builder_run.config
        except_infos = []

        try:
            if config.vm_test_runs > 1:
                # Run the VMTests multiple times to see if they fail.
                self._RunStage(generic_stages.RepeatStage,
                               config.vm_test_runs,
                               vm_test_stages.VMTestStage,
                               board,
                               builder_run=builder_run)
            else:
                # Retry VM-based tests in case failures are flaky.
                self._RunStage(generic_stages.RetryStage,
                               constants.VM_NUM_RETRIES,
                               vm_test_stages.VMTestStage,
                               board,
                               builder_run=builder_run)
        except Exception as e:
            except_infos.extend(
                failures_lib.CreateExceptInfo(e, traceback.format_exc()))

        # Run stages serially to avoid issues encountered when running VMs (or the
        # devserver) in parallel: https://crbug.com/779267
        if config.tast_vm_tests:
            try:
                self._RunStage(generic_stages.RetryStage,
                               constants.VM_NUM_RETRIES,
                               tast_test_stages.TastVMTestStage,
                               board,
                               builder_run=builder_run)
            except Exception as e:
                except_infos.extend(
                    failures_lib.CreateExceptInfo(e, traceback.format_exc()))

        if except_infos:
            raise failures_lib.CompoundFailure('VM tests failed', except_infos)
Пример #6
0
 def testHasEmptyList(self):
     """Tests the HasEmptyList method."""
     self.assertTrue(failures_lib.CompoundFailure().HasEmptyList())
     exc_infos = self._CreateExceptInfos(KeyError)
     self.assertFalse(
         failures_lib.CompoundFailure(exc_infos=exc_infos).HasEmptyList())