Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

test_neuroshareio.py 3.3 KB

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