Skip to content

Commit

Permalink
fix mock tests (#1587)
Browse files Browse the repository at this point in the history
* fix mock tests

* Fix flake8

* Update test_mock.py

Co-authored-by: Ryan Ly <[email protected]>
Co-authored-by: Oliver Ruebel <[email protected]>
  • Loading branch information
3 people authored Nov 10, 2022
1 parent ceffef3 commit a4f24bc
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 27 deletions.
13 changes: 13 additions & 0 deletions src/pynwb/testing/mock/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@


def name_generator(name):
"""
Returns unique names of neurodata types using an incrementing number. The first time you pass "TimeSeries" it
returns "TimeSeries". The second time, it returns "TimeSeries2", the third time it returns "TimeSeries3", etc.
Parameters
----------
name: str
name of neurodata_type, e.g. TimeSeries
Returns
-------
name of neurodata_object: str
"""
if name not in name_generator_registry:
name_generator_registry[name] = 1
return name
Expand Down
70 changes: 43 additions & 27 deletions tests/unit/test_mock.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
from pynwb.testing.mock.file import mock_Subject, mock_NWBFile

from pynwb.testing.mock.base import mock_TimeSeries

from pynwb.testing.mock.ophys import (
mock_ImagingPlane,
mock_TwoPhotonSeries,
mock_RoiResponseSeries,
mock_PlaneSegmentation,
mock_OpticalChannel,
mock_Fluorescence,
mock_DfOverF,
mock_ImageSegmentation,
)

from pynwb.testing.mock.ogen import (
Expand All @@ -29,33 +34,44 @@
mock_SpikeEventSeries,
)

from pynwb.testing import TestCase
import pytest

from pynwb.testing.mock.utils import name_generator, name_generator_registry


@pytest.mark.parametrize(
"mock_function", [
mock_ImagingPlane,
mock_TwoPhotonSeries,
mock_RoiResponseSeries,
mock_PlaneSegmentation,
mock_OpticalChannel,
mock_Fluorescence,
mock_DfOverF,
mock_ImageSegmentation,
mock_OptogeneticStimulusSite,
mock_OptogeneticSeries,
mock_Device,
mock_Position,
mock_PupilTracking,
mock_CompassDirection,
mock_SpatialSeries,
mock_ElectrodeGroup,
mock_ElectrodeTable,
mock_ElectricalSeries,
mock_SpikeEventSeries,
mock_Subject,
mock_NWBFile,
mock_TimeSeries,
],
)
def test_mock(mock_function):
mock_function()


def test_name_generator():

name_generator_registry.clear() # reset registry

class TestMock(TestCase):

@pytest.mark.parametrize(
"mock_function", [
mock_ImagingPlane,
mock_TwoPhotonSeries,
mock_RoiResponseSeries,
mock_PlaneSegmentation,
mock_OpticalChannel,
mock_OptogeneticStimulusSite,
mock_OptogeneticSeries,
mock_Device,
mock_Position,
mock_PupilTracking,
mock_CompassDirection,
mock_SpatialSeries,
mock_ElectrodeGroup,
mock_ElectrodeTable,
mock_ElectricalSeries,
mock_SpikeEventSeries,
mock_Subject,
mock_NWBFile,
],
)
def test_mock(mock_function):
mock_function()
assert name_generator("TimeSeries") == "TimeSeries"
assert name_generator("TimeSeries") == "TimeSeries2"

0 comments on commit a4f24bc

Please sign in to comment.