Example #1
0
 def testJson(self):
     json_output = StringIO()
     json_factory.OutputToJSON(json_output, sort_keys=True,
                               indent=2)(self.record)
     if self.UPDATE_OUTPUT:
         with open(_LocalFilename('record.json'), 'wb') as jsonfile:
             jsonfile.write(json_output.getvalue())
     else:
         data.AssertEqualsAndDiff(self.json, json_output.getvalue())
Example #2
0
def _AttachJson(record, testrun):
  """Attach a copy of the JSON-ified record as an info parameter.

  Save a copy of the JSON-ified record in an attachment so we can access
  un-mangled fields later if we want.  Remove attachments since those get
  copied over and can potentially be quite large.
  """
  record_dict = data.ConvertToBaseTypes(record, ignore_keys=('attachments',))
  record_json = json_factory.OutputToJSON(sort_keys=True).encode(record_dict)
  testrun_param = testrun.info_parameters.add()
  testrun_param.name = 'OpenHTF_record.json'
  testrun_param.value_binary = record_json
  # pylint: disable=no-member
  testrun_param.type = testrun_pb2.InformationParameter.TEXT_UTF8
Example #3
0
  # As described above, this is how measurements are set.  The value that has
  # been set can also be accessed, but should only be set once (this will be
  # enforced in the future, for now it's best-practice).
  test.measurements.hello_world_measurement = 'Hello Again!'


if __name__ == '__main__':
  # We instantiate our OpenHTF test with the phases we want to run as args.
  # Multiple phases would be passed as additional args, and additional
  # keyword arguments may be passed as well.  See other examples for more
  # complex uses.
  test = Test(hello_world)

  # In order to view the result of the test, we have to output it somewhere,
  # and a local JSON file is a convenient way to do this.  Custom output
  # mechanisms can be implemented, but for now we'll just keep it simple.
  # This will always output to the same ./hello_world.json file, formatted
  # slightly for human readability.
  test.AddOutputCallbacks(
      json_factory.OutputToJSON('./{dut_id}.hello_world.json', indent=2))

  # PromptForTestStart prompts the operator for a DUT ID, a unique identifier
  # for the DUT (Device Under Test).  OpenHTF requires that a DUT ID is set
  # each time a test is executed.  It may be set programmatically, but the
  # simplest way to get one is to prompt the user for it.  If test_start is
  # not provided, the test will start immediately and assume the DUT ID will
  # be set later (OpenHTF will raise an exception when the test completes if
  # a DUT ID has not been set).
  test.Execute(test_start=triggers.PromptForTestStart())
Example #4
0
    test.Attach('test_attachment', 'This is test attachment data.')
    test.AttachFromFile('example_attachment.txt')


if __name__ == '__main__':
    test = openhtf.Test(
        hello_world,
        set_measurements,
        dimensions,
        attachments,
        # Some metadata fields, these in particular are used by mfg-inspector,
        # but you can include any metadata fields.
        test_name='MyTest',
        test_description='OpenHTF Example Test',
        test_version='1.0.0')
    test.AddOutputCallbacks(
        json_factory.OutputToJSON('./%(dut_id)s.%(start_time_millis)s.json',
                                  indent=4))
    #test.AddOutputCallbacks(mfg_inspector.OutputToTestRunProto(
    #    './%(dut_id)s.%(start_time_millis)s.pb'))
    # Example of how to upload to mfg-inspector.  Replace filename with your
    # JSON-formatted private key downloaded from Google Developers Console
    # when you created the Service Account you intend to use, or name it
    # 'my_private_key.json'.
    #if os.path.isfile('my_private_key.json'):
    #  with open('my_private_key.json', 'r') as json_file:
    #    test.AddOutputCallbacks(mfg_inspector.UploadToMfgInspector.from_json(
    #        json.load(json_file)))

    test.Execute(test_start=triggers.PromptForTestStart())
Example #5
0

if __name__ == '__main__':
    test = openhtf.Test(
        hello_world,
        set_measurements,
        dimensions,
        attachments,
        # Some metadata fields, these in particular are used by mfg-inspector,
        # but you can include any metadata fields.
        test_name='MyTest',
        test_description='OpenHTF Example Test',
        test_version='1.0.0')
    test.AddOutputCallbacks(
        json_factory.OutputToJSON(
            './{dut_id}.{metadata[test_name]}.{start_time_millis}.json',
            indent=4))
    test.AddOutputCallbacks(
        mfg_inspector.OutputToTestRunProto(
            './{dut_id}.{start_time_millis}.pb'))
    # Example of how to upload to mfg-inspector.  Replace filename with your
    # JSON-formatted private key downloaded from Google Developers Console
    # when you created the Service Account you intend to use, or name it
    # 'my_private_key.json'.
    #if os.path.isfile('my_private_key.json'):
    #  with open('my_private_key.json', 'r') as json_file:
    #    test.AddOutputCallbacks(output.UploadToMfgInspector.from_json(
    #        json.load(json_file)))
    test.Configure(http_port=None, teardown_function=teardown)
    test.Execute(test_start=triggers.PromptForTestStart())
Example #6
0
          docstring='This measurement is declared inline!',
          units=UOM['HERTZ'],
          validators=[validators.InRange(0, 10)])
@measures('another_inline', docstring='Because why not?')
def InlinePhase(test):
    # This measurement will have an outcome of FAIL, because the set value of 15
    # will not pass the 0 <= x <= 10 validator.
    test.measurements.inline_kwargs = 15
    test.measurements.another_inline = 'This one is unvalidated.'

    # Let's log a message so the operator knows the test should fail.
    test.logger.info('Set inline_kwargs to a failing value, test should FAIL!')


if __name__ == '__main__':
    # We instantiate our OpenHTF test with the phases we want to run as args.
    test = Test(HelloPhase, AgainPhase, LotsOfMeasurements, MeasureSeconds,
                InlinePhase)

    # In order to view the result of the test, we have to output it somewhere,
    # and a local JSON file is a convenient way to do this.  Custom output
    # mechanisms can be implemented, but for now we'll just keep it simple.
    # This will always output to the same ./measurements.json file, formatted
    # slightly for human readability.
    test.AddOutputCallbacks(
        json_factory.OutputToJSON('./measurements.json', indent=2))

    # Unlike hello_world.py, where we prompt for a DUT ID, here we'll just
    # use an arbitrary one.
    test.Execute(test_start=lambda: 'MyDutId')
Example #7
0
    # As described above, this is how measurements are set.  The value that has
    # been set can also be accessed, but should only be set once (this will be
    # enforced in the future, for now it's best-practice).
    test.measurements.hello_world_measurement = 'Hello Again!'


if __name__ == '__main__':
    # We instantiate our OpenHTF test with the phases we want to run as args.
    # Multiple phases would be passed as additional args, and additional
    # keyword arguments may be passed as well.  See other examples for more
    # complex uses.
    test = Test(hello_world)

    # In order to view the result of the test, we have to output it somewhere,
    # and a local JSON file is a convenient way to do this.  Custom output
    # mechanisms can be implemented, but for now we'll just keep it simple.
    # This will always output to the same ./hello_world.json file, formatted
    # slightly for human readability.
    test.AddOutputCallbacks(
        json_factory.OutputToJSON('./hello_world.json', indent=2))

    # PromptForTestStart prompts the operator for a DUT ID, a unique identifier
    # for the DUT (Device Under Test).  OpenHTF requires that a DUT ID is set
    # each time a test is executed.  It may be set programmatically, but the
    # simplest way to get one is to prompt the user for it.  If test_start is
    # not provided, the test will start immediately and assume the DUT ID will
    # be set later (OpenHTF will raise an exception when the test completes if
    # a DUT ID has not been set).
    test.Execute(test_start=triggers.PromptForTestStart())