Skip to content

Commit 3d86c12

Browse files
committed
update neuroshare tests to also work for neuroshareapiio
1 parent f3dce46 commit 3d86c12

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

neo/test/iotest/test_neuroshareio.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import sys
66
import os
7+
import pathlib
8+
import shutil
79
import tarfile
810
import zipfile
911
import tempfile
@@ -15,34 +17,33 @@
1517
from neo.test.iotest.common_io_test import BaseTestIO
1618

1719

18-
class TestNeuroshareIO(unittest.TestCase, BaseTestIO):
20+
class TestNeuroshareIO(BaseTestIO, unittest.TestCase):
1921
ioclass = NeuroshareIO
20-
entities_to_download = [
21-
'neuroshare/Multichannel_fil_1.mcd'
22-
]
22+
entities_to_download = ['neuroshare']
2323
entities_to_test = ['neuroshare/Multichannel_fil_1.mcd']
2424

25-
def setUp(self):
26-
BaseTestIO.setUp(self)
25+
@classmethod
26+
def setUpClass(cls, *args, **kwargs):
27+
super().setUpClass()
2728
if sys.platform.startswith('win'):
2829
distantfile = 'http://download.multichannelsystems.com/download_data/software/neuroshare/nsMCDLibrary_3.7b.zip'
2930
localfile = os.path.join(tempfile.gettempdir(), 'nsMCDLibrary_3.7b.zip')
3031
if not os.path.exists(localfile):
3132
urlretrieve(distantfile, localfile)
3233
if platform.architecture()[0].startswith('64'):
33-
self.dllname = os.path.join(
34+
cls.dllname = os.path.join(
3435
tempfile.gettempdir(),
3536
'Matlab/Matlab-Import-Filter/Matlab_Interface/nsMCDLibrary64.dll')
36-
if not os.path.exists(self.dllname):
37+
if not os.path.exists(cls.dllname):
3738
zip = zipfile.ZipFile(localfile)
3839
zip.extract(
3940
'Matlab/Matlab-Import-Filter/Matlab_Interface/nsMCDLibrary64.dll',
4041
path=tempfile.gettempdir())
4142
else:
42-
self.dllname = os.path.join(
43+
cls.dllname = os.path.join(
4344
tempfile.gettempdir(),
4445
'Matlab/Matlab-Import-Filter/Matlab_Interface/nsMCDLibrary.dll')
45-
if not os.path.exists(self.dllname):
46+
if not os.path.exists(cls.dllname):
4647
zip = zipfile.ZipFile(localfile)
4748
zip.extract(
4849
'Matlab/Matlab-Import-Filter/Matlab_Interface/nsMCDLibrary.dll',
@@ -57,13 +58,30 @@ def setUp(self):
5758
localfile = os.path.join(tempfile.gettempdir(), 'nsMCDLibrary_Linux32_3.7b.tar.gz')
5859
if not os.path.exists(localfile):
5960
urlretrieve(distantfile, localfile)
60-
self.dllname = os.path.join(tempfile.gettempdir(), 'nsMCDLibrary/nsMCDLibrary.so')
61-
if not os.path.exists(self.dllname):
61+
cls.dllname = os.path.join(tempfile.gettempdir(), 'nsMCDLibrary/nsMCDLibrary.so')
62+
if not os.path.exists(cls.dllname):
6263
tar = tarfile.open(localfile)
6364
tar.extract('nsMCDLibrary/nsMCDLibrary.so', path=tempfile.gettempdir())
6465
else:
6566
raise unittest.SkipTest("Not currently supported on OS X")
6667

68+
# move dll to path discoverable by neuroshare package
69+
discoverable_path = pathlib.Path.home() / ".neuroshare" / cls.dllname.split('/')[-1]
70+
if not discoverable_path.exists():
71+
discoverable_path.parent.mkdir(exist_ok=True)
72+
shutil.copyfile(cls.dllname, discoverable_path)
73+
cls._cleanup_library = True
74+
else:
75+
cls._cleanup_library = False
76+
77+
cls.default_keyword_arguments['dllname'] = cls.dllname
78+
79+
@classmethod
80+
def tearDownClass(cls) -> None:
81+
if cls._cleanup_library:
82+
discoverable_path = pathlib.Path.home() / ".neuroshare" / cls.dllname.split('/')[-1]
83+
discoverable_path.unlink(missing_ok=True)
84+
6785
def test_with_multichannel(self):
6886
for filename in self.files_to_test:
6987
filename = self.get_local_path(filename)

0 commit comments

Comments
 (0)