示例#1
0
def test_instrument_fail(close_before_and_after):
    with pytest.raises(RuntimeError, match="Failed to create instrument"):
        DummyFailingInstrument(name="failinginstrument")

    assert Instrument.instances() == []
    assert DummyFailingInstrument.instances() == []
    assert Instrument._all_instruments == {}
示例#2
0
    def test_check_instances(self):
        with self.assertRaises(KeyError):
            DummyInstrument(name='testdummy', gates=['dac1', 'dac2', 'dac3'])

        self.assertEqual(Instrument.instances(), [])
        self.assertEqual(DummyInstrument.instances(), [self.instrument])
        self.assertEqual(self.instrument.instances(), [self.instrument])
示例#3
0
def test_check_instances(testdummy):
    with pytest.raises(KeyError, match='Another instrument has the name: testdummy'):
        DummyInstrument(name='testdummy', gates=['dac1', 'dac2', 'dac3'])

    assert Instrument.instances() == []
    assert DummyInstrument.instances() == [testdummy]
    assert testdummy.instances() == [testdummy]
示例#4
0
    def test_check_instances(self):
        with self.assertRaises(KeyError) as cm:
            DummyInstrument(name='testdummy', gates=['dac1', 'dac2', 'dac3'])
        assert str(cm.exception) == "'Another instrument has the name: testdummy'"

        self.assertEqual(Instrument.instances(), [])
        self.assertEqual(DummyInstrument.instances(), [self.instrument])
        self.assertEqual(self.instrument.instances(), [self.instrument])
示例#5
0
def test_instrument_allows_channel_name_starting_with_number(close_before_and_after):
    instr = DummyChannelInstrument(name="foo", channel_names=["1", "2", "3"])

    for chan in instr.channels:
        assert chan.short_name.isidentifier() is False
        assert chan.full_name.isidentifier() is True
    assert Instrument.instances() == []
    assert DummyChannelInstrument.instances() == [instr]
    assert Instrument._all_instruments != {}
示例#6
0
def test_instrument_retry_with_same_name(close_before_and_after):
    with pytest.raises(RuntimeError, match="Failed to create instrument"):
        DummyFailingInstrument(name="failinginstrument")
    instr = DummyFailingInstrument(name="failinginstrument", fail=False)

    # Check that the instrument is successfully registered after failing first
    assert Instrument.instances() == []
    assert DummyFailingInstrument.instances() == [instr]
    expected_dict = weakref.WeakValueDictionary()
    expected_dict["failinginstrument"] = instr
    assert Instrument._all_instruments == expected_dict
示例#7
0
def test_instrument_on_invalid_identifier(close_before_and_after):
    # Check if warning and error raised when invalid identifer name given
    with pytest.warns(
        UserWarning, match="Changed !-name to !_name for instrument identifier"
    ):
        with pytest.raises(ValueError, match="!_name invalid instrument identifier"):
            DummyInstrument(name="!-name")

    assert Instrument.instances() == []
    assert DummyInstrument.instances() == []
    assert Instrument._all_instruments == {}
示例#8
0
def test_instrument_warns_on_hyphen_in_name(close_before_and_after):
    # Check if warning is raised and name is valid
    # identifier when dashes '-' are converted to underscores '_'
    with pytest.warns(
        UserWarning, match="Changed -name to _name for instrument identifier"
    ):
        instr = DummyInstrument(name="-name")

    assert instr.name == "_name"
    assert Instrument.instances() == []
    assert DummyInstrument.instances() == [instr]
    assert Instrument._all_instruments != {}
示例#9
0
def test_instrument_channel_name_raise_on_invalid(close_before_and_after):
    with pytest.raises(ValueError, match="foo_☃ invalid instrument identifier"):
        DummyChannelInstrument(name="foo", channel_names=["☃"])
    assert Instrument.instances() == []
    assert DummyChannelInstrument.instances() == []
    assert Instrument._all_instruments == {}