Пример #1
0
  def test_phase_multiple_diagnoses_with_failure(self):

    @htf.PhaseDiagnoser(OkayResult)
    def fine_diag(phase_record):
      del phase_record  # Unused.
      return htf.Diagnosis(OkayResult.FINE, 'Fine'),

    @htf.PhaseDiagnoser(BadResult)
    def bad_diag(phase_record):
      del phase_record  # Unused.
      return htf.Diagnosis(BadResult.ONE, 'Bad!', is_failure=True)

    phase = htf.diagnose(fine_diag, bad_diag)(basic_phase)

    phase_rec = yield phase
    self.assertPhaseContinue(phase_rec)
    self.assertPhaseOutcomeFail(phase_rec)
    self.assertEqual([OkayResult.FINE], phase_rec.diagnosis_results)
    self.assertEqual([BadResult.ONE], phase_rec.failure_diagnosis_results)
    store = self.get_diagnoses_store()
    self.assertEqual(
        htf.Diagnosis(OkayResult.FINE, 'Fine'),
        store.get_diagnosis(OkayResult.FINE))
    self.assertEqual(
        htf.Diagnosis(BadResult.ONE, 'Bad!', is_failure=True),
        store.get_diagnosis(BadResult.ONE))
Пример #2
0
  def test_phase_multiple_diagnoses__same_result(self):

    @htf.PhaseDiagnoser(OkayResult)
    def multi_diag(phase_record):
      del phase_record  # Unused.
      return [
          htf.Diagnosis(OkayResult.FINE, 'Fine1'),
          htf.Diagnosis(OkayResult.FINE, 'Fine2'),
      ]

    phase = htf.diagnose(multi_diag)(basic_phase)

    phase_rec = yield phase
    self.assertPhaseContinue(phase_rec)
    self.assertPhaseOutcomePass(phase_rec)
    self.assertEqual([OkayResult.FINE, OkayResult.FINE],
                     phase_rec.diagnosis_results)
    self.assertEqual([], phase_rec.failure_diagnosis_results)
    store = self.get_diagnoses_store()
    self.assertEqual(
        htf.Diagnosis(OkayResult.FINE, 'Fine2'),
        store.get_diagnosis(OkayResult.FINE))
    self.assertEqual([
        htf.Diagnosis(OkayResult.FINE, 'Fine1'),
        htf.Diagnosis(OkayResult.FINE, 'Fine2'),
    ], self.last_test_state.test_record.diagnoses)
Пример #3
0
  def test_phase_multiple_diagnoses_from_multiple_diagnosers(self):

    @htf.PhaseDiagnoser(OkayResult)
    def fine_diag(phase_record):
      del phase_record  # Unused.
      return htf.Diagnosis(OkayResult.FINE, 'Fine')

    @htf.PhaseDiagnoser(OkayResult)
    def great_diag(phase_record):
      del phase_record  # Unused.
      return htf.Diagnosis(OkayResult.GREAT, 'Great')

    phase = htf.diagnose(fine_diag, great_diag)(basic_phase)

    phase_rec = yield phase
    self.assertPhaseContinue(phase_rec)
    self.assertPhaseOutcomePass(phase_rec)
    self.assertEqual([OkayResult.FINE, OkayResult.GREAT],
                     phase_rec.diagnosis_results)
    self.assertEqual([], phase_rec.failure_diagnosis_results)
    store = self.get_diagnoses_store()
    self.assertEqual(
        htf.Diagnosis(OkayResult.FINE, 'Fine'),
        store.get_diagnosis(OkayResult.FINE))
    self.assertEqual(
        htf.Diagnosis(OkayResult.GREAT, 'Great'),
        store.get_diagnosis(OkayResult.GREAT))
