test_neuroshareio.py 3.3 KB

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