Esempio n. 1
0
def test_load_devices_from_happi_1(tmp_path, monkeypatch, device_names,
                                   loaded_names, kw_args, success, errmsg):
    """
    Tests for ``load_devices_from_happi``.
    """
    _configure_happi(tmp_path, monkeypatch, json_devices=_happi_json_db_1)

    # Load as a dictionary
    if success:
        ns = {}
        dlist = load_devices_from_happi(device_names, namespace=ns, **kw_args)
        assert len(ns) == len(loaded_names), str(ns)
        for d in loaded_names:
            assert d in ns
        assert set(dlist) == set(loaded_names)
    else:
        with pytest.raises(Exception, match=errmsg):
            ns = {}
            load_devices_from_happi(device_names, namespace=ns, **kw_args)

    # Load in local namespace
    def _test_loading(device_names, loaded_names):
        if success:
            load_devices_from_happi(device_names,
                                    namespace=locals(),
                                    **kw_args)
            for d in loaded_names:
                assert d in locals()
        else:
            with pytest.raises(Exception, match=errmsg):
                load_devices_from_happi(device_names,
                                        namespace=locals(),
                                        **kw_args)

    _test_loading(device_names=device_names, loaded_names=loaded_names)
Esempio n. 2
0
 def _test_loading(device_names, loaded_names):
     if success:
         load_devices_from_happi(device_names,
                                 namespace=locals(),
                                 **kw_args)
         for d in loaded_names:
             assert d in locals()
     else:
         with pytest.raises(Exception, match=errmsg):
             load_devices_from_happi(device_names,
                                     namespace=locals(),
                                     **kw_args)
Esempio n. 3
0
def test_load_devices_from_happi_2_fail(tmp_path, monkeypatch):
    """
    Function ``load_devices_from_happi``: parameter ``namespace`` is required and must be of type ``dict``.
    """
    _configure_happi(tmp_path, monkeypatch, json_devices=_happi_json_db_1)

    # Missing 'namespace' parameter
    with pytest.raises(
            TypeError,
            match="missing 1 required keyword-only argument: 'namespace'"):
        load_devices_from_happi(["det", "motor"])

    # Incorrect type of 'namespace' parameter
    with pytest.raises(TypeError,
                       match="Parameter 'namespace' must be a dictionary"):
        load_devices_from_happi(["det", "motor"], namespace=[1, 2, 3])