Skip to content

Bug: snapshot fails when instantiating InstrumentBase #1209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
5 changes: 3 additions & 2 deletions qcodes/instrument/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ def __init__(self, name: str,
'ChannelList']] = {}
super().__init__(**kwargs)

# This is needed for snapshot method to work
self._meta_attrs = ['name']

def add_parameter(self, name: str,
parameter_class: type=Parameter, **kwargs) -> None:
"""
Expand Down Expand Up @@ -396,8 +399,6 @@ def __init__(self, name: str,
self.add_parameter('IDN', get_cmd=self.get_idn,
vals=Anything())

self._meta_attrs = ['name']

self.record_instance(self)

def get_idn(self) -> Dict[str, Optional[str]]:
Expand Down
3 changes: 2 additions & 1 deletion qcodes/instrument/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def __init__(self, parent: Instrument, name: str, **kwargs) -> None:

self.name = "{}_{}".format(parent.name, str(name))
self.short_name = str(name)
self._meta_attrs = ['name']

self._parent = parent

Expand Down Expand Up @@ -73,6 +72,7 @@ def name_parts(self) -> List[str]:
name_parts.append(self.short_name)
return name_parts


class MultiChannelInstrumentParameter(MultiParameter):
"""
Parameter to get or set multiple channels simultaneously.
Expand Down Expand Up @@ -122,6 +122,7 @@ def full_names(self):

return self.names


class ChannelList(Metadatable):
"""
Container for channelized parameters that allows for sweeps over
Expand Down
28 changes: 27 additions & 1 deletion qcodes/tests/test_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Test suite for instument.*
"""
from unittest import TestCase
from qcodes.instrument.base import Instrument
from qcodes.instrument.base import Instrument, InstrumentBase
from .instrument_mocks import DummyInstrument, MockParabola
from qcodes.instrument.parameter import Parameter
import gc
Expand Down Expand Up @@ -111,7 +111,33 @@ def test_snapshot_value(self):

snapshot = self.instrument.snapshot()

self.assertIn('name', snapshot)
self.assertEqual('testdummy', snapshot['name'])

self.assertIn('value', snapshot['parameters']['has_snapshot_value'])
self.assertEqual(42,
snapshot['parameters']['has_snapshot_value']['value'])
self.assertNotIn('value', snapshot['parameters']['no_snapshot_value'])


class TestInstrumentBase(TestCase):
"""
This class contains tests that are relevant to the InstrumentBase class.
"""

def test_snapshot_and_meta_attrs(self):
"""Test snapshot of InstrumentBase contains _meta_attrs attributes"""
instr = InstrumentBase('instr')

self.assertEqual(instr.name, 'instr')

self.assertTrue(hasattr(instr, '_meta_attrs'))
self.assertListEqual(instr._meta_attrs, ['name'])

snapshot = instr.snapshot()

self.assertIn('name', snapshot)
self.assertEqual('instr', snapshot['name'])

self.assertIn('__class__', snapshot)
self.assertIn('InstrumentBase', snapshot['__class__'])