Skip to content

Commit

Permalink
Merge pull request #1140 from google:wallacbe-set_time
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 611654940
  • Loading branch information
copybara-github committed Mar 1, 2024
2 parents 2fccdbf + 4cf0734 commit 2f840a3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
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

0 comments on commit 2f840a3

Please sign in to comment.