def test_bad_manifest(): # not abs path in with copy_config() as config_path: with edit_config(config_path) as config: config["manifest"]["$BASE_DIR"] = "not_absolute" with pytest.raises(BluepySnapError): test_module.Config.parse(config_path) with copy_config() as config_path: with edit_config(config_path) as config: config["manifest"]["$COMPONENT_DIR"] = "$BASE_DIR/$NETWORK_DIR" with pytest.raises(BluepySnapError): test_module.Config.parse(config_path) with copy_config() as config_path: with edit_config(config_path) as config: config["components"]["other"] = "$COMPONENT_DIR/$BASE_DIR" with pytest.raises(BluepySnapError): test_module.Config.parse(config_path) with copy_config() as config_path: with edit_config(config_path) as config: config["components"]["other"] = "something/$COMPONENT_DIR/" with pytest.raises(BluepySnapError): test_module.Config.parse(config_path) with copy_config() as config_path: with edit_config(config_path) as config: config["components"]["other"] = "/something/$COMPONENT_DIR/" with pytest.raises(BluepySnapError): test_module.Config.parse(config_path)
def test_invalid_config_edges_file(): with copy_circuit() as (_, config_copy_path): with edit_config(config_copy_path) as config: del config['networks']['edges'][0]['edges_file'] errors = test_module.validate(str(config_copy_path)) assert errors == {Error(Error.FATAL, 'Invalid "edges_file": None')} with edit_config(config_copy_path) as config: config['networks']['edges'][0]['edges_file'] = '/' errors = test_module.validate(str(config_copy_path)) assert errors == {Error(Error.FATAL, 'Invalid "edges_file": /')}
def test_invalid_config_nodes_file(): with copy_circuit() as (_, config_copy_path): with edit_config(config_copy_path) as config: del config["networks"]["nodes"][0]["nodes_file"] errors = test_module.validate(str(config_copy_path)) assert errors == {Error(Error.FATAL, 'Invalid "nodes_file": None')} with edit_config(config_copy_path) as config: config["networks"]["nodes"][0]["nodes_file"] = "/" errors = test_module.validate(str(config_copy_path)) assert errors == {Error(Error.FATAL, 'Invalid "nodes_file": /')}
def test_no_config_edges_population(): with copy_circuit() as (_, config_copy_path): expected = {Error(Error.FATAL, 'No "populations" defined in config "edges"')} with edit_config(config_copy_path) as config: del config["networks"]["edges"][0]["populations"]["default"] errors = test_module.validate(str(config_copy_path), bbp_check=True) assert errors == expected with edit_config(config_copy_path) as config: del config["networks"]["edges"][0]["populations"] errors = test_module.validate(str(config_copy_path), bbp_check=True) assert errors == expected
def test_get_filepath_point(): with copy_config() as config_copy_path: with edit_config(config_copy_path) as config: config["components"][ "point_neuron_models_dir"] = "$COMPONENT_DIR/point_neuron_models" circuit = Circuit(config_copy_path) nodes = create_node_population(str(TEST_DATA_DIR / "nodes_points.h5"), "default", circuit) test_obj = test_module.NeuronModelsHelper(circuit.config["components"], nodes) node_id = 0 assert nodes.get(node_id, properties=Node.MODEL_TEMPLATE) == "nml:empty_bio" actual = test_obj.get_filepath(node_id) expected = Path( circuit.config["components"]["point_neuron_models_dir"], "empty_bio.nml") assert actual == expected node_id = 1 assert nodes.get( node_id, properties=Node.MODEL_TEMPLATE) == "nml:/abs/path/empty_bio" actual = test_obj.get_filepath(node_id) expected = Path("/abs/path/empty_bio.nml") assert actual == expected
def test_invalid_edge_population_type(): with copy_circuit() as (_, config_copy_path): fake_type = "fake_type" with edit_config(config_copy_path) as config: config["networks"]["edges"][0]["populations"]["default"]["type"] = fake_type errors = test_module.validate(str(config_copy_path), bbp_check=True) assert errors == {Error(Error.WARNING, "Invalid edge type: {}".format(fake_type))}
def test_no_config_edges(): with copy_circuit() as (_, config_copy_path): with edit_config(config_copy_path) as config: del config['networks']['edges'] errors = test_module.validate(str(config_copy_path)) assert errors == { Error(Error.FATAL, 'No "edges" in config "networks"') }
def test_ok_circuit(): errors = test_module.validate(str(TEST_DATA_DIR / 'circuit_config.json')) assert errors == set() with copy_circuit() as (_, config_copy_path): with edit_config(config_copy_path) as config: config['networks']['nodes'][0]['node_types_file'] = None errors = test_module.validate(str(config_copy_path)) assert errors == set()
def test_no_bio_component_dirs(): dirs = ['morphologies_dir', 'biophysical_neuron_models_dir'] for dir_ in dirs: with copy_circuit() as (_, config_copy_path): with edit_config(config_copy_path) as config: del config['components'][dir_] errors = test_module.validate(str(config_copy_path), True) # multiplication by 2 because we have 2 populations, each produces the same error. assert errors == {BbpError(Error.FATAL, 'Invalid components "{}": {}'.format(dir_, None))}
def test_invalid_bio_alternate_morphology_dir(): with copy_circuit() as (circuit_copy_path, config_copy_path): component = "neurolucida-asc" fake_path = str(circuit_copy_path / "fake/path") with edit_config(config_copy_path) as config: config["networks"]["nodes"][0]["populations"]["default"]["alternate_morphologies"] = { component: fake_path } errors = test_module.validate(str(config_copy_path), True) assert errors == { BbpError(Error.FATAL, 'Invalid components "{}": {}'.format(component, fake_path)) }
def test_edges_population_not_found_in_h5(): with copy_circuit() as (circuit_copy_path, config_copy_path): edges_file = circuit_copy_path / "edges.h5" with edit_config(config_copy_path) as config: config["networks"]["edges"][0]["populations"]["fake_population"] = {} errors = test_module.validate(str(config_copy_path), bbp_check=True) assert errors == { Error( Error.FATAL, "populations not found in {}:\n{}".format(edges_file, "\tfake_population\n"), ) }
def test_bad_manifest(): # 2 anchors would result in the absolute path of the last one : misleading with copy_config() as config_path: with edit_config(config_path) as config: config["manifest"]["$COMPONENT_DIR"] = "$BASE_DIR/$NETWORK_DIR" with pytest.raises(BluepySnapError): test_module.Config.parse(config_path) # same but not in the manifest with copy_config() as config_path: with edit_config(config_path) as config: config["components"]["other"] = "$COMPONENT_DIR/$BASE_DIR" with pytest.raises(BluepySnapError): test_module.Config.parse(config_path) # relative path with an anchor in the middle is not allowed this breaks the purpose of the # anchors (they are not just generic placeholders) with copy_config() as config_path: with edit_config(config_path) as config: config["components"]["other"] = "something/$COMPONENT_DIR/" with pytest.raises(BluepySnapError): test_module.Config.parse(config_path) # abs path with an anchor in the middle is not allowed with copy_config() as config_path: with edit_config(config_path) as config: config["components"]["other"] = "/something/$COMPONENT_DIR/" with pytest.raises(BluepySnapError): test_module.Config.parse(config_path) # unknown anchor with copy_config() as config_path: with edit_config(config_path) as config: config["components"]["other"] = "$UNKNOWN/something/" with pytest.raises(KeyError): test_module.Config.parse(config_path)
def test_biophysical_in_library(self): with copy_circuit() as (circuit_copy_path, config_copy_path): with edit_config(config_copy_path) as config: config["networks"]["nodes"][0]["nodes_file"] = "$NETWORK_DIR/nodes_quaternions.h5" nodes_file = circuit_copy_path / 'nodes_quaternions.h5' with h5py.File(nodes_file, 'r+') as h5f: data = h5f['nodes/default/0/model_type'][:] del h5f['nodes/default/0/model_type'] h5f.create_dataset('nodes/default/0/model_type', data=np.zeros_like(data, dtype=int)) h5f.create_dataset('nodes/default/0/@library/model_type', data=np.array(["biophysical", ], dtype=h5py.string_dtype())) circuit = Circuit(str(config_copy_path)) assert isinstance(circuit.nodes['default'].morph, test_module.MorphHelper)
def test_no_alternate_morph_files(): with copy_circuit() as (circuit_copy_path, config_copy_path): nodes_file = str(circuit_copy_path / "nodes.h5") with edit_config(config_copy_path) as config: config["networks"]["nodes"][0]["populations"]["default"]["alternate_morphologies"] = { "neurolucida-asc": config["components"]["morphologies_dir"] } errors = test_module.validate(str(config_copy_path), bbp_check=True) assert errors == { Error( Error.WARNING, "missing 1 files in group morphology: default/0[{}]:\n\tmorph-A.asc\n".format( nodes_file ), ) }
def test_not_biophysical_population(self): with copy_circuit() as (circuit_copy_path, config_copy_path): with edit_config(config_copy_path) as config: config["networks"]["nodes"][0]["nodes_file"] = "$NETWORK_DIR/nodes_quaternions.h5" nodes_file = circuit_copy_path / 'nodes_quaternions.h5' with h5py.File(nodes_file, 'r+') as h5f: data = h5f['nodes/default/0/model_type'][:] del h5f['nodes/default/0/model_type'] h5f.create_dataset('nodes/default/0/model_type', data=np.zeros_like(data, dtype=int)) h5f.create_dataset('nodes/default/0/@library/model_type', data=np.array(["virtual", ], dtype=h5py.string_dtype())) with pytest.raises(BluepySnapError): circuit = Circuit(str(config_copy_path)) circuit.nodes['default'].morph
def test_parse(): actual = test_module.Config.parse( str(TEST_DATA_DIR / 'circuit_config.json')) # check double resolution and '.' works: $COMPONENT_DIR -> $BASE_DIR -> '.' assert actual['components']['morphologies_dir'] == str(TEST_DATA_DIR / 'morphologies') # check resolution and './' works: $NETWORK_DIR -> './' assert actual['networks']['nodes'][0]['nodes_file'] == str(TEST_DATA_DIR / 'nodes.h5') # check resolution of '../' works: $PARENT --> '../' with copy_config() as config_path: with edit_config(config_path) as config: config["manifest"]["$PARENT"] = "../" config["components"]["other"] = "$PARENT/other" actual = test_module.Config.parse(config_path) assert (actual['components']['other'] == str( Path(config_path.parent / "../other").resolve())) # check resolution of '../' works in a path outside manifest with copy_config() as config_path: with edit_config(config_path) as config: config["components"]["other"] = "../other" actual = test_module.Config.parse(config_path) assert (actual['components']['other'] == str( Path(config_path.parent / "../other").resolve())) # check resolution without manifest of '../' works in a path outside # i.e. : self.manifest contains the configdir even if manifest is not here with copy_config() as config_path: with edit_config(config_path) as config: for k in list(config): config.pop(k) config["something"] = "../other" actual = test_module.Config.parse(config_path) assert actual["something"] == str( Path(config_path.parent / "../other").resolve()) # check resolution with multiple slashes with copy_config() as config_path: with edit_config(config_path) as config: config["something"] = "$COMPONENT_DIR/something////else" actual = test_module.Config.parse(config_path) assert actual["something"] == str( Path(config_path.parent) / 'something' / 'else') # check resolution with $ in a middle of the words with copy_config() as config_path: with edit_config(config_path) as config: config["something"] = "$COMPONENT_DIR/somet$hing/else" actual = test_module.Config.parse(config_path) assert actual["something"] == str( Path(config_path.parent) / 'somet$hing' / 'else') # check resolution with relative path without "." in the manifest with copy_config() as config_path: with edit_config(config_path) as config: config["manifest"]["$NOPOINT"] = "nopoint" config["components"]["other"] = "$NOPOINT/other" actual = test_module.Config.parse(config_path) assert actual["components"]["other"] == str( Path(config_path.parent) / 'nopoint' / 'other') # check resolution for non path objects with copy_config() as config_path: with edit_config(config_path) as config: for k in list(config): config.pop(k) config["string"] = "string" config["int"] = 1 config["double"] = 0.2 # just to check because we use starting with '.' as a special case config["tricky_double"] = .2 config["path"] = "./path" actual = test_module.Config.parse(config_path) # string assert actual["string"] == "string" # int assert actual["int"] == 1 # double assert actual["double"] == 0.2 assert actual["tricky_double"] == 0.2 # path assert actual["path"] == str( Path(config_path.parent / "./path").resolve())
def test_ok_edge_population_type(): with copy_circuit() as (_, config_copy_path): with edit_config(config_copy_path) as config: config["networks"]["edges"][0]["populations"]["default"]["type"] = "chemical" errors = test_module.validate(str(config_copy_path), bbp_check=True) assert errors == set()
def test_invalid_config_nodes_type_file(): with copy_circuit() as (_, config_copy_path): with edit_config(config_copy_path) as config: config['networks']['nodes'][0]['node_types_file'] = '/' errors = test_module.validate(str(config_copy_path)) assert errors == {Error(Error.FATAL, 'Invalid "node_types_file": /')}
def test_no_config_components(): with copy_circuit() as (_, config_copy_path): with edit_config(config_copy_path) as config: del config['components'] errors = test_module.validate(str(config_copy_path)) assert errors == {Error(Error.FATAL, 'No "components" in config')}