Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some tests that fail when running locally #1361

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion neo/test/coretest/test_analogsignal.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def test__repr(self):
def test__pretty(self):
for i, signal in enumerate(self.signals):
prepr = pretty(signal)
targ = (('AnalogSignal with %d channels of length %d; units %s; datatype %s \n'
targ = (('AnalogSignal with %d channels of length %d; units %s; datatype %s\n'
'' % (signal.shape[1], signal.shape[0],
signal.units.dimensionality.unicode, signal.dtype))
+ ('annotations: %s\n' % signal.annotations)
Expand Down
2 changes: 1 addition & 1 deletion neo/test/coretest/test_irregularysampledsignal.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ def test__divide_signal_by_const_should_preserve_data_complement(self):
def test__pretty(self):
res = pretty(self.signal1)
signal = self.signal1
targ = (("IrregularlySampledSignal with %d channels of length %d; units %s; datatype %s \n"
targ = (("IrregularlySampledSignal with %d channels of length %d; units %s; datatype %s\n"
"" % (signal.shape[1], signal.shape[0], signal.units.dimensionality.unicode,
signal.dtype))
+ ("name: '{}'\ndescription: '{}'\n".format(signal.name, signal.description))
Expand Down
File renamed without changes.
55 changes: 29 additions & 26 deletions neo/test/iotest/test_medio.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@
import pathlib
import unittest

import quantities as pq
import numpy as np

from neo.io.medio import MedIO
from neo.test.iotest.common_io_test import BaseTestIO
from neo.test.iotest.tools import get_test_file_full_path
from neo.io.proxyobjects import (AnalogSignalProxy,
SpikeTrainProxy, EventProxy, EpochProxy)
from neo import (AnalogSignal, SpikeTrain)

import quantities as pq
import numpy as np
try:
import dhn_med_py
HAVE_DHN_MED = True
except ImportError:
HAVE_DHN_MED = False


# This run standard tests, this is mandatory for all IOs
# This runs standard tests, this is mandatory for all IOs
@unittest.skipUnless(HAVE_DHN_MED, "requires dhn_med_py package and all its dependencies")
class TestMedIO(BaseTestIO, unittest.TestCase, ):
ioclass = MedIO
entities_to_download = ['med']
Expand All @@ -31,22 +34,22 @@ def setUp(self):
self.dirname = self.get_local_path('med/sine_waves.medd')
self.dirname2 = self.get_local_path('med/test.medd')
self.password = 'L2_password'

def test_read_segment_lazy(self):

r = MedIO(self.dirname, self.password)
seg = r.read_segment(lazy=False)

# There will only be one analogsignal in this reading
self.assertEqual(len(seg.analogsignals), 1)
# Test that the correct number of samples are read, 5760000 samps for 3 channels
self.assertEqual(seg.analogsignals[0].shape[0], 5760000)
self.assertEqual(seg.analogsignals[0].shape[1], 3)

# Test the first sample value of all 3 channels, which are
# known to be [-1, -4, -4]
np.testing.assert_array_equal(seg.analogsignals[0][0][:3], [-1, -4, -4])

for anasig in seg.analogsignals:
self.assertNotEqual(anasig.size, 0)
for st in seg.spiketrains:
Expand All @@ -61,61 +64,61 @@ def test_read_segment_lazy(self):
assert ev.name is not None
for ep in seg.epochs:
assert ep.name is not None

r.close()

def test_read_block(self):

r = MedIO(self.dirname, self.password)
bl = r.read_block(lazy=True)
self.assertTrue(bl.annotations)

for count, seg in enumerate(bl.segments):
assert seg.name == 'Seg #' + str(count) + ' Block #0'

for anasig in seg.analogsignals:
assert anasig.name is not None

# Verify that the block annotations from the MED session are
# read properly. There are a lot of annotations, so we'll just
# spot-check a couple of them.
assert(bl.annotations['metadata']['recording_country'] == 'United States')
assert(bl.annotations['metadata']['AC_line_frequency'] == 60.0)

r.close()

def test_read_segment_with_time_slice(self):
"""
Test loading of a time slice and check resulting times
"""
r = MedIO(self.dirname, self.password)
seg = r.read_segment(time_slice=None)

# spike and epoch timestamps are not being read
self.assertEqual(len(seg.spiketrains), 0)
self.assertEqual(len(seg.epochs), 1)
self.assertEqual(len(seg.epochs[0]), 0)

# Test for 180 events (1 per second for 3 minute recording)
self.assertEqual(len(seg.events), 1)
self.assertEqual(len(seg.events[0]), 180)

for asig in seg.analogsignals:
self.assertEqual(asig.shape[0], 5760000)
n_channels = sum(a.shape[-1] for a in seg.analogsignals)
self.assertEqual(n_channels, 3)

t_start, t_stop = 500 * pq.ms, 800 * pq.ms
seg = r.read_segment(time_slice=(t_start, t_stop))

# Test that 300 ms were read, which at 32 kHz, is 9600 samples
self.assertAlmostEqual(seg.analogsignals[0].shape[0], 9600, delta=1.)
# Test that it read from 3 channels
self.assertEqual(seg.analogsignals[0].shape[1], 3)

self.assertAlmostEqual(seg.t_start.rescale(t_start.units), t_start, delta=5.)
self.assertAlmostEqual(seg.t_stop.rescale(t_stop.units), t_stop, delta=5.)

r.close()


Expand Down
8 changes: 8 additions & 0 deletions neo/test/iotest/test_plexon2io.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
from neo.test.rawiotest.test_plexon2rawio import TestPlexon2RawIO


try:
from neo.rawio.plexon2rawio.pypl2 import pypl2lib
HAVE_PYPL2 = True
except (ImportError, TimeoutError):
HAVE_PYPL2 = False


@unittest.skipUnless(HAVE_PYPL2, "requires pypl package and all its dependencies")
class TestPlexon2IO(BaseTestIO, unittest.TestCase):
entities_to_download = TestPlexon2RawIO.entities_to_download
entities_to_test = TestPlexon2RawIO.entities_to_test
Expand Down
9 changes: 9 additions & 0 deletions neo/test/rawiotest/test_cedrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

from neo.test.rawiotest.common_rawio_test import BaseTestRawIO

try:
import sonpy
HAVE_SONPY = True
except ImportError:
HAVE_SONPY = False


# This runs standard tests, this is mandatory for all IOs
@unittest.skipUnless(HAVE_SONPY, "requires sonpy package and all its dependencies")

class TestCedRawIO(BaseTestRawIO, unittest.TestCase, ):
rawioclass = CedRawIO
Expand Down
Loading