diff --git a/openhtf/__init__.py b/openhtf/__init__.py index 0dd2e3672..996c52002 100644 --- a/openhtf/__init__.py +++ b/openhtf/__init__.py @@ -14,6 +14,7 @@ """The main OpenHTF entry point.""" import signal +import sys import typing from openhtf.core import phase_executor @@ -112,6 +113,7 @@ Subtest = openhtf.core.phase_collections.Subtest diagnose = openhtf.core.phase_descriptor.diagnose + measures = openhtf.core.phase_descriptor.measures PhaseDescriptor = openhtf.core.phase_descriptor.PhaseDescriptor PhaseNameCase = openhtf.core.phase_descriptor.PhaseNameCase @@ -147,3 +149,7 @@ def get_version(): # Register signal handler to stop all tests on SIGINT. Test.DEFAULT_SIGINT_HANDLER = signal.signal(signal.SIGINT, Test.handle_sig_int) + +if sys.version_info.major == 3 and sys.version_info.minor >= 10: + import collections + setattr(collections, "MutableMapping", collections.abc.MutableMapping) diff --git a/openhtf/core/dut_id.py b/openhtf/core/dut_id.py new file mode 100644 index 000000000..35b2bde56 --- /dev/null +++ b/openhtf/core/dut_id.py @@ -0,0 +1,15 @@ +from dataclasses import dataclass +from typing import Optional +from dataclasses import dataclass + + +@dataclass +class DutIdentifier: + halter_serial_number: Optional [str] = None + mac_address: Optional[str] = None + part_number: Optional[str] = None + additional: Optional[dict] = None + + @property + def test_id(self) -> str: + return self.halter_serial_number diff --git a/openhtf/core/test_descriptor.py b/openhtf/core/test_descriptor.py index 94aa466fa..649201253 100644 --- a/openhtf/core/test_descriptor.py +++ b/openhtf/core/test_descriptor.py @@ -45,6 +45,7 @@ from openhtf.core import test_executor from openhtf.core import test_record as htf_test_record from openhtf.core import test_state +from openhtf.core.dut_id import DutIdentifier from openhtf.util import configuration from openhtf.util import console_output @@ -276,7 +277,9 @@ def abort_from_sig_int(self) -> None: def execute(self, test_start: Optional[Union[phase_descriptor.PhaseT, - Callable[[], str]]] = None, + Callable[[], str], + Callable[[], DutIdentifier], + ]] = None, profile_filename: Optional[Text] = None) -> bool: """Starts the framework and executes the given test. @@ -300,7 +303,7 @@ def execute(self, self._test_desc.phase_sequence) # Lock this section so we don't .stop() the executor between instantiating # it and .Start()'ing it, doing so does weird things to the executor state. - with self._lock: + with (self._lock): # Sanity check to make sure someone isn't doing something weird like # trying to Execute() the same test twice in two separate threads. We # hold the lock between here and Start()'ing the executor to guarantee @@ -317,7 +320,13 @@ def execute(self, @phase_descriptor.PhaseOptions() def trigger_phase(test): - test.test_record.dut_id = typing.cast(types.LambdaType, test_start)() + dut_id = typing.cast(types.LambdaType, test_start)() + if isinstance(dut_id, DutIdentifier): + test.test_record.dut_id = dut_id.test_id + test.test_record.dut_extended_id = dut_id + else: + test.test_record.dut_id = dut_id + test.test_record.dut_extended_id = DutIdentifier() trigger = trigger_phase else: diff --git a/openhtf/core/test_record.py b/openhtf/core/test_record.py index bddce0357..1a387bdbb 100644 --- a/openhtf/core/test_record.py +++ b/openhtf/core/test_record.py @@ -16,6 +16,7 @@ import enum import hashlib import inspect +import json import logging import os import tempfile @@ -24,6 +25,7 @@ import attr from openhtf import util +from openhtf.core.dut_id import DutIdentifier from openhtf.util import configuration from openhtf.util import data from openhtf.util import logs @@ -167,6 +169,7 @@ class TestRecord(object): """The record of a single run of a test.""" dut_id = attr.ib(type=Optional[Text]) + dut_extended_id = attr.ib(type=Optional[DutIdentifier]) station_id = attr.ib(type=Text) start_time_millis = attr.ib(type=int, default=0) end_time_millis = attr.ib(type=Optional[int], default=None) @@ -250,6 +253,7 @@ def as_base_types(self) -> Dict[Text, Any]: metadata['config'] = self._cached_config_from_metadata ret = { 'dut_id': data.convert_to_base_types(self.dut_id), + #'dut_extended_id': data.convert_to_base_types (self.dut_extended_id), 'start_time_millis': self.start_time_millis, 'end_time_millis': self.end_time_millis, 'outcome': data.convert_to_base_types(self.outcome), diff --git a/openhtf/core/test_state.py b/openhtf/core/test_state.py index 3c408a77a..673b77eb9 100644 --- a/openhtf/core/test_state.py +++ b/openhtf/core/test_state.py @@ -174,6 +174,7 @@ def __init__(self, test_desc: 'test_descriptor.TestDescriptor', self.test_record = test_record.TestRecord( dut_id=None, + dut_extended_id=None, station_id=CONF.station_id, code_info=test_desc.code_info, start_time_millis=0,