Skip to content

Commit

Permalink
Merge pull request microsoft#2099 from QCoDeS/astafan8-station-config…
Browse files Browse the repository at this point in the history
…-instrument-name-order

Station: Pass name as kwarg so that its order in instrument class is not relevant
  • Loading branch information
astafan8 authored Aug 4, 2020
2 parents 4437d84 + 5151792 commit 7025bb9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion qcodes/station.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def load_instrument(self, identifier: str,
instr_class_name = instr_cfg['type'].split('.')[-1]
module = importlib.import_module(module_name)
instr_class = getattr(module, instr_class_name)
instr = instr_class(name, **instr_kwargs)
instr = instr_class(name=name, **instr_kwargs)

def resolve_instrument_identifier(
instrument: ChannelOrInstrumentBase,
Expand Down
36 changes: 36 additions & 0 deletions qcodes/tests/test_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,42 @@ def test_name_init_kwarg(simple_mock_station):
assert st.components['test'] is mock


def test_name_specified_in_init_in_yaml_is_used():
st = station_from_config_str(
"""
instruments:
mock:
type: qcodes.tests.instrument_mocks.DummyInstrument
init:
name: dummy
""")

mock = st.load_instrument('mock')
assert isinstance(mock, DummyInstrument)
assert mock.name == 'dummy'
assert st.components['dummy'] is mock


class InstrumentWithNameAsNotFirstArgument(Instrument):
def __init__(self, first_arg, name):
super(InstrumentWithNameAsNotFirstArgument, self).__init__(name)
self._first_arg = first_arg


def test_able_to_load_instrument_with_name_argument_not_being_the_first():
st = station_from_config_str(
"""
instruments:
name_goes_second:
type: qcodes.tests.test_station.InstrumentWithNameAsNotFirstArgument
""")

instr = st.load_instrument('name_goes_second', first_arg=42)
assert isinstance(instr, InstrumentWithNameAsNotFirstArgument)
assert instr.name == 'name_goes_second'
assert st.components['name_goes_second'] is instr


def test_setup_alias_parameters():
st = station_from_config_str("""
instruments:
Expand Down

0 comments on commit 7025bb9

Please sign in to comment.