예제 #1
0
 def testReportIndividualTestResultEarlyReturnIfNotSupported(self):
     self.setLuciContextWithContent({})
     rsr = result_sink.ResultSinkReporter(self._host)
     rsr._post = lambda: 1/0  # Shouldn't be called.
     self.assertEqual(
             rsr.report_individual_test_result(None, None, None, None, None),
             0)
예제 #2
0
 def testReportResultEarlyReturnIfNotSupported(self):
     self.setLuciContextWithContent({})
     rsr = result_sink.ResultSinkReporter(self._host)
     result_sink._create_json_test_result = lambda: 1/0
     self.assertEqual(rsr._report_result(
             'test_id', json_results.ResultType.Pass, True, {}, {},
             '<pre>summary</pre>', 1, {}), 0, {})
예제 #3
0
    def testReportIndividualTestResultMultipleArtifacts(self):
        self.setLuciContextWithContent(DEFAULT_LUCI_CONTEXT)
        rsr = result_sink.ResultSinkReporter(self._host)
        rsr._post = StubWithRetval(2)
        results = CreateResult({
            'name': 'test_name',
            'actual': json_results.ResultType.Pass,
            'artifacts': {
                'artifact_name': ['some_artifact', 'another_artifact'],
            },
        })
        retval = rsr.report_individual_test_result('test_name_prefix.',
                                                   results, ARTIFACT_DIR,
                                                   CreateTestExpectations())
        self.assertEqual(retval, 2)

        test_result = GetTestResultFromPostedJson(rsr._post.args[0])
        expected_result = CreateExpectedTestResult(
            artifacts={
                'artifact_name-file0': {
                    'filePath':
                    self._host.join(self._host.getcwd(), ARTIFACT_DIR,
                                    'some_artifact'),
                },
                'artifact_name-file1': {
                    'filePath':
                    self._host.join(self._host.getcwd(), ARTIFACT_DIR,
                                    'another_artifact'),
                },
            })
        self.assertEqual(test_result, expected_result)
예제 #4
0
    def testReportIndividualTestResultLongSummaryUnicode(self):
        self.setLuciContextWithContent(DEFAULT_LUCI_CONTEXT)
        rsr = result_sink.ResultSinkReporter(self._host)
        result = CreateResult({
            'name': 'test_name',
            'actual': json_results.ResultType.Pass,
            'out': u'\u00A5' + 'a' * 4096,
            'err': '',
        })
        rsr._post = StubWithRetval(0)
        rsr.report_individual_test_result('test_name_prefix.',
                                          result, ARTIFACT_DIR,
                                          CreateTestExpectations())

        test_result = GetTestResultFromPostedJson(rsr._post.args[0])
        truncated_summary = '<pre>stdout: %s%s' % (
            u'\u00A5' + 'a' *
            (result_sink.MAX_HTML_SUMMARY_LENGTH -
             len(result_sink.TRUNCATED_SUMMARY_MESSAGE) - 15),
            result_sink.TRUNCATED_SUMMARY_MESSAGE)
        self.assertEqual(len(truncated_summary.encode('utf-8')),
                         result_sink.MAX_HTML_SUMMARY_LENGTH)
        artifact_contents = 'stdout: %s\nstderr: ' % (u'\u00A5' + 'a' * 4096)
        expected_result = CreateExpectedTestResult(
            summary_html=truncated_summary,
            artifacts={
                'Test Log': {
                    'contents':
                    base64.b64encode(artifact_contents.encode('utf-8'))
                }
            })
        self.assertEqual(test_result, expected_result)
예제 #5
0
 def testReportIndividualTestResultNoTestExpectations(self):
     self.setLuciContextWithContent(DEFAULT_LUCI_CONTEXT)
     rsr = result_sink.ResultSinkReporter(self._host)
     result = CreateResult({
         'name': 'test_name',
         'actual': json_results.ResultType.Pass,
     })
     rsr._post = StubWithRetval(2)
     retval = rsr.report_individual_test_result('test_name_prefix.', result,
                                                ARTIFACT_DIR, None)
     self.assertEqual(retval, 2)
     expected_result = CreateExpectedTestResult(tags=[
         {
             'key': 'test_name',
             'value': 'test_name_prefix.test_name'
         },
         {
             'key': 'typ_expectation',
             'value': json_results.ResultType.Pass
         },
         {
             'key': 'raw_typ_expectation',
             'value': 'Pass'
         },
     ])
     self.assertEqual(GetTestResultFromPostedJson(rsr._post.args[0]),
                      expected_result)
예제 #6
0
 def testReportIndividualTestResultBasicCase(self):
     self.setLuciContextWithContent(DEFAULT_LUCI_CONTEXT)
     rsr = result_sink.ResultSinkReporter(self._host)
     result = CreateResult({
         'name': 'test_name',
         'actual': json_results.ResultType.Pass,
     })
     rsr._post = StubWithRetval(2)
     retval = rsr.report_individual_test_result('test_name_prefix.', result,
                                                ARTIFACT_DIR,
                                                CreateTestExpectations())
     self.assertEqual(retval, 2)
     expected_result = CreateExpectedTestResult()
     self.assertEqual(GetTestResultFromPostedJson(rsr._post.args[0]),
                      expected_result)
예제 #7
0
 def testReportIndividualTestResultConflictingKeyLongSummary(self):
     self.setLuciContextWithContent(DEFAULT_LUCI_CONTEXT)
     rsr = result_sink.ResultSinkReporter(self._host)
     rsr._post = lambda: 1 / 0
     result = CreateResult({
         'name': 'test_name',
         'actual': json_results.ResultType.Pass,
         'artifacts': {
             'Test Log': [''],
         },
         'out': 'a' * 4097,
     })
     with self.assertRaises(AssertionError):
         rsr.report_individual_test_result('test_name_prefix', result,
                                           ARTIFACT_DIR,
                                           CreateTestExpectations())
예제 #8
0
def _setup_process(host, worker_num, child):
    child.host = host
    child.result_sink_reporter = result_sink.ResultSinkReporter(
            host, child.disable_resultsink)
    child.worker_num = worker_num
    # pylint: disable=protected-access

    if child.coverage:  # pragma: no cover
        import coverage
        child.cov = coverage.coverage(source=child.coverage_source,
                                      data_suffix=True)
        child.cov._warn_no_data = False
        child.cov.start()

    if child.setup_fn:
        child.context_after_setup = child.setup_fn(child, child.context)
    else:
        child.context_after_setup = child.context
    return child
예제 #9
0
 def testValidSinkKey(self):
     self.setLuciContextWithContent(DEFAULT_LUCI_CONTEXT)
     rsr = result_sink.ResultSinkReporter(self._host)
     self.assertTrue(rsr.resultdb_supported)
예제 #10
0
 def testNoSinkKey(self):
     self.setLuciContextWithContent({})
     rsr = result_sink.ResultSinkReporter(self._host)
     self.assertFalse(rsr.resultdb_supported)
예제 #11
0
 def testExplicitDisable(self):
     self.setLuciContextWithContent(DEFAULT_LUCI_CONTEXT)
     rsr = result_sink.ResultSinkReporter(self._host, True)
     self.assertFalse(rsr.resultdb_supported)
예제 #12
0
 def testNoLuciContext(self):
     if 'LUCI_CONTEXT' in self._host.env:
         del self._host.env['LUCI_CONTEXT']
     rsr = result_sink.ResultSinkReporter(self._host)
     self.assertFalse(rsr.resultdb_supported)