Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add set_time_millis to measurement #1140

Merged
3 commits merged into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions openhtf/core/measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def WidgetTestPhase(test):
import enum
import functools
import logging
import time
import typing
from typing import Any, Callable, Dict, Iterator, List, Optional, Text, Tuple, Union

Expand Down Expand Up @@ -189,6 +190,7 @@ class Measurement(object):
outcome: One of the Outcome() enumeration values, starting at UNSET.
marginal: A bool flag indicating if this measurement is marginal if the
outcome is PASS.
set_time_millis: The time the measurement is set in milliseconds.
_cached: A cached dict representation of this measurement created initially
during as_base_types and updated in place to save allocation time.
"""
Expand All @@ -214,6 +216,7 @@ class Measurement(object):
_notification_cb = attr.ib(type=Optional[Callable[[], None]], default=None)
outcome = attr.ib(type=Outcome, default=Outcome.UNSET)
marginal = attr.ib(type=bool, default=False)
set_time_millis = attr.ib(type=int, default=None)

# Runtime cache to speed up conversions.
_cached = attr.ib(type=Optional[Dict[Text, Any]], default=None)
Expand Down Expand Up @@ -845,6 +848,7 @@ def __setitem__(self, name: Text, value: Any) -> None:
'Cannot set dimensioned measurement without indices')
m.measured_value.set(value)
m.notify_value_set()
m.set_time_millis = util.time_millis()

def __getitem__(self, name: Text) -> Any:
self._assert_valid_key(name)
Expand Down
2 changes: 2 additions & 0 deletions test/core/diagnoses_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,7 @@ def check_record_diagnoser(phase_record):
is_value_set=True,
stored_value=True,
cached_value=True),
set_time_millis=phase_record.measurements['pass_measure'].set_time_millis,
cached=mock.ANY), phase_record.measurements['pass_measure'])
self.assertEqual(
htf.Measurement(
Expand All @@ -1175,6 +1176,7 @@ def check_record_diagnoser(phase_record):
stored_value=False,
cached_value=False),
validators=[is_true],
set_time_millis=phase_record.measurements['fail_measure'].set_time_millis,
cached=mock.ANY), phase_record.measurements['fail_measure'])
return None

Expand Down
Loading