Пример #4
0
class ConditionalValidatorsTest(htf_test.TestCase):
    def setUp(self):
        super(ConditionalValidatorsTest, self).setUp()
        self.validator_values = []
        self.validator_return_value = False

    def _make_validator(self):
        def _validator(value):
            self.validator_values.append(value)
            return self.validator_return_value

        return _validator

    @htf_test.yields_phases
    def test_conditional_measurement__not_run_no_results(self):
        @htf.measures(
            htf.Measurement('validator_not_run').validate_on(
                {OkayResult.OKAY: self._make_validator()}))
        def phase(test):
            test.measurements.validator_not_run = True

        phase_rec = yield phase

        self.assertPhaseContinue(phase_rec)
        self.assertPhaseOutcomePass(phase_rec)
        self.assertEqual([], self.validator_values)

    @htf_test.yields_phases_with(
        phase_diagnoses=[htf.Diagnosis(OkayResult.FINE, 'Fine.')])
    def test_conditional_measurement__not_run_different_results(self):
        @htf.measures(
            htf.Measurement('validator_not_run').validate_on(
                {OkayResult.OKAY: self._make_validator()}))
        def phase(test):
            test.measurements.validator_not_run = True

        phase_rec = yield phase

        self.assertPhaseContinue(phase_rec)
        self.assertPhaseOutcomePass(phase_rec)
        self.assertEqual([], self.validator_values)

    @htf_test.yields_phases_with(
        phase_diagnoses=[htf.Diagnosis(OkayResult.OKAY, 'Okay.')])
    def test_conditional_measurement__run(self):
        self.validator_return_value = True

        @htf.measures(
            htf.Measurement('validator_run').validate_on(
                {OkayResult.OKAY: self._make_validator()}))
        def phase(test):
            test.measurements.validator_run = True

        phase_rec = yield phase

        self.assertPhaseContinue(phase_rec)
        self.assertPhaseOutcomePass(phase_rec)
        self.assertEqual([True], self.validator_values)
Пример #5
0
    def test_test_diagnosis_pass__phase_diagnosis_pass(self):
        phase = htf.diagnose(basic_wrapper_phase_diagnoser)(basic_phase)
        test = htf.Test(phase)
        test.add_test_diagnosers(basic_wrapper_test_diagnoser)

        test_rec = yield test

        self.assertTestPass(test_rec)
        self.assertEqual([
            htf.Diagnosis(OkayResult.OKAY, 'Everything is okay.'),
            htf.Diagnosis(OkayResult.TEST_OK, 'Okay'),
        ], test_rec.diagnoses)
        phase_rec = test_rec.phases[1]
        self.assertEqual([OkayResult.OKAY], phase_rec.diagnosis_results)
        self.assertEqual([], phase_rec.failure_diagnosis_results)
Пример #6
0
    def test_test_diagnosis_fail__phase_diagnosis_pass(self):
        phase = htf.diagnose(basic_wrapper_phase_diagnoser)(basic_phase)
        test = htf.Test(phase)
        test.add_test_diagnosers(fail_test_diagnoser)

        test_rec = yield test

        self.assertTestFail(test_rec)
        self.assertEqual([
            htf.Diagnosis(OkayResult.OKAY, 'Everything is okay.'),
            htf.Diagnosis(BadResult.TWO, 'Uh oh!', is_failure=True),
        ], test_rec.diagnoses)
        phase_rec = test_rec.phases[1]
        self.assertEqual([OkayResult.OKAY], phase_rec.diagnosis_results)
        self.assertEqual([], phase_rec.failure_diagnosis_results)
Пример #7
0
    def test_test_diagnosis_pass__phase_diagnosis_fail(self):
        phase = htf.diagnose(fail_phase_diagnoser)(basic_phase)
        test = htf.Test(phase)
        test.add_test_diagnosers(basic_wrapper_test_diagnoser)

        test_rec = yield test

        self.assertTestFail(test_rec)
        self.assertEqual([
            htf.Diagnosis(BadResult.ONE, 'Oh no!', is_failure=True),
            htf.Diagnosis(OkayResult.TEST_OK, 'Okay'),
        ], test_rec.diagnoses)
        phase_rec = test_rec.phases[1]
        self.assertEqual([], phase_rec.diagnosis_results)
        self.assertEqual([BadResult.ONE], phase_rec.failure_diagnosis_results)
Пример #8
0
 def assertPhaseHasFailDiagnosis(self, phase_rec):
     self.assertEqual([], phase_rec.diagnosis_results)
     self.assertEqual([BadResult.ONE], phase_rec.failure_diagnosis_results)
     store = self.get_diagnoses_store()
     self.assertEqual(
         htf.Diagnosis(BadResult.ONE, 'Oh no!', is_failure=True),
         store.get_diagnosis(BadResult.ONE))
Пример #9
0
 def assertPhaseHasBasicOkayDiagnosis(self, phase_rec):
   self.assertEqual([OkayResult.OKAY], phase_rec.diagnosis_results)
   self.assertEqual([], phase_rec.failure_diagnosis_results)
   store = self.get_diagnoses_store()
   self.assertEqual(
       htf.Diagnosis(OkayResult.OKAY, 'Everything is okay.'),
       store.get_diagnosis(OkayResult.OKAY))
Пример #10
0
  def test_failed_phase_diagnoser_on_test(self):
    phase = htf.diagnose(fail_phase_diagnoser)(basic_phase)

    test_rec = yield htf.Test(phase)
    self.assertTestFail(test_rec)
    self.assertEqual([htf.Diagnosis(BadResult.ONE, 'Oh no!', is_failure=True)],
                     test_rec.diagnoses)
Пример #11
0
    def test_test_diagnoser(self):
        test = htf.Test(basic_phase)
        test.add_test_diagnosers(basic_wrapper_test_diagnoser)

        test_rec = yield test

        self.assertTestPass(test_rec)
        self.assertEqual([htf.Diagnosis(OkayResult.TEST_OK, 'Okay')],
                         test_rec.diagnoses)
Пример #12
0
  def test_always_failed_test_diagnoser(self):
    test = htf.Test(basic_phase)
    test.add_test_diagnosers(always_fail_test_diagnoser)

    test_rec = yield test

    self.assertTestFail(test_rec)
    self.assertEqual([htf.Diagnosis(BadResult.TWO, 'Uh oh!', is_failure=True)],
                     test_rec.diagnoses)
Пример #13
0
    def test_basic_phase_diagnoser_on_test(self):
        phase = htf.diagnose(basic_wrapper_phase_diagnoser)(basic_phase)

        test_rec = yield htf.Test(phase)
        self.assertTestPass(test_rec)
        self.assertEqual([
            htf.Diagnosis(OkayResult.OKAY,
                          'Everything is okay.',
                          priority=htf.DiagPriority.NORMAL)
        ], test_rec.diagnoses)
Пример #14
0
    def test_test_diagnoser__exception_with_phase_excption(self):
        test = htf.Test(exception_phase)
        test.add_test_diagnosers(exception_test_diagnoser,
                                 basic_wrapper_test_diagnoser)

        test_rec = yield test

        self.assertTestError(test_rec, exc_type=PhaseError)
        self.assertEqual([test_record.OutcomeDetails('PhaseError', mock.ANY)],
                         test_rec.outcome_details)
        self.assertEqual([htf.Diagnosis(OkayResult.TEST_OK, 'Okay')],
                         test_rec.diagnoses)
Пример #15
0
    def test_phase_diagnoser_exception__generator_exceptions_after_add(self):
        @htf.PhaseDiagnoser(BadResult)
        def generate_diag_then_error(phase_record):
            del phase_record  # Unused.
            yield htf.Diagnosis(BadResult.ONE, 'Bad!', is_failure=True)
            raise DiagPhaseError('it fatal')

        phase = htf.diagnose(generate_diag_then_error)(basic_phase)

        phase_rec = yield phase

        self.assertPhaseError(phase_rec, exc_type=DiagPhaseError)
        self.assertPhaseOutcomeError(phase_rec)
        self.assertEqual([], phase_rec.diagnosis_results)
        self.assertEqual([BadResult.ONE], phase_rec.failure_diagnosis_results)
        store = self.get_diagnoses_store()
        self.assertEqual(htf.Diagnosis(BadResult.ONE, 'Bad!', is_failure=True),
                         store.get_diagnosis(BadResult.ONE))
Пример #16
0
    def test_basic_subclass_diagnoser(self):
        class SubclassBasicPhaseDiagnoser(diagnoses_lib.BasePhaseDiagnoser):
            def __init__(self):
                super(SubclassBasicPhaseDiagnoser,
                      self).__init__(OkayResult,
                                     name='SubclassBasicPhaseDiagnoser')

            def run(self, phase_record):
                del phase_record  # Unused.
                return htf.Diagnosis(OkayResult.FINE, 'Everything is fine.')

        phase = htf.diagnose(SubclassBasicPhaseDiagnoser())(basic_phase)

        phase_rec = yield phase
        self.assertPhaseContinue(phase_rec)
        self.assertPhaseOutcomePass(phase_rec)
        self.assertEqual([OkayResult.FINE], phase_rec.diagnosis_results)
        self.assertEqual([], phase_rec.failure_diagnosis_results)
        store = self.get_diagnoses_store()
        self.assertEqual(htf.Diagnosis(OkayResult.FINE, 'Everything is fine.'),
                         store.get_diagnosis(OkayResult.FINE))
Пример #17
0
def always_fail_phase_diagnoser(phase_record):
    del phase_record  # Unused.
    return htf.Diagnosis(BadResult.ONE, 'Oh no!')
Пример #18
0
 def bad_result(phase_record):
     del phase_record  # Unused.
     return [htf.Diagnosis(BadResult.ONE, 'one')]
Пример #19
0
 def test_internal_cannot_be_failure(self):
     with self.assertRaises(diagnoses_lib.InvalidDiagnosisError):
         _ = htf.Diagnosis(BadResult.ONE,
                           'blarg',
                           is_internal=True,
                           is_failure=True)
Пример #20
0
def fail_phase_diagnoser(phase_record):
    del phase_record  # Unused.
    return htf.Diagnosis(BadResult.ONE, 'Oh no!', is_failure=True)
Пример #21
0
 def generate_diag_then_error(phase_record):
     del phase_record  # Unused.
     yield htf.Diagnosis(BadResult.ONE, 'Bad!', is_failure=True)
     raise DiagPhaseError('it fatal')
Пример #22
0
 def bad_diag(phase_record):
     del phase_record  # Unused.
     return htf.Diagnosis(BadResult.ONE, 'Bad!', is_failure=True)
Пример #23
0
def always_fail_test_diagnoser(test_record_, store):
    del test_record_  # Unused.
    del store  # Unused.
    return htf.Diagnosis(BadResult.TWO, 'Uh oh!')
Пример #24
0
 def fine_diag(phase_record):
     del phase_record  # Unused.
     return htf.Diagnosis(OkayResult.FINE, 'Fine'),
Пример #25
0
 def run(self, phase_record):
     del phase_record  # Unused.
     return htf.Diagnosis(OkayResult.FINE, 'Everything is fine.')
Пример #26
0
def basic_wrapper_phase_diagnoser(phase_record):
    del phase_record  # Unused.
    return htf.Diagnosis(OkayResult.OKAY, 'Everything is okay.')
Пример #27
0
 def great_diag(phase_record):
     del phase_record  # Unused.
     return htf.Diagnosis(OkayResult.GREAT, 'Great')
Пример #28
0
 def multi(phase_record):
     del phase_record  # Unused.
     return [
         htf.Diagnosis(OkayResult.FINE, 'Fine'),
         htf.Diagnosis(OkayResult.GREAT, 'Great'),
     ]
Пример #29
0
 def bad_result(test_record_, store):
     del test_record_  # Unused.
     del store  # Unused.
     return [htf.Diagnosis(BadResult.ONE, 'one')]
Пример #30
0
 def multi_diag(phase_record):
     del phase_record  # Unused.
     return [
         htf.Diagnosis(OkayResult.FINE, 'Fine1'),
         htf.Diagnosis(OkayResult.FINE, 'Fine2'),
     ]