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_exampleio.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # -*- coding: utf-8 -*-
  2. """
  3. Tests of neo.io.exampleio
  4. """
  5. # needed for python 3 compatibility
  6. from __future__ import unicode_literals, print_function, division, absolute_import
  7. import unittest
  8. from neo.io.exampleio import ExampleIO # , HAVE_SCIPY
  9. from neo.test.iotest.common_io_test import BaseTestIO
  10. import quantities as pq
  11. import numpy as np
  12. # This run standart tests, this is mandatory for all IO
  13. class TestExampleIO(BaseTestIO, unittest.TestCase, ):
  14. ioclass = ExampleIO
  15. files_to_test = ['fake1',
  16. 'fake2',
  17. ]
  18. files_to_download = []
  19. class Specific_TestExampleIO(unittest.TestCase):
  20. def test_read_segment_lazy(self):
  21. r = ExampleIO(filename=None)
  22. seg = r.read_segment(lazy=True)
  23. for ana in seg.analogsignals:
  24. self.assertEqual(ana.size, 0)
  25. assert hasattr(ana, 'lazy_shape')
  26. for st in seg.spiketrains:
  27. self.assertEqual(st.size, 0)
  28. assert hasattr(st, 'lazy_shape')
  29. seg = r.read_segment(lazy=False)
  30. for anasig in seg.analogsignals:
  31. self.assertNotEqual(anasig.size, 0)
  32. for st in seg.spiketrains:
  33. self.assertNotEqual(st.size, 0)
  34. # annotations
  35. assert 'seg_extra_info' in seg.annotations
  36. assert seg.name == 'Seg #0 Block #0'
  37. for anasig in seg.analogsignals:
  38. assert anasig.name is not None
  39. for st in seg.spiketrains:
  40. assert st.name is not None
  41. for ev in seg.events:
  42. assert ev.name is not None
  43. for ep in seg.epochs:
  44. assert ep.name is not None
  45. def test_read_block(self):
  46. r = ExampleIO(filename=None)
  47. bl = r.read_block(lazy=True)
  48. assert len(bl.list_units) == 3
  49. assert len(bl.channel_indexes) == 1 + 3 # signals grouped + units
  50. def test_read_segment_with_time_slice(self):
  51. r = ExampleIO(filename=None)
  52. seg = r.read_segment(time_slice=None)
  53. shape_full = seg.analogsignals[0].shape
  54. spikes_full = seg.spiketrains[0]
  55. event_full = seg.events[0]
  56. t_start, t_stop = 260 * pq.ms, 1.854 * pq.s
  57. seg = r.read_segment(time_slice=(t_start, t_stop))
  58. shape_slice = seg.analogsignals[0].shape
  59. spikes_slice = seg.spiketrains[0]
  60. event_slice = seg.events[0]
  61. assert shape_full[0] > shape_slice[0]
  62. assert spikes_full.size > spikes_slice.size
  63. assert np.all(spikes_slice >= t_start)
  64. assert np.all(spikes_slice <= t_stop)
  65. assert spikes_slice.t_start == t_start
  66. assert spikes_slice.t_stop == t_stop
  67. assert event_full.size > event_slice.size
  68. assert np.all(event_slice.times >= t_start)
  69. assert np.all(event_slice.times <= t_stop)
  70. if __name__ == "__main__":
  71. unittest.main()