Skip to content

Commit 1e9e843

Browse files
sprengerJuliaSprenger
authored andcommitted
[neuroshare] extend tests also to linux and IO fixes
1 parent 7c12115 commit 1e9e843

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

neo/io/neurosharectypesio.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import sys
2020
import ctypes
2121
import os
22+
import warnings
2223

2324
import numpy as np
2425
import quantities as pq
@@ -131,6 +132,10 @@ def read_segment(self, import_neuroshare_segment=True,
131132

132133
seg = Segment(file_origin=os.path.basename(self.filename), )
133134

135+
if self.dllname == '':
136+
warnings.warn('No neuroshare dll provided. Can not load data.')
137+
return Segment()
138+
134139
if sys.platform.startswith('win'):
135140
neuroshare = ctypes.windll.LoadLibrary(self.dllname)
136141
elif sys.platform.startswith('linux'):
@@ -147,7 +152,7 @@ def read_segment(self, import_neuroshare_segment=True,
147152

148153
# open file
149154
hFile = ctypes.c_uint32(0)
150-
neuroshare.ns_OpenFile(ctypes.c_char_p(self.filename), ctypes.byref(hFile))
155+
neuroshare.ns_OpenFile(ctypes.c_char_p(bytes(self.filename, 'utf-8')), ctypes.byref(hFile))
151156
fileinfo = ns_FILEINFO()
152157
neuroshare.ns_GetFileInfo(hFile, ctypes.byref(fileinfo), ctypes.sizeof(fileinfo))
153158

@@ -176,8 +181,6 @@ def read_segment(self, import_neuroshare_segment=True,
176181
pdTimeStamp = ctypes.c_double(0.)
177182
pdwDataRetSize = ctypes.c_uint32(0)
178183

179-
ea = Event(name=str(entityInfo.szEntityLabel), )
180-
181184
times = []
182185
labels = []
183186
for dwIndex in range(entityInfo.dwItemCount):
@@ -186,9 +189,10 @@ def read_segment(self, import_neuroshare_segment=True,
186189
ctypes.sizeof(pData), ctypes.byref(pdwDataRetSize))
187190
times.append(pdTimeStamp.value)
188191
labels.append(str(pData.value))
189-
ea.times = times * pq.s
190-
ea.labels = np.array(labels, dtype='U')
192+
times = times * pq.s
193+
labels = np.array(labels, dtype='U')
191194

195+
ea = Event(name=str(entityInfo.szEntityLabel), times=times, labels=labels)
192196
seg.events.append(ea)
193197

194198
# analog
@@ -212,7 +216,7 @@ def read_segment(self, import_neuroshare_segment=True,
212216
ctypes.POINTER(ctypes.c_double)))
213217
total_read += pdwContCount.value
214218

215-
signal = pq.Quantity(pData, units=pAnalogInfo.szUnits, copy=False)
219+
signal = pq.Quantity(pData, units=pAnalogInfo.szUnits.decode(), copy=False)
216220

217221
# t_start
218222
dwIndex = 0

neo/test/iotest/test_neuroshareio.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,19 @@
88
import zipfile
99
import tempfile
1010
import platform
11-
1211
import unittest
13-
14-
try:
15-
from urllib import urlretrieve # Py2
16-
except ImportError:
17-
from urllib.request import urlretrieve # Py3
12+
from urllib.request import urlretrieve
1813

1914
from neo.io import NeuroshareIO
2015
from neo.test.iotest.common_io_test import BaseTestIO
2116

2217

23-
@unittest.skipUnless(sys.platform.startswith("win"), "Only works on Windows")
2418
class TestNeuroshareIO(unittest.TestCase, BaseTestIO):
2519
ioclass = NeuroshareIO
2620
entities_to_download = [
2721
'neuroshare/Multichannel_fil_1.mcd'
2822
]
29-
entities_to_test = []
23+
entities_to_test = ['neuroshare/Multichannel_fil_1.mcd']
3024

3125
def setUp(self):
3226
BaseTestIO.setUp(self)
@@ -71,7 +65,7 @@ def setUp(self):
7165
raise unittest.SkipTest("Not currently supported on OS X")
7266

7367
def test_with_multichannel(self):
74-
filename0 = self.get_local_path(self.files_to_download[0])
68+
filename0 = self.get_local_path(self.files_to_test[0])
7569
reader = NeuroshareIO(filename0, self.dllname)
7670
blocks = reader.read()
7771
n = len(blocks[0].segments[0].analogsignals)

0 commit comments

Comments
 (0)