Beispiel #1
0
    def mark_passed(self, test, flaky=False):
        """Sets test as passed

    Params:
      test (str): a test in format "{TestCase}/{testMethod}"

    If flaky=True, or if 'FAIL' already set in 'actual',
    apply is_flaky=True for all test(s).
    """
        if not test:
            LOGGER.warn('Empty or None test name passed to standard_json_util')
            return

        result_sink_test_result = result_sink_util.compose_test_result(
            test, 'PASS', True)
        self.result_sink.post(result_sink_test_result)

        if test in self.tests:
            self.tests[test]['actual'] = self.tests[test]['actual'] + " PASS"
        else:
            self.tests[test] = self._init_test('PASS', 'PASS')

        if flaky or 'FAIL' in self.tests[test]['actual']:
            self.tests[test]['is_flaky'] = True

        self.tests[test].pop('is_unexpected', None)
  def test_long_test_log(self):
    """Tests long test log is reported as expected."""
    len_32_str = 'This is a string in length of 32'
    self.assertEqual(len(len_32_str), 32)
    len_4128_str = (4 * 32 + 1) * len_32_str
    self.assertEqual(len(len_4128_str), 4128)
    expected_summary_html = ('<pre>' + len_32_str * 126 + 'This is a stri' +
                             '...Full output in "Test Log" Artifact.</pre>')

    expected = {
        'testId': 'TestCase/testSomething',
        'status': 'PASS',
        'expected': True,
        'summaryHtml': expected_summary_html,
        'artifacts': {
            'Test Log': {
                'contents': base64.b64encode(len_4128_str)
            },
        },
        'tags': [],
    }
    test_result = result_sink_util.compose_test_result('TestCase/testSomething',
                                                       'PASS', True,
                                                       len_4128_str)
    self.assertEqual(test_result, expected)
Beispiel #3
0
    def mark_timeout(self, test):
        """Sets test as TIMEOUT, which is used to indicate a test abort/timeout

    Params:
      test (str): a test in format "{TestCase}/{testMethod}"
    """
        if not test:
            LOGGER.warn('Empty or None test name passed to standard_json_util')
            return

        # Timeout tests in iOS test runner are tests that's unexpectedly not run.
        test_log = (
            'The test is compiled in test target but was unexpectedly not'
            ' run or not finished.')
        result_sink_test_result = result_sink_util.compose_test_result(
            test,
            'SKIP',
            False,
            test_log=test_log,
            tags=[('disabled_test', 'false')])
        self.result_sink.post(result_sink_test_result)

        if test in self.tests:
            self.tests[test][
                'actual'] = self.tests[test]['actual'] + " TIMEOUT"
            self.tests[test]['is_unexpected'] = True
        else:
            self.tests[test] = self._init_test('PASS', 'TIMEOUT', True)
  def test_compose_test_result_assertions(self):
    """Tests invalid status is rejected"""
    with self.assertRaises(AssertionError):
      test_result = result_sink_util.compose_test_result(
          'TestCase/testSomething', 'SOME_INVALID_STATUS', True)

    with self.assertRaises(AssertionError):
      test_result = result_sink_util.compose_test_result(
          'TestCase/testSomething', 'PASS', True, tags=('a', 'b'))

    with self.assertRaises(AssertionError):
      test_result = result_sink_util.compose_test_result(
          'TestCase/testSomething',
          'PASS',
          True,
          tags=[('a', 'b', 'c'), ('d', 'e')])

    with self.assertRaises(AssertionError):
      test_result = result_sink_util.compose_test_result(
          'TestCase/testSomething', 'PASS', True, tags=[('a', 'b'), ('c', 3)])
Beispiel #5
0
 def test_compose_test_result(self):
     """Tests compose_test_result function."""
     # Test a test result without log_path.
     test_result = result_sink_util.compose_test_result(
         'TestCase/testSomething', 'PASS', True)
     expected = {
         'testId': 'TestCase/testSomething',
         'status': 'PASS',
         'expected': True,
         'tags': [],
     }
     self.assertEqual(test_result, expected)
     # Tests a test result with log_path.
     test_result = result_sink_util.compose_test_result(
         'TestCase/testSomething', 'PASS', True, 'Some logs.')
     expected = {
         'testId': 'TestCase/testSomething',
         'status': 'PASS',
         'expected': True,
         'summaryHtml': '<pre>Some logs.</pre>',
         'tags': [],
     }
     self.assertEqual(test_result, expected)
Beispiel #6
0
    def mark_skipped(self, test):
        """Sets test(s) as expected SKIP.

    Params:
      test (str): a test in format "{TestCase}/{testMethod}"
    """
        if not test:
            LOGGER.warn('Empty or None test name passed to standard_json_util')
            return

        result_sink_test_result = result_sink_util.compose_test_result(
            test, 'SKIP', True, tags=[('disabled_test', 'true')])
        self.result_sink.post(result_sink_test_result)

        self.tests[test] = self._init_test('SKIP', 'SKIP')
 def test_composed_with_tags(self):
   """Tests tags is in correct format."""
   expected = {
       'testId': 'TestCase/testSomething',
       'status': 'SKIP',
       'expected': True,
       'tags': [{
           'key': 'disabled_test',
           'value': 'true',
       }]
   }
   test_result = result_sink_util.compose_test_result(
       'TestCase/testSomething',
       'SKIP',
       True,
       tags=[('disabled_test', 'true')])
   self.assertEqual(test_result, expected)
Beispiel #8
0
    def mark_failed(self, test, test_log=None):
        """Sets test(s) as failed.

    Params:
      test (str): a test in format "{TestCase}/{testMethod}"
      test_log (str): log of the specific test
    """
        if not test:
            LOGGER.warn('Empty or None test name passed to standard_json_util')
            return

        result_sink_test_result = result_sink_util.compose_test_result(
            test, 'FAIL', False, test_log=test_log)
        self.result_sink.post(result_sink_test_result)

        if test in self.tests:
            self.tests[test]['actual'] = self.tests[test]['actual'] + " FAIL"
            self.tests[test]['is_unexpected'] = True
        else:
            self.tests[test] = self._init_test('PASS', 'FAIL', True)