Skip to content

Commit

Permalink
add missing tests for 6 cppcore functions (#354)
Browse files Browse the repository at this point in the history
* add tests for getFeatureInt & getFeatureDouble

* add tests for getMapIntData & getMapDoubleData

* add test_featuretypes

* make efel.reset flush gError

* add test_getgError
  • Loading branch information
anilbey authored Jan 11, 2024
1 parent cc9a2b7 commit 2bd34e6
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
2 changes: 2 additions & 0 deletions efel/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ def getDistance(
def _initialise():
"""Set cppcore initial values"""
cppcore.Initialize(_settings.dependencyfile_path, "log")
# flush the GErrorString from previous runs by calling getgError()
cppcore.getgError()

# First set some settings that are used by the feature extraction

Expand Down
59 changes: 59 additions & 0 deletions tests/test_cppcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,24 @@ def test_getFeatureNames(self): # pylint: disable=R0201
expected_featurenames += ["Spikecount", "Spikecount_stimint"]
assert set(feature_names) == set(expected_featurenames)

def test_getFeatureInt(self):
"""cppcore: Testing getFeatureInt"""
import efel
self.setup_data()
# get int feature
feature_values = list()
efel.cppcore.getFeatureInt('AP_begin_indices', feature_values)
assert isinstance(feature_values[0], int)

def test_getFeatureDouble(self):
"""cppcore: Testing getFeatureDouble."""
import efel
self.setup_data()
# get double feature
feature_values = list()
efel.cppcore.getFeatureDouble('AP_amplitude', feature_values)
assert isinstance(feature_values[0], float)

def test_getFeatureDouble_failure(self): # pylint: disable=R0201
"""cppcore: Testing failure exit code in getFeatureDouble"""
import efel
Expand Down Expand Up @@ -155,6 +173,47 @@ def test_getFeature_non_existant(self): # pylint: disable=R0201
import efel
efel.cppcore.getFeature("does_not_exist", list())

def test_getMapIntData(self):
"""cppcore: Testing getMapIntData."""
import efel
self.setup_data()
# with non-existent key
res = efel.cppcore.getMapIntData('AP_begin_indices')
assert res == []
feature_values = list()
efel.cppcore.getFeatureInt('AP_begin_indices', feature_values)
res = efel.cppcore.getMapIntData('AP_begin_indices')
assert res == [5655, 6057, 6527, 7161, 8266]

def test_getMapDoubleData(self):
"""cppcore: Testing getMapDoubleData."""
import efel
self.setup_data()
# with non-existent key
res = efel.cppcore.getMapDoubleData('AP_amplitude')
assert res == []
feature_values = list()
efel.cppcore.getFeatureDouble('AP_amplitude', feature_values)
res = efel.cppcore.getMapDoubleData('AP_amplitude')
assert res[0] == 80.45724099440199
assert len(res) == 5

def test_featuretype(self):
"""cppcore: Testing featuretype."""
import efel
assert efel.cppcore.featuretype('AP_amplitude') == 'double'
assert efel.cppcore.featuretype('AP_begin_indices') == 'int'

def test_getgError(self):
"""cppcore: Testing getgError."""
import efel
efel.reset()
assert efel.cppcore.getgError() == ''
feature_values = list()
efel.cppcore.getFeatureDouble('AP_amplitude', feature_values)
assert "Feature T not found" in efel.cppcore.getgError()
assert efel.cppcore.getgError() == ''

def test_logging(self): # pylint: disable=R0201
"""cppcore: Testing logging"""
import efel
Expand Down

0 comments on commit 2bd34e6

Please sign in to comment.