Esempio n. 1
0
def test_subscription_from_config_wrong_name(dataset):
    """
    This test checks that an exception is thrown if a wrong name for a
    subscriber is passed
    """
    # This string represents the config file in the home directory:
    config = """
    {
        "subscription":{
            "subscribers":{
                "test_subscriber_wrong":{
                    "factory": "qcodes.tests.dataset.test_subscribing.MockSubscriber",
                    "factory_kwargs":{
                        "lg": false
                    },
                    "subscription_kwargs":{
                        "min_wait": 0,
                        "min_count": 1,
                        "callback_kwargs": {}
                    }
                }
            }
        }
    }
    """
    db_location = qcodes.config.core.db_location
    with default_config(user_config=config):
        qcodes.config.core.db_location = db_location

        assert 'test_subscriber' not in qcodes.config.subscription.subscribers
        with pytest.raises(RuntimeError):
            sub_id_c = dataset.subscribe_from_config('test_subscriber')
Esempio n. 2
0
def test_defaults(dataset_with_outliers):
    run_id = dataset_with_outliers.run_id

    # plot_by_id loads from the database location provided in the qcodes
    # config. But the tests are supposed to run with the standard config.
    # Therefore we need to backup the db location and add it to the default
    # config context.
    db_location = qcodes.config.core.db_location
    with default_config():
        qcodes.config.core.db_location = db_location
        _, cb = plot_by_id(run_id)
        assert cb[0].extend == 'neither'

        qcodes.config.plotting.auto_color_scale.enabled = True

        _, cb = plot_by_id(run_id)
        assert cb[0].extend == 'both'
    plt.close()
Esempio n. 3
0
def use_default_config():
    with default_config():
        yield
Esempio n. 4
0
def test_subscription_from_config(dataset, basic_subscriber):
    """
    This test is similar to `test_basic_subscription`, with the only
    difference that another subscriber from a config file is added.
    """
    # This string represents the config file in the home directory:
    config = """
    {
        "subscription":{
            "subscribers":{
                "test_subscriber":{
                    "factory": "qcodes.tests.dataset.test_subscribing.MockSubscriber",
                    "factory_kwargs":{
                        "lg": false
                    },
                    "subscription_kwargs":{
                        "min_wait": 0,
                        "min_count": 1,
                        "callback_kwargs": {}
                    }
                }
            }
        }
    }
    """
    # This little dance around the db_location is due to the fact that the
    # dataset fixture creates a dataset in a db in a temporary directory.
    # Therefore we need to 'backup' the path to the db when using the
    # default configuration.
    db_location = qcodes.config.core.db_location
    with default_config(user_config=config):
        qcodes.config.core.db_location = db_location

        assert 'test_subscriber' in qcodes.config.subscription.subscribers

        xparam = ParamSpecBase(name='x',
                           paramtype='numeric',
                           label='x parameter',
                           unit='V')
        yparam = ParamSpecBase(name='y',
                              paramtype='numeric',
                              label='y parameter',
                              unit='Hz')
        idps = InterDependencies_(dependencies={yparam: (xparam,)})
        dataset.set_interdependencies(idps)

        dataset.mark_started()

        sub_id = dataset.subscribe(basic_subscriber, min_wait=0, min_count=1,
                                   state={})
        sub_id_c = dataset.subscribe_from_config('test_subscriber')
        assert len(dataset.subscribers) == 2
        assert list(dataset.subscribers.keys()) == [sub_id, sub_id_c]

        expected_state = {}

        # Here we are only testing 2 to reduce the CI time
        for x in range(2):
            y = -x**2
            dataset.add_result({'x': x, 'y': y})
            expected_state[x+1] = [(x, y)]

            @retry_until_does_not_throw(
                exception_class_to_expect=AssertionError, delay=0, tries=10)
            def assert_expected_state():
                assert dataset.subscribers[sub_id].state == expected_state
                assert dataset.subscribers[sub_id_c].state == expected_state

            assert_expected_state()