Beispiel #1
0
def test_load_hierarchy(mocker, gen_configs):
    """Ensure we load configs from the correct locations"""

    # Set project dir to differentiate from system dir (root package dir)
    tmp_dir = os.path.join(os.getcwd(), "tmp")
    mocker.patch.dict(
        paths.fpga_config, {"project": os.path.join(tmp_dir, "fpga_config")}
    )

    # Create a list to use in the test with this tmp project dir
    my_config_files = [
        paths.fpga_config["nengo"],
        paths.fpga_config["system"],
        paths.fpga_config["user"],
        paths.fpga_config["project"],
    ]

    # Create some dummy configs
    sec = "config"
    entry = "file"
    for k, v in paths.fpga_config.items():
        gen_configs.create_config(v, contents={sec: {entry: k}})

    # Explicitly define keys in reverse hierarchical order
    keys = ["project", "user", "system", "nengo"]

    # Load configs, then remove the highest priority file and reload
    for k in keys:
        fpga_config.reload_config(my_config_files)
        assert fpga_config.item_dict(sec)[entry] == k
        os.remove(paths.fpga_config[k])
Beispiel #2
0
def test_item_dict(gen_configs):
    """Test the item dict function of the config parser"""

    # Create a dummy config and load it
    fname = os.path.join(os.getcwd(), "test_config")
    gen_configs.create_config(fname)
    fpga_config.reload_config(fname)

    section = list(gen_configs.default_contents.keys())[0]
    config_dict = fpga_config.item_dict(section)

    assert config_dict == gen_configs.default_contents[section]
Beispiel #3
0
def dummy_net(config_contents, gen_configs):  # noqa: W0521
    """Setup an FPGA network

    `config_contents` was kept separate so we can update the config file
    """

    # Create a dummy config for testing
    fname = os.path.join(os.getcwd(), "test-config")
    fpga_name = list(config_contents.keys())[1]

    gen_configs.create_config(fname, contents=config_contents)
    fpga_config.reload_config(fname)

    return FpgaPesEnsembleNetwork(fpga_name, 1, 1, 0.001)
Beispiel #4
0
def test_clear(gen_configs):
    """Test the clear function of the config parser"""

    # Create a dummy config and load it
    fname = os.path.join(os.getcwd(), "test_config")
    gen_configs.create_config(fname)
    fpga_config.reload_config(fname)

    # Confirm we loaded our dummy config
    assert len(fpga_config.sections()) == len(gen_configs.default_contents)

    # Clear and confirm
    fpga_config._clear()
    assert len(fpga_config.sections()) == 0
Beispiel #5
0
def test_connect_ssh_client(ssh_method, config_contents, gen_configs, mocker):
    """Test the IDExtractor's connect_ssh_client function

    Almost identical to test in "test_networks"
    """

    # Create a dummy config for testing
    fname = os.path.join(os.getcwd(), "test-config")
    fpga_name = list(config_contents.keys())[1]

    # Add ssh_connection method to dummy config dict
    if ssh_method is not None:
        config_contents[fpga_name][ssh_method[0]] = ssh_method[1]

    gen_configs.create_config(fname, contents=config_contents)
    fpga_config.reload_config(fname)

    # Don't actually connect the socket in init
    mocker.patch("socket.socket.bind")
    mocker.patch("socket.socket.listen")

    # Create driver
    extractor = IDExtractor(fpga_name)

    # Don't actually connect the ssh client
    connect_mock = mocker.patch.object(extractor.ssh_client, "connect")

    ssh_user = config_contents[fpga_name]["ssh_user"]
    remote_ip = config_contents[fpga_name]["ip"]
    ssh_port = config_contents[fpga_name]["ssh_port"]
    extractor.connect_ssh_client(ssh_user, remote_ip)

    # Create the expected call based on the config
    if ssh_method is None:
        connect_mock.assert_called_once_with(remote_ip,
                                             port=ssh_port,
                                             username=ssh_user)
    elif ssh_method[0] == "ssh_pwd":
        connect_mock.assert_called_once_with(remote_ip,
                                             port=ssh_port,
                                             username=ssh_user,
                                             password=ssh_method[1])
    elif ssh_method[0] == "ssh_key":
        connect_mock.assert_called_once_with(remote_ip,
                                             port=ssh_port,
                                             username=ssh_user,
                                             key_filename=ssh_method[1])
Beispiel #6
0
def dummy_extractor(config_contents, gen_configs, mocker):  # noqa: W0521
    """Setup an ID extractor

    `config_contents` was kept separate so we can update the config file
    """

    # Create a dummy config for testing
    fname = os.path.join(os.getcwd(), "test-config")
    fpga_name = list(config_contents.keys())[1]

    gen_configs.create_config(fname, contents=config_contents)
    fpga_config.reload_config(fname)

    # Don't actually connect the socket in init
    mocker.patch("socket.socket.bind")
    mocker.patch("socket.socket.listen")

    return IDExtractor(fpga_name)