Skip to content

Commit fdf6013

Browse files
authored
Merge pull request #1361 from apdavison/fix-local-test-failures
Fix some tests that fail when running locally
2 parents 5d08d72 + 606659a commit fdf6013

File tree

8 files changed

+108
-80
lines changed

8 files changed

+108
-80
lines changed

neo/test/coretest/test_analogsignal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def test__repr(self):
286286
def test__pretty(self):
287287
for i, signal in enumerate(self.signals):
288288
prepr = pretty(signal)
289-
targ = (('AnalogSignal with %d channels of length %d; units %s; datatype %s \n'
289+
targ = (('AnalogSignal with %d channels of length %d; units %s; datatype %s\n'
290290
'' % (signal.shape[1], signal.shape[0],
291291
signal.units.dimensionality.unicode, signal.dtype))
292292
+ ('annotations: %s\n' % signal.annotations)

neo/test/coretest/test_irregularysampledsignal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ def test__divide_signal_by_const_should_preserve_data_complement(self):
806806
def test__pretty(self):
807807
res = pretty(self.signal1)
808808
signal = self.signal1
809-
targ = (("IrregularlySampledSignal with %d channels of length %d; units %s; datatype %s \n"
809+
targ = (("IrregularlySampledSignal with %d channels of length %d; units %s; datatype %s\n"
810810
"" % (signal.shape[1], signal.shape[0], signal.units.dimensionality.unicode,
811811
signal.dtype))
812812
+ ("name: '{}'\ndescription: '{}'\n".format(signal.name, signal.description))
File renamed without changes.

neo/test/iotest/test_medio.py

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@
55
import pathlib
66
import unittest
77

8+
import quantities as pq
9+
import numpy as np
10+
811
from neo.io.medio import MedIO
912
from neo.test.iotest.common_io_test import BaseTestIO
10-
from neo.test.iotest.tools import get_test_file_full_path
11-
from neo.io.proxyobjects import (AnalogSignalProxy,
12-
SpikeTrainProxy, EventProxy, EpochProxy)
13-
from neo import (AnalogSignal, SpikeTrain)
1413

15-
import quantities as pq
16-
import numpy as np
14+
try:
15+
import dhn_med_py
16+
HAVE_DHN_MED = True
17+
except ImportError:
18+
HAVE_DHN_MED = False
1719

1820

19-
# This run standard tests, this is mandatory for all IOs
21+
# This runs standard tests, this is mandatory for all IOs
22+
@unittest.skipUnless(HAVE_DHN_MED, "requires dhn_med_py package and all its dependencies")
2023
class TestMedIO(BaseTestIO, unittest.TestCase, ):
2124
ioclass = MedIO
2225
entities_to_download = ['med']
@@ -31,22 +34,22 @@ def setUp(self):
3134
self.dirname = self.get_local_path('med/sine_waves.medd')
3235
self.dirname2 = self.get_local_path('med/test.medd')
3336
self.password = 'L2_password'
34-
37+
3538
def test_read_segment_lazy(self):
36-
39+
3740
r = MedIO(self.dirname, self.password)
3841
seg = r.read_segment(lazy=False)
39-
42+
4043
# There will only be one analogsignal in this reading
4144
self.assertEqual(len(seg.analogsignals), 1)
4245
# Test that the correct number of samples are read, 5760000 samps for 3 channels
4346
self.assertEqual(seg.analogsignals[0].shape[0], 5760000)
4447
self.assertEqual(seg.analogsignals[0].shape[1], 3)
45-
48+
4649
# Test the first sample value of all 3 channels, which are
4750
# known to be [-1, -4, -4]
4851
np.testing.assert_array_equal(seg.analogsignals[0][0][:3], [-1, -4, -4])
49-
52+
5053
for anasig in seg.analogsignals:
5154
self.assertNotEqual(anasig.size, 0)
5255
for st in seg.spiketrains:
@@ -61,61 +64,61 @@ def test_read_segment_lazy(self):
6164
assert ev.name is not None
6265
for ep in seg.epochs:
6366
assert ep.name is not None
64-
67+
6568
r.close()
6669

6770
def test_read_block(self):
68-
71+
6972
r = MedIO(self.dirname, self.password)
7073
bl = r.read_block(lazy=True)
7174
self.assertTrue(bl.annotations)
72-
75+
7376
for count, seg in enumerate(bl.segments):
7477
assert seg.name == 'Seg #' + str(count) + ' Block #0'
75-
78+
7679
for anasig in seg.analogsignals:
7780
assert anasig.name is not None
78-
81+
7982
# Verify that the block annotations from the MED session are
8083
# read properly. There are a lot of annotations, so we'll just
8184
# spot-check a couple of them.
8285
assert(bl.annotations['metadata']['recording_country'] == 'United States')
8386
assert(bl.annotations['metadata']['AC_line_frequency'] == 60.0)
84-
87+
8588
r.close()
86-
89+
8790
def test_read_segment_with_time_slice(self):
8891
"""
8992
Test loading of a time slice and check resulting times
9093
"""
9194
r = MedIO(self.dirname, self.password)
9295
seg = r.read_segment(time_slice=None)
93-
96+
9497
# spike and epoch timestamps are not being read
9598
self.assertEqual(len(seg.spiketrains), 0)
9699
self.assertEqual(len(seg.epochs), 1)
97100
self.assertEqual(len(seg.epochs[0]), 0)
98-
101+
99102
# Test for 180 events (1 per second for 3 minute recording)
100103
self.assertEqual(len(seg.events), 1)
101104
self.assertEqual(len(seg.events[0]), 180)
102-
105+
103106
for asig in seg.analogsignals:
104107
self.assertEqual(asig.shape[0], 5760000)
105108
n_channels = sum(a.shape[-1] for a in seg.analogsignals)
106109
self.assertEqual(n_channels, 3)
107-
110+
108111
t_start, t_stop = 500 * pq.ms, 800 * pq.ms
109112
seg = r.read_segment(time_slice=(t_start, t_stop))
110-
113+
111114
# Test that 300 ms were read, which at 32 kHz, is 9600 samples
112115
self.assertAlmostEqual(seg.analogsignals[0].shape[0], 9600, delta=1.)
113116
# Test that it read from 3 channels
114117
self.assertEqual(seg.analogsignals[0].shape[1], 3)
115-
118+
116119
self.assertAlmostEqual(seg.t_start.rescale(t_start.units), t_start, delta=5.)
117120
self.assertAlmostEqual(seg.t_stop.rescale(t_stop.units), t_stop, delta=5.)
118-
121+
119122
r.close()
120123

121124

neo/test/iotest/test_plexon2io.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
from neo.test.rawiotest.test_plexon2rawio import TestPlexon2RawIO
1111

1212

13+
try:
14+
from neo.rawio.plexon2rawio.pypl2 import pypl2lib
15+
HAVE_PYPL2 = True
16+
except (ImportError, TimeoutError):
17+
HAVE_PYPL2 = False
18+
19+
20+
@unittest.skipUnless(HAVE_PYPL2, "requires pypl package and all its dependencies")
1321
class TestPlexon2IO(BaseTestIO, unittest.TestCase):
1422
entities_to_download = TestPlexon2RawIO.entities_to_download
1523
entities_to_test = TestPlexon2RawIO.entities_to_test

neo/test/rawiotest/test_cedrawio.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44

55
from neo.test.rawiotest.common_rawio_test import BaseTestRawIO
66

7+
try:
8+
import sonpy
9+
HAVE_SONPY = True
10+
except ImportError:
11+
HAVE_SONPY = False
12+
13+
14+
# This runs standard tests, this is mandatory for all IOs
15+
@unittest.skipUnless(HAVE_SONPY, "requires sonpy package and all its dependencies")
716

817
class TestCedRawIO(BaseTestRawIO, unittest.TestCase, ):
918
rawioclass = CedRawIO

0 commit comments

Comments
 (0)