test_neuroshareio.py 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. @unittest.skipUnless(sys.platform.startswith("win"), "Only works on Windows")
  21. class TestNeuroshareIO(unittest.TestCase, BaseTestIO):
  22. ioclass = NeuroshareIO
  23. files_to_test = []
  24. files_to_download = ['Multichannel_fil_1.mcd', ]
  25. def setUp(self):
  26. BaseTestIO.setUp(self)
  27. if sys.platform.startswith('win'):
  28. distantfile = 'http://download.multichannelsystems.com/download_data/software/neuroshare/nsMCDLibrary_3.7b.zip'
  29. localfile = os.path.join(tempfile.gettempdir(), 'nsMCDLibrary_3.7b.zip')
  30. if not os.path.exists(localfile):
  31. urlretrieve(distantfile, localfile)
  32. if platform.architecture()[0].startswith('64'):
  33. self.dllname = os.path.join(
  34. tempfile.gettempdir(),
  35. 'Matlab/Matlab-Import-Filter/Matlab_Interface/nsMCDLibrary64.dll')
  36. if not os.path.exists(self.dllname):
  37. zip = zipfile.ZipFile(localfile)
  38. zip.extract(
  39. 'Matlab/Matlab-Import-Filter/Matlab_Interface/nsMCDLibrary64.dll',
  40. path=tempfile.gettempdir())
  41. else:
  42. self.dllname = os.path.join(
  43. tempfile.gettempdir(),
  44. 'Matlab/Matlab-Import-Filter/Matlab_Interface/nsMCDLibrary.dll')
  45. if not os.path.exists(self.dllname):
  46. zip = zipfile.ZipFile(localfile)
  47. zip.extract(
  48. 'Matlab/Matlab-Import-Filter/Matlab_Interface/nsMCDLibrary.dll',
  49. path=tempfile.gettempdir())
  50. elif sys.platform.startswith('linux'):
  51. if platform.architecture()[0].startswith('64'):
  52. distantfile = 'http://download.multichannelsystems.com/download_data/software/neuroshare/nsMCDLibrary_Linux64_3.7b.tar.gz'
  53. localfile = os.path.join(tempfile.gettempdir(), 'nsMCDLibrary_Linux64_3.7b.tar.gz')
  54. else:
  55. distantfile = 'http://download.multichannelsystems.com/download_data/software/neuroshare/nsMCDLibrary_Linux32_3.7b.tar.gz'
  56. localfile = os.path.join(tempfile.gettempdir(), 'nsMCDLibrary_Linux32_3.7b.tar.gz')
  57. if not os.path.exists(localfile):
  58. urlretrieve(distantfile, localfile)
  59. self.dllname = os.path.join(tempfile.gettempdir(), 'nsMCDLibrary/nsMCDLibrary.so')
  60. if not os.path.exists(self.dllname):
  61. tar = tarfile.open(localfile)
  62. tar.extract('nsMCDLibrary/nsMCDLibrary.so', path=tempfile.gettempdir())
  63. else:
  64. raise unittest.SkipTest("Not currently supported on OS X")
  65. def test_with_multichannel(self):
  66. filename0 = self.get_filename_path(self.files_to_download[0])
  67. reader = NeuroshareIO(filename0, self.dllname)
  68. blocks = reader.read()
  69. n = len(blocks[0].segments[0].analogsignals)
  70. assert n == 2, \
  71. 'For {} , nb AnalogSignal: {} (should be 2)'.format(self.files_to_download[0], n)
  72. if __name__ == "__main__":
  73. unittest.main()