Skip to content
Closed
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: 3 additions & 1 deletion openhtf/core/monitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ def get_value(self) -> Any:
else:
# Only pass in args that the monitor phase takes.
kwargs = {
arg: val for arg, val in self.extra_kwargs if arg in argspec_args
arg: val
for arg, val in self.extra_kwargs.items()
if arg in argspec_args
}
return self.monitor_desc.with_args(**kwargs)(self.test_state)

Expand Down
20 changes: 20 additions & 0 deletions test/core/monitors_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from openhtf import plugs
from openhtf.core import base_plugs
from openhtf.core import monitors
from openhtf.core import phase_descriptor


class EmptyPlug(base_plugs.BasePlug):
Expand Down Expand Up @@ -96,3 +97,22 @@ def phase(test):
first_meas[0], 100, msg='At time 0, there should be a call made.')
self.assertEqual(
2, first_meas[1], msg="And it should be the monitor func's return val")

def test_get_value_with_extra_kwargs(self):
"""Monitor without **kwargs handles a phase carrying extra_kwargs.

A phase that has been parameterized with PhaseDescriptor.with_args() carries
its kwargs in extra_kwargs. The monitor thread forwards those kwargs to the
monitor function, keeping only the arguments the monitor accepts. This used
to iterate over the extra_kwargs dict directly (yielding keys) and unpack
each key into two names, raising `ValueError: too many values to unpack`.
"""

def monitor_func(test):
del test # Unused.
return 1

monitor_thread = monitors._MonitorThread(
'meas', phase_descriptor.PhaseDescriptor(monitor_func),
{'port': 1234}, self.test_state, 1000)
self.assertEqual(1, monitor_thread.get_value())