예제 #1
0
 def test_result_add_operator_success(self):
     record1 = records.TestResultRecord(self.tn)
     record1.test_begin()
     s = signals.TestPass(self.details, self.float_extra)
     record1.test_pass(s)
     tr1 = records.TestResult()
     tr1.add_record(record1)
     tr1.add_controller_info("MockDevice", ["magicA", "magicB"])
     record2 = records.TestResultRecord(self.tn)
     record2.test_begin()
     s = signals.TestPass(self.details, self.json_extra)
     record2.test_pass(s)
     tr2 = records.TestResult()
     tr2.add_record(record2)
     tr2.add_controller_info("MockDevice", ["magicC"])
     tr2 += tr1
     self.assertTrue(tr2.passed, [tr1, tr2])
     self.assertTrue(tr2.controller_info, {"MockDevice": ["magicC"]})
예제 #2
0
 def test_result_record_pass_with_json_extra(self):
     record = records.TestResultRecord(self.tn)
     record.test_begin()
     s = signals.TestPass(self.details, self.json_extra)
     record.test_pass(s)
     self.verify_record(record=record,
                        result=records.TestResultEnums.TEST_RESULT_PASS,
                        details=self.details,
                        extras=self.json_extra)
예제 #3
0
 def test_result_add_operator_type_mismatch(self):
     record1 = records.TestResultRecord(self.tn)
     record1.test_begin()
     s = signals.TestPass(self.details, self.float_extra)
     record1.test_pass(s)
     tr1 = records.TestResult()
     tr1.add_record(record1)
     expected_msg = "Operand .* of type .* is not a TestResult."
     with self.assertRaisesRegexp(TypeError, expected_msg):
         tr1 += "haha"
예제 #4
0
 def test_result_record_explicit_pass_with_float_extra(self):
     record = records.TestResultRecord(self.tn)
     record.test_begin()
     s = signals.TestPass(self.details, self.float_extra)
     record.test_pass(s)
     self.verify_record(record=record,
                        result=records.TestResultEnums.TEST_RESULT_PASS,
                        details=self.details,
                        termination_signal_type='TestPass',
                        extras=self.float_extra)
예제 #5
0
 def test_result_fail_class_with_test_signal(self):
     record1 = records.TestResultRecord(self.tn)
     record1.test_begin()
     s = signals.TestPass(self.details, self.float_extra)
     record1.test_pass(s)
     tr = records.TestResult()
     tr.add_record(record1)
     s = signals.TestFailure(self.details, self.float_extra)
     record2 = records.TestResultRecord("SomeTest", s)
     tr.fail_class(record2)
     self.assertEqual(len(tr.passed), 1)
     self.assertEqual(len(tr.failed), 1)
     self.assertEqual(len(tr.executed), 2)
예제 #6
0
 def test_result_add_operator_success(self):
     record1 = records.TestResultRecord(self.tn)
     record1.test_begin()
     s = signals.TestPass(self.details, self.float_extra)
     record1.test_pass(s)
     tr1 = records.TestResult()
     tr1.add_record(record1)
     controller_info = records.ControllerInfoRecord(
         'SomeClass', 'MockDevice', ['magicA', 'magicB'])
     tr1.add_controller_info_record(controller_info)
     record2 = records.TestResultRecord(self.tn)
     record2.test_begin()
     s = signals.TestPass(self.details, self.json_extra)
     record2.test_pass(s)
     tr2 = records.TestResult()
     tr2.add_record(record2)
     controller_info = records.ControllerInfoRecord(
         'SomeClass', 'MockDevice', ['magicC'])
     tr2.add_controller_info_record(controller_info)
     tr2 += tr1
     self.assertTrue(tr2.passed, [tr1, tr2])
     self.assertTrue(tr2.controller_info, {'MockDevice': ['magicC']})
예제 #7
0
 def test_is_all_pass(self):
     s = signals.TestPass(self.details, self.float_extra)
     record1 = records.TestResultRecord(self.tn)
     record1.test_begin()
     record1.test_pass(s)
     s = signals.TestSkip(self.details, self.float_extra)
     record2 = records.TestResultRecord(self.tn)
     record2.test_begin()
     record2.test_skip(s)
     tr = records.TestResult()
     tr.add_record(record1)
     tr.add_record(record2)
     tr.add_record(record1)
     self.assertEqual(len(tr.passed), 2)
     self.assertTrue(tr.is_all_pass)
예제 #8
0
def explicit_pass(msg, extras=None):
    """Explicitly pass a test.

    A test with not uncaught exception will pass implicitly so the usage of
    this is optional. It is intended for reporting extra information when a
    test passes.

    Args:
        msg: A string explaining the details of the passed test.
        extras: An optional field for extra information to be included in
            test result.

    Raises:
        signals.TestPass: Mark a test as passed.
    """
    raise signals.TestPass(msg, extras)
예제 #9
0
    def create_test_record(self, mobly_test_class):
        """Creates a TestResultRecord for the instrumentation block.

    Args:
      mobly_test_class: string, the name of the Mobly test case
        executing the instrumentation run.

    Returns:
      A TestResultRecord with an appropriate signals exception
      representing the instrumentation test method's result status.
    """
        details = self._get_details()
        extras = self._get_extras()

        tr_record = records.TestResultRecord(
            t_name=self._get_full_name(),
            t_class=mobly_test_class,
        )
        if self._begin_time:
            tr_record.begin_time = self._begin_time

        if self._is_failed():
            tr_record.test_fail(
                e=signals.TestFailure(details=details, extras=extras))
        elif self._status_code in _InstrumentationStatusCodeCategories.SKIPPED:
            tr_record.test_skip(
                e=signals.TestSkip(details=details, extras=extras))
        elif self._status_code in _InstrumentationStatusCodeCategories.PASS:
            tr_record.test_pass(
                e=signals.TestPass(details=details, extras=extras))
        elif self._status_code in _InstrumentationStatusCodeCategories.TIMING:
            if self._error_message:
                tr_record.test_error(
                    e=signals.TestError(details=details, extras=extras))
            else:
                tr_record = None
        else:
            tr_record.test_error(
                e=signals.TestError(details=details, extras=extras))
        if self._known_keys[_InstrumentationKnownStatusKeys.STACK]:
            tr_record.termination_signal.stacktrace = self._known_keys[
                _InstrumentationKnownStatusKeys.STACK]
        return tr_record
예제 #10
0
파일: asserts.py 프로젝트: qvas1r/mobly
def explicit_pass(msg, extras=None):
    """Explicitly pass a test.

  This will pass the test explicitly regardless of any other error happened
  in the test body. E.g. even if errors have been recorded with `expects`,
  the test will still be marked pass if this is called.

  A test without uncaught exception will pass implicitly so this should be
  used scarcely.

  Args:
    msg: A string explaining the details of the passed test.
    extras: An optional field for extra information to be included in
      test result.

  Raises:
    signals.TestPass: Mark a test as passed.
  """
    raise signals.TestPass(msg, extras)
예제 #11
0
    def test_result_fail_class_with_special_error(self):
        """Call TestResult.fail_class with an error class that requires more
        than one arg to instantiate.
        """
        record1 = records.TestResultRecord(self.tn)
        record1.test_begin()
        s = signals.TestPass(self.details, self.float_extra)
        record1.test_pass(s)
        tr = records.TestResult()
        tr.add_record(record1)

        class SpecialError(Exception):
            def __init__(self, arg1, arg2):
                self.msg = "%s %s" % (arg1, arg2)

        se = SpecialError("haha", 42)
        record2 = records.TestResultRecord("SomeTest", se)
        tr.fail_class(record2)
        self.assertEqual(len(tr.passed), 1)
        self.assertEqual(len(tr.failed), 1)
        self.assertEqual(len(tr.executed), 2)