示例#1
0
  def test_save_and_upload(self):
    testrun_output = io.BytesIO()
    mock_converter = mock.MagicMock(return_value=MOCK_TEST_RUN_PROTO)

    callback = mfg_inspector.MfgInspector(
        user='******', keydata='keydata', token_uri='')
    callback.set_converter(mock_converter)

    callback.save_to_disk(filename_pattern=testrun_output)(MOCK_TEST_RUN)
    callback.upload()(MOCK_TEST_RUN)

    # Parse what was written to BytesIO back into a proto and compare
    testrun_output.seek(0)
    testrun = test_runs_pb2.TestRun()
    testrun.ParseFromString(testrun_output.read())

    self.assertEqual(MOCK_TEST_RUN_PROTO, testrun)

    self.mock_send_mfg_inspector_data.assert_called_with(
        MOCK_TEST_RUN_PROTO, self.mock_credentials, callback.destination_url,
        guzzle_pb2.COMPRESSED_TEST_RUN)

    # Make sure mock converter only called once i.e. the test record was
    # was converted to a proto only once.  This important because some custom
    # converters mutate the test record, so the converter is not idempotent.
    self.assertEqual(1, mock_converter.call_count)
示例#2
0
def _test_run_from_test_record(record):
  """Create a TestRun proto from an OpenHTF TestRecord.

  Most fields are just copied over, some are pulled out of metadata (listed
  below), and measurements are munged a bit for backwards compatibility.

  Metadata fields:
    'test_description': TestInfo's description field.
    'test_version': TestInfo's version_string field.
    'test_name': TestInfo's name field.
    'run_name': TestRun's run_name field.
    'operator_name': TestRun's operator_name field.


  Returns:  An instance of the TestRun proto for the given record.
  """
  testrun = test_runs_pb2.TestRun()
  _populate_header(record, testrun)
  _attach_json(record, testrun)

  used_parameter_names = set(['OpenHTF_record.json'])
  mangled_parameters = _extract_parameters(record, testrun,
                                           used_parameter_names)
  _add_mangled_parameters(testrun, mangled_parameters, used_parameter_names)
  _add_log_lines(record, testrun)
  return testrun
示例#3
0
  def test_save_only(self, user_mock):
    user_mock.prompt.return_value = 'SomeWidget'
    record = yield self._test

    testrun_output = io.BytesIO()
    callback = mfg_inspector.MfgInspector()

    callback.set_converter(
        converter=test_runs_converter.test_run_from_test_record,)
    save_to_disk_callback = callback.save_to_disk(
        filename_pattern=testrun_output)
    save_to_disk_callback(record)

    # Parse what was written to BytesIO back into a proto and compare
    testrun_output.seek(0)
    testrun = test_runs_pb2.TestRun()
    testrun.ParseFromString(testrun_output.read())

    expected_test_run_proto = test_runs_converter.test_run_from_test_record(
        record)
    self.assertEqual(expected_test_run_proto, testrun)

    self.assertFalse(self.mock_send_mfg_inspector_data.called)
示例#4
0
import unittest

import mock

import openhtf as htf
from openhtf import util
from examples import all_the_things
from openhtf.output.callbacks import mfg_inspector
from openhtf.output.proto import guzzle_pb2
from openhtf.output.proto import test_runs_converter
from openhtf.output.proto import test_runs_pb2
from openhtf.util import test

MOCK_TEST_RUN_PROTO = test_runs_pb2.TestRun(
    tester_name='mock_test_run',
    dut_serial='UNITTEST1234',
    test_status=test_runs_pb2.PASS,
    test_info=test_runs_pb2.TestInfo(name='unit_test'))

MOCK_TEST_RUN = collections.namedtuple('Testrun',
                                       mfg_inspector.MfgInspector.PARAMS)(None,
                                                                          None,
                                                                          None,
                                                                          None)


class TestMfgInspector(test.TestCase):

  def setUp(self):
    super(TestMfgInspector, self).setUp()
    self.mock_credentials = mock.patch(
示例#5
0
import io
import unittest
from unittest import mock

import openhtf as htf
from openhtf import util
from examples import all_the_things
from openhtf.output.callbacks import mfg_inspector
from openhtf.output.proto import guzzle_pb2
from openhtf.output.proto import test_runs_converter
from openhtf.output.proto import test_runs_pb2
from openhtf.util import test

MOCK_TEST_RUN_PROTO = test_runs_pb2.TestRun(  # pytype: disable=module-attr  # gen-stub-imports
    tester_name='mock_test_run',
    dut_serial='UNITTEST1234',
    test_status=test_runs_pb2.PASS,
    test_info=test_runs_pb2.TestInfo(name='unit_test'))  # pytype: disable=module-attr  # gen-stub-imports

MOCK_TEST_RUN = collections.namedtuple('Testrun',
                                       mfg_inspector.MfgInspector.PARAMS)(None,
                                                                          None,
                                                                          None,
                                                                          None)


class TestMfgInspector(test.TestCase):
    def setUp(self):
        super(TestMfgInspector, self).setUp()
        self.mock_credentials = mock.patch(
            'oauth2client.client.SignedJwtAssertionCredentials').start(