-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- use pytest functions which can use fixtures - use fixtures to reduce network roundtrips - use parametrized fixture to control igraph usage - also splits igraph tests into 2
- Loading branch information
Showing
3 changed files
with
145 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import os | ||
import pytest | ||
import navis | ||
from contextlib import contextmanager | ||
import logging | ||
import pymaid | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@contextmanager | ||
def igraph_context(use_igraph): | ||
orig = navis.config.use_igraph | ||
logger.debug(f"Setting navis.config.use_igraph = {use_igraph}") | ||
navis.config.use_igraph = use_igraph | ||
yield use_igraph | ||
logger.debug(f"Resetting navis.config.use_igraph = {orig}") | ||
navis.config.use_igraph = orig | ||
|
||
|
||
@pytest.fixture(scope="session", params=[True, False]) | ||
def use_igraph(request): | ||
with igraph_context(request.param) as use: | ||
yield use | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def client(): | ||
return pymaid.CatmaidInstance( | ||
os.environ.get("PYMAID_TEST_SERVER_URL", 'https://fafb.catmaid.virtualflybrain.org/'), | ||
os.environ.get("PYMAID_TEST_TOKEN"), | ||
os.environ.get("PYMAID_TEST_HTTP_USER"), | ||
os.environ.get("PYMAID_TEST_HTTP_PW"), | ||
make_global=True, | ||
) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def skids(): | ||
return [ | ||
int(s) for s in os.environ.get( | ||
"PYMAID_TEST_SKIDS", | ||
"16,1299740,4744251" | ||
).split(",") | ||
] | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def annotation_names(): | ||
return os.environ.get( | ||
"PYMAID_TEST_ANNOTATIONS", | ||
'Paper: Dolan and Belliart-Guérin et al. 2018,Paper: Wang et al 2020a' | ||
).split(",") | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def volume_name(): | ||
return os.environ.get("PYMAID_TEST_VOLUME", "LH_R") | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def stack_id(): | ||
return int(os.environ.get("PYMAID_TEST_STACK_ID", 1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import pytest | ||
import pymaid | ||
import navis as ns | ||
import numpy as np | ||
|
||
SEED = 1991 | ||
|
||
@pytest.fixture(scope="module") | ||
def neuron_list(client, skids): | ||
return pymaid.get_neuron(skids[0:2], remote_instance=client) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def neuron(neuron_list): | ||
n = neuron_list[0] | ||
return n.reroot(n.soma, inplace=False) | ||
|
||
@pytest.fixture(scope="module") | ||
def leaf_slab(neuron): | ||
rng = np.random.default_rng(SEED) | ||
leaf_id = neuron.nodes[neuron.nodes.type == 'end'].sample( | ||
1, random_state=rng).iloc[0].node_id | ||
slab_id = neuron.nodes[neuron.nodes.type == 'slab'].sample( | ||
1, random_state=rng).iloc[0].node_id | ||
return (leaf_id, slab_id) | ||
|
||
|
||
def test_reroot(neuron_list, neuron, leaf_slab, use_igraph): | ||
leaf_id, slab_id = leaf_slab | ||
assert neuron.reroot(leaf_id, inplace=False) is not None | ||
assert neuron_list.reroot(neuron_list.soma, inplace=False) is not None | ||
|
||
|
||
def test_distal_to(neuron, leaf_slab, use_igraph): | ||
leaf_id, slab_id = leaf_slab | ||
assert ns.distal_to(neuron, leaf_id, neuron.root) | ||
assert not ns.distal_to(neuron, neuron.root, leaf_id) | ||
|
||
|
||
def test_distance(neuron, use_igraph): | ||
leaf_id = neuron.nodes[neuron.nodes.type == 'end'].iloc[0].node_id | ||
|
||
assert ns.dist_between(neuron, leaf_id, neuron.root) is not None | ||
assert ns.dist_between(neuron, neuron.root, leaf_id) is not None | ||
|
||
|
||
def test_find_bp(neuron, use_igraph): | ||
assert ns.find_main_branchpoint(neuron, reroot_soma=False) is not None | ||
|
||
|
||
def test_split_fragments(neuron, use_igraph): | ||
assert ns.split_into_fragments(neuron, n=2, reroot_soma=False) is not None | ||
|
||
|
||
def test_longest_neurite(neuron, use_igraph): | ||
assert ns.longest_neurite(neuron, n=2, reroot_soma=False) is not None | ||
|
||
|
||
def test_cut_neuron(neuron, leaf_slab, use_igraph): | ||
leaf_id, slab_id = leaf_slab | ||
dist, prox = ns.cut_skeleton(neuron, slab_id) | ||
assert dist.nodes.shape != prox.nodes.shape | ||
|
||
# Make sure dist and prox check out | ||
assert ns.distal_to(neuron, dist.root, prox.root) | ||
|
||
|
||
def test_subset(neuron, use_igraph): | ||
assert isinstance( | ||
ns.subset_neuron(neuron, neuron.segments[0]), | ||
pymaid.CatmaidNeuron | ||
) | ||
|
||
|
||
def test_node_sorting(neuron, use_igraph): | ||
result = ns.graph.node_label_sorting(neuron) | ||
assert isinstance(result, np.ndarray) | ||
|
||
|
||
def test_geodesic_matrix(neuron, use_igraph): | ||
geo = ns.geodesic_matrix(neuron) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters