Skip to content

Commit

Permalink
Add integration test for NeuronConnector
Browse files Browse the repository at this point in the history
  • Loading branch information
clbarnes committed Oct 23, 2023
1 parent 2c32c29 commit 1100f3b
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from pathlib import Path
import os
from typing import List
Expand All @@ -15,6 +16,11 @@ def data_dir():
return Path(__file__).resolve().parent.parent / "navis" / "data"


@pytest.fixture(scope="session")
def fixture_dir():
return Path(__file__).resolve().parent / "fixtures"


@pytest.fixture(
params=["Path", "pathstr", "swcstr", "textbuffer", "rawbuffer", "DataFrame"]
)
Expand Down Expand Up @@ -115,3 +121,26 @@ def treeneuron_dfs(swc_paths, synapses_paths):
neuron.connectors = pd.read_csv(syn_path)
out.append(neuron)
return out


@pytest.fixture
def neuron_connections(fixture_dir: Path):
expected_jso = json.loads(
fixture_dir.joinpath("network_connector", "expected.json").read_text()
)
expected = {
int(pre): {
int(post): n for post, n in d.items()
} for pre, d in expected_jso.items()
}

nl = navis.read_json(
str(fixture_dir.joinpath("network_connector", "network.json"))
)
nrns = []
for nrn in nl:
nrn.name = f"skeleton {nrn.id}"
nrn.id = int(nrn.id)
nrns.append(nrn)

return nrns, expected
50 changes: 50 additions & 0 deletions tests/fixtures/neuron_connector/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"2582391": {
"2582391": 0,
"6557581": 10,
"8198416": 12,
"8198513": 14,
"8252067": 41,
"11051276": 55
},
"6557581": {
"2582391": 9,
"6557581": 0,
"8198416": 8,
"8198513": 9,
"8252067": 1,
"11051276": 9
},
"8198416": {
"2582391": 8,
"6557581": 8,
"8198416": 0,
"8198513": 14,
"8252067": 9,
"11051276": 10
},
"8198513": {
"2582391": 7,
"6557581": 13,
"8198416": 16,
"8198513": 0,
"8252067": 9,
"11051276": 5
},
"8252067": {
"2582391": 0,
"6557581": 3,
"8198416": 0,
"8198513": 1,
"8252067": 0,
"11051276": 1
},
"11051276": {
"2582391": 0,
"6557581": 2,
"8198416": 1,
"8198513": 1,
"8252067": 0,
"11051276": 0
}
}
1 change: 1 addition & 0 deletions tests/fixtures/neuron_connector/network.json

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions tests/test_connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import navis
from navis.connectivity import NeuronConnector
from navis import NeuronList


def test_neuron_connector():
Expand Down Expand Up @@ -121,3 +122,17 @@ def test_neuron_connector_synthetic(simple_network):
assert mdg.number_of_nodes() == dg.number_of_nodes()
assert mdg.number_of_edges() == 4
assert sorted(mdg.edges()) == expected_edges


def test_neuron_connector_real(
neuron_connections: Tuple[NeuronList, dict[int, dict[int, int]]]
):
nl, exp = neuron_connections
nc = NeuronConnector(nl)
dg = nc.to_digraph(include_other=False)
for pre_n, post_n, edata in dg.edges(data=True):
pre_skid = dg.nodes[pre_n]["neuron"].id
post_skid = dg.nodes[post_n]["neuron"].id
n = edata["weight"]

assert exp[pre_skid][post_skid] == n

0 comments on commit 1100f3b

Please sign in to comment.