Ejemplo n.º 1
0
 def test_json(self, user_mock):
     user_mock.prompt.return_value = 'SomeWidget'
     record = yield self._test
     json_output = io.BytesIO()
     json_factory.OutputToJSON(json_output, sort_keys=True,
                               indent=2)(record)
     json_output.seek(0)
     json.loads(json_output.read())
Ejemplo n.º 2
0
 def test_json(self, user_mock):
     user_mock.prompt.return_value = 'SomeWidget'
     record = yield self._test
     if sys.version_info[0] < 3:
         json_output = BytesIO()
     else:
         json_output = StringIO()
     json_factory.OutputToJSON(json_output, sort_keys=True,
                               indent=2)(record)
Ejemplo n.º 3
0
 def test_json(self):
     json_output = StringIO()
     json_factory.OutputToJSON(json_output, sort_keys=True,
                               indent=2)(self.record)
     if self.UPDATE_OUTPUT:
         with open(_local_filename('record.json'), 'wb') as jsonfile:
             jsonfile.write(json_output.getvalue())
     else:
         self.assertTrue(
             data.equals_log_diff(self.json, json_output.getvalue()))
Ejemplo n.º 4
0
def _attach_json(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_json = json_factory.OutputToJSON(
      inline_attachments=False,
      sort_keys=True, indent=2).serialize_test_record(record)
  testrun_param = testrun.info_parameters.add()
  testrun_param.name = 'OpenHTF_record.json'
  testrun_param.value_binary = record_json.encode('utf-8')
  # pylint: disable=no-member
  testrun_param.type = test_runs_pb2.TEXT_UTF8
Ejemplo n.º 5
0
def main():
    # We instantiate our OpenHTF test with the phases we want to run as args.
    test = htf.Test(hello_phase, again_phase, lots_of_measurements,
                    measure_seconds, inline_phase, multdim_measurements)

    # 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.add_output_callbacks(
        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')
Ejemplo n.º 6
0
def main():
    test = htf.Test(
        htf.PhaseGroup.with_teardown(teardown)(
            hello_world,
            set_measurements,
            dimensions,
            attachments,
            skip_phase,
            measures_with_args.with_args(minimum=1, maximum=4),
            measures_with_marginal_args.with_args(marginal_minimum=4,
                                                  marginal_maximum=6),
            analysis,
        ),
        # 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.add_output_callbacks(
        callbacks.OutputToFile(
            './{dut_id}.{metadata[test_name]}.{start_time_millis}.pickle'))
    test.add_output_callbacks(
        json_factory.OutputToJSON(
            './{dut_id}.{metadata[test_name]}.{start_time_millis}.json',
            indent=4))
    test.add_output_callbacks(console_summary.ConsoleSummary())

    # Example of how to output to testrun protobuf format and save to disk then
    # upload.  Replace json_file 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'.
    # inspector = (mfg_inspector.MfgInspector
    #    .from_json(json.load(json_file)))
    #    .set_converter(test_runs_converter.test_run_from_test_record))
    # test.add_output_callbacks(
    #     inspector.save_to_disk('./{dut_id}.{start_time_millis}.pb'),
    #     inspector.upload())

    test.execute(test_start=user_input.prompt_for_test_start())
Ejemplo n.º 7
0
def main():
    # We instantiate our OpenHTF test with the phases we want to run as args.
    test = htf.Test(
        measurements_example.hello_phase,
        measurements_example.again_phase,
        failing_phase,
        measurements_example.lots_of_measurements,
        checkpoints.checkpoint(),
        long_running_phase,
    )

    # In order to view the result of the test, we have to output it somewhere,
    # outputting to console is an easy way to do this.
    test.add_output_callbacks(console_summary.ConsoleSummary())

    # The complete summary is viable in json, including the measurements
    # included in measurements_example.lots_of_measurements.
    test.add_output_callbacks(
        json_factory.OutputToJSON('./checkpoints.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')
Ejemplo n.º 8
0
def 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 = htf.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.add_output_callbacks(
        json_factory.OutputToJSON('./{dut_id}.hello_world.json', indent=2))

    # prompt_for_test_start 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=user_input.prompt_for_test_start())
Ejemplo n.º 9
0
        set_measurements,
        dimensions,
        attachments,
        skip_phase,
        measures_with_args.with_args(min=2, max=4),
        # 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.add_output_callbacks(
        callbacks.OutputToFile(
            './{dut_id}.{metadata[test_name]}.{start_time_millis}.pickle'))
    test.add_output_callbacks(
        json_factory.OutputToJSON(
            './{dut_id}.{metadata[test_name]}.{start_time_millis}.json',
            indent=4))

    # Example of how to output to testrun protobuf format.
    #test.add_output_callbacks(
    #  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.add_output_callbacks(mfg_inspector.UploadToMfgInspector.from_json(
    #        json.load(json_file)))
Ejemplo n.º 10
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 = htf.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.add_output_callbacks(
        json_factory.OutputToJSON('./{dut_id}.hello_world.json', indent=2))

    # prompt_for_test_start 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=user_input.prompt_for_test_start())
Ejemplo n.º 11
0
    # checkpoint phase is run right before this phase.
    for i in range(10):
        test.logger.info('Still running....')
        time.sleep(10)
    test.logger.info('Done with long_running_phase')


if __name__ == '__main__':
    # We instantiate our OpenHTF test with the phases we want to run as args.
    test = htf.Test(
        measurements_example.hello_phase,
        measurements_example.again_phase,
        failing_phase,
        measurements_example.lots_of_measurements,
        checkpoints.checkpoint(),
        long_running_phase,
    )

    # In order to view the result of the test, we have to output it somewhere,
    # outputting to console is an easy way to do this.
    test.add_output_callbacks(console_summary.ConsoleSummary())

    # The complete summary is viable in json, including the measurements
    # included in measurements_example.lots_of_measurements.
    test.add_output_callbacks(
        json_factory.OutputToJSON('./checkpoints.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')
Ejemplo n.º 12
0
    test.logger.info('This is what a dataframe looks like:\n%s', power_df)
    test.measurements['average_voltage'] = power_df['V'].mean()

    # We can convert the dataframe to a numpy array as well
    power_array = power_df.as_matrix()
    test.logger.info('This is the same data in a numpy array:\n%s',
                     power_array)
    test.measurements['average_current'] = power_array.mean(axis=0)[2]

    # Finally, let's estimate the resistance
    test.measurements['resistance'] = (test.measurements['average_voltage'] /
                                       test.measurements['average_current'])


if __name__ == '__main__':
    # We instantiate our OpenHTF test with the phases we want to run as args.
    test = htf.Test(hello_phase, again_phase, lots_of_measurements,
                    measure_seconds, inline_phase, multdim_measurements)

    # 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.add_output_callbacks(
        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')
Ejemplo n.º 13
0
 def test_json(self, user_mock):
     user_mock.prompt.return_value = 'SomeWidget'
     record = yield self._test
     json_output = StringIO()
     json_factory.OutputToJSON(json_output, sort_keys=True,
                               indent=2)(record)