From 68f0f72de47d38a67e90a7b29f05486210e0340b Mon Sep 17 00:00:00 2001 From: Yuan Ren Date: Thu, 14 Nov 2024 10:54:40 -0800 Subject: [PATCH] Rename functions --- src/qcodes/extensions/__init__.py | 8 ++++---- src/qcodes/extensions/infer.py | 10 +++++----- tests/extensions/test_infer.py | 18 ++++++++++++------ 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/qcodes/extensions/__init__.py b/src/qcodes/extensions/__init__.py index 918b822961b..200b54760c1 100644 --- a/src/qcodes/extensions/__init__.py +++ b/src/qcodes/extensions/__init__.py @@ -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, @@ -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", diff --git a/src/qcodes/extensions/infer.py b/src/qcodes/extensions/infer.py index cb4c0676416..5cf2e90c3d8 100644 --- a/src/qcodes/extensions/infer.py +++ b/src/qcodes/extensions/infer.py @@ -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( @@ -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: diff --git a/tests/extensions/test_infer.py b/tests/extensions/test_infer.py index 26bf78e0b49..fd53756999b 100644 --- a/tests/extensions/test_infer.py +++ b/tests/extensions/test_infer.py @@ -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, ) @@ -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]) @@ -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)