test_neuroshareio.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. """
  2. Tests of neo.io.neuroshareio
  3. """
  4. import sys
  5. import os
  6. import tarfile
  7. import zipfile
  8. import tempfile
  9. import platform
  10. import unittest
  11. try:
  12. from urllib import urlretrieve # Py2
  13. except ImportError:
  14. from urllib.request import urlretrieve # Py3
  15. from neo.io import NeuroshareIO
  16. from neo.test.iotest.common_io_test import BaseTestIO
  17. @unittest.skipUnless(sys.platform.startswith("win"), "Only works on Windows")
  18. class TestNeuroshareIO(unittest.TestCase, BaseTestIO):
  19. ioclass = NeuroshareIO
  20. files_to_test = []
  21. files_to_download = ['Multichannel_fil_1.mcd', ]
  22. def setUp(self):
  23. BaseTestIO.setUp(self)
  24. if sys.platform.startswith('win'):
  25. distantfile = 'http://download.multichannelsystems.com/download_data/software/neuroshare/nsMCDLibrary_3.7b.zip'
  26. localfile = os.path.join(tempfile.gettempdir(), 'nsMCDLibrary_3.7b.zip')
  27. if not os.path.exists(localfile):
  28. urlretrieve(distantfile, localfile)
  29. if platform.architecture()[0].startswith('64'):
  30. self.dllname = os.path.join(
  31. tempfile.gettempdir(),
  32. 'Matlab/Matlab-Import-Filter/Matlab_Interface/nsMCDLibrary64.dll')
  33. if not os.path.exists(self.dllname):
  34. zip = zipfile.ZipFile(localfile)
  35. zip.extract(
  36. 'Matlab/Matlab-Import-Filter/Matlab_Interface/nsMCDLibrary64.dll',
  37. path=tempfile.gettempdir())
  38. else:
  39. self.dllname = os.path.join(
  40. tempfile.gettempdir(),
  41. 'Matlab/Matlab-Import-Filter/Matlab_Interface/nsMCDLibrary.dll')
  42. if not os.path.exists(self.dllname):
  43. zip = zipfile.ZipFile(localfile)
  44. zip.extract(
  45. 'Matlab/Matlab-Import-Filter/Matlab_Interface/nsMCDLibrary.dll',
  46. path=tempfile.gettempdir())
  47. elif sys.platform.startswith('linux'):
  48. if platform.architecture()[0].startswith('64'):
  49. distantfile = 'http://download.multichannelsystems.com/download_data/software/neuroshare/nsMCDLibrary_Linux64_3.7b.tar.gz'
  50. localfile = os.path.join(tempfile.gettempdir(), 'nsMCDLibrary_Linux64_3.7b.tar.gz')
  51. else:
  52. distantfile = 'http://download.multichannelsystems.com/download_data/software/neuroshare/nsMCDLibrary_Linux32_3.7b.tar.gz'
  53. localfile = os.path.join(tempfile.gettempdir(), 'nsMCDLibrary_Linux32_3.7b.tar.gz')
  54. if not os.path.exists(localfile):
  55. urlretrieve(distantfile, localfile)
  56. self.dllname = os.path.join(tempfile.gettempdir(), 'nsMCDLibrary/nsMCDLibrary.so')
  57. if not os.path.exists(self.dllname):
  58. tar = tarfile.open(localfile)
  59. tar.extract('nsMCDLibrary/nsMCDLibrary.so', path=tempfile.gettempdir())
  60. else:
  61. raise unittest.SkipTest("Not currently supported on OS X")
  62. def test_with_multichannel(self):
  63. filename0 = self.get_filename_path(self.files_to_download[0])
  64. reader = NeuroshareIO(filename0, self.dllname)
  65. blocks = reader.read()
  66. n = len(blocks[0].segments[0].analogsignals)
  67. assert n == 2, \
  68. 'For {} , nb AnalogSignal: {} (should be 2)'.format(self.files_to_download[0], n)
  69. if __name__ == "__main__":
  70. unittest.main()