Skip to content

Commit

Permalink
Rename functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuan Ren committed Nov 14, 2024
1 parent 802247f commit 68f0f72
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/qcodes/extensions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
InferAttrs,
InferError,
get_chain_links_of_type,
get_instrument_from_chain,
get_instrument_from_param,
get_parameter_chain,
get_parent_instruments_from_chain_of_type,
get_root_parameter,
get_sole_chain_link_of_type,
get_sole_instrument_from_chain,
get_sole_parent_instrument_from_chain_of_type,
infer_channel,
infer_instrument,
infer_instrument_module,
Expand All @@ -32,8 +32,8 @@
"get_parameter_chain",
"get_root_parameter",
"get_sole_chain_link_of_type",
"get_instrument_from_chain",
"get_sole_instrument_from_chain",
"get_parent_instruments_from_chain_of_type",
"get_sole_parent_instrument_from_chain_of_type",
"infer_channel",
"infer_instrument",
"infer_instrument_module",
Expand Down
10 changes: 5 additions & 5 deletions src/qcodes/extensions/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,11 @@ def get_sole_chain_link_of_type(
return chain_links[0]


def get_instrument_from_chain(
def get_parent_instruments_from_chain_of_type(
instrument_type: type[TInstrument] | tuple[type[TInstrument], ...],
parameter: Parameter,
) -> tuple[TInstrument, ...]:
"""Gets all instruments in a chain of linked parameters that match a given type"""
"""Gets all parent instruments in a chain of linked parameters that match a given type"""

param_chain = get_parameter_chain(parameter)
return tuple(
Expand All @@ -272,12 +272,12 @@ def get_instrument_from_chain(
)


def get_sole_instrument_from_chain(
def get_sole_parent_instrument_from_chain_of_type(
instrument_type: type[TInstrument] | tuple[type[TInstrument], ...],
parameter: Parameter,
) -> TInstrument:
"""Gets the one instruments in a chain of linked parameters that match a given type"""
instruments = get_instrument_from_chain(
"""Gets the one parent instruments in a chain of linked parameters that match a given type"""
instruments = get_parent_instruments_from_chain_of_type(
instrument_type=instrument_type, parameter=parameter
)
if len(instruments) != 1:
Expand Down
18 changes: 12 additions & 6 deletions tests/extensions/test_infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
InferError,
_merge_user_and_class_attrs,
get_chain_links_of_type,
get_instrument_from_chain,
get_parameter_chain,
get_parent_instruments_from_chain_of_type,
get_root_parameter,
get_sole_chain_link_of_type,
get_sole_instrument_from_chain,
get_sole_parent_instrument_from_chain_of_type,
infer_channel,
infer_instrument,
)
Expand Down Expand Up @@ -359,7 +359,9 @@ def test_get_instrument_from_chain(
good_inst_del_1, good_inst_del_2, good_inst_del_3 = multi_inst_chain

InferAttrs.add("linked_parameter")
instruments = get_instrument_from_chain(DummyInstrument, good_inst_del_3)
instruments = get_parent_instruments_from_chain_of_type(
DummyInstrument, good_inst_del_3
)
assert set(instruments) == set([inst, inst2])


Expand All @@ -368,15 +370,19 @@ def test_get_sole_instrument_from_chain(instrument_fixture2, multi_inst_chain):
good_inst_del_1, good_inst_del_2, good_inst_del_3 = multi_inst_chain

InferAttrs.add("linked_parameter")
sole_instrument = get_sole_instrument_from_chain(DummyInstrument2, good_inst_del_3)
sole_instrument = get_sole_parent_instrument_from_chain_of_type(
DummyInstrument2, good_inst_del_3
)
assert sole_instrument == inst2

with pytest.raises(ValueError) as exc_info:
_ = get_sole_instrument_from_chain(DummyInstrument, good_inst_del_3)
_ = get_sole_parent_instrument_from_chain_of_type(
DummyInstrument, good_inst_del_3
)
assert "Expected only a single instrument of type" in str(exc_info.value)

with pytest.raises(ValueError) as exc_info:
_ = get_sole_instrument_from_chain(
_ = get_sole_parent_instrument_from_chain_of_type(
(DummyInstrument, DummyInstrument2), good_inst_del_3
)
assert "Expected only a single instrument of types" in str(exc_info.value)

0 comments on commit 68f0f72

Please sign in to comment.