-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Ensure all features return built-in types
- Loading branch information
1 parent
acbba0f
commit 384cf12
Showing
4 changed files
with
129 additions
and
4 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
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,43 @@ | ||
"""Configuration for the pytest test suite.""" | ||
from pathlib import Path | ||
|
||
import pytest | ||
import neurom as nm | ||
|
||
|
||
@pytest.fixture | ||
def DATA_PATH(): | ||
return Path(__file__).parent / "data" | ||
|
||
|
||
@pytest.fixture | ||
def SWC_PATH(DATA_PATH): | ||
return DATA_PATH / "swc" | ||
|
||
|
||
@pytest.fixture | ||
def MORPHOLOGY(SWC_PATH): | ||
return nm.load_morphology(SWC_PATH / "test_morph.swc") | ||
|
||
|
||
@pytest.fixture | ||
def NEURITE(MORPHOLOGY): | ||
return MORPHOLOGY.neurites[0] | ||
|
||
|
||
@pytest.fixture | ||
def SECTION(NEURITE): | ||
return NEURITE.sections[0] | ||
|
||
|
||
@pytest.fixture | ||
def NRN_FILES(DATA_PATH): | ||
return [ | ||
DATA_PATH / "h5/v1" / f | ||
for f in ("Neuron.h5", "Neuron_2_branch.h5", "bio_neuron-001.h5") | ||
] | ||
|
||
|
||
@pytest.fixture | ||
def POP(NRN_FILES): | ||
return nm.load_morphologies(NRN_FILES) |
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,59 @@ | ||
from itertools import chain | ||
|
||
import numpy as np | ||
import pytest | ||
from numpy import testing as npt | ||
|
||
from neurom import features | ||
|
||
|
||
def _check_nested_type(data): | ||
"""Check that the given data contains only built-in types. | ||
The data should either be an int or float, or a list or tuple of ints or floats. | ||
""" | ||
if isinstance(data, (list, tuple)): | ||
for i in data: | ||
_check_nested_type(i) | ||
else: | ||
assert isinstance(data, (int, float)) | ||
|
||
|
||
class TestFeatureTypes: | ||
"""Test that all features return raw Python types.""" | ||
|
||
@pytest.mark.parametrize( | ||
"feature_name", | ||
[ | ||
pytest.param(name, id=f"Test type of {name} neurite feature") | ||
for name in features._NEURITE_FEATURES | ||
] | ||
) | ||
def test_neurite_feature_types(self, feature_name, NEURITE): | ||
"""Test neurite features.""" | ||
res = features._NEURITE_FEATURES.get(feature_name)(NEURITE) | ||
_check_nested_type(res) | ||
|
||
@pytest.mark.parametrize( | ||
"feature_name", | ||
[ | ||
pytest.param(name, id=f"Test type of {name} morphology feature") | ||
for name in features._MORPHOLOGY_FEATURES | ||
] | ||
) | ||
def test_morphology_feature_types(self, feature_name, MORPHOLOGY): | ||
"""Test morphology features.""" | ||
res = features._MORPHOLOGY_FEATURES.get(feature_name)(MORPHOLOGY) | ||
_check_nested_type(res) | ||
|
||
@pytest.mark.parametrize( | ||
"feature_name", | ||
[ | ||
pytest.param(name, id=f"Test type of {name} population feature") | ||
for name in features._POPULATION_FEATURES | ||
] | ||
) | ||
def test_population_feature_types(self, feature_name, POP): | ||
"""Test population features.""" | ||
res = features._POPULATION_FEATURES.get(feature_name)(POP) | ||
_check_nested_type(res) |
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