|
18 | 18 | __test__ = False |
19 | 19 |
|
20 | 20 | import os |
| 21 | +import inspect |
21 | 22 | from copy import copy |
22 | 23 | import unittest |
23 | 24 |
|
24 | 25 | from neo.core import Block, Segment |
| 26 | +from neo.io.basefromrawio import BaseFromRaw |
25 | 27 | from neo.test.tools import (assert_same_sub_schema, |
26 | 28 | assert_neo_object_is_compliant, |
27 | 29 | assert_sub_schema_is_lazy_loaded, |
@@ -154,7 +156,7 @@ def able_to_write_or_read(self, writeread=False, readwrite=False): |
154 | 156 | # sampling_rate (RawBinaryIO...) the test is too much complex to design |
155 | 157 | # genericaly. |
156 | 158 | if (self.higher in self.ioclass.read_params and |
157 | | - len(self.ioclass.read_params[self.higher]) != 0): |
| 159 | + len(self.ioclass.read_params[self.higher]) != 0): |
158 | 160 | return False |
159 | 161 |
|
160 | 162 | # handle cases where the test should write then read |
@@ -511,3 +513,48 @@ def test_readed_with_lazy_is_compliant(self): |
511 | 513 | # intercept exceptions and add more information |
512 | 514 | except BaseException as exc: |
513 | 515 | raise |
| 516 | + |
| 517 | + def test_create_group_across_segment(self): |
| 518 | + """ |
| 519 | + Read {io_name} files in 'files_to_test' with |
| 520 | + create_group_across_segment test cases. |
| 521 | +
|
| 522 | + Test read_block method of BaseFromRaw with different test cases |
| 523 | + for create_group_across_segment. |
| 524 | +
|
| 525 | + """.format(io_name=self.ioclass.__name__) |
| 526 | + |
| 527 | + test_cases = [ |
| 528 | + {"SpikeTrain": True}, |
| 529 | + {"AnalogSignal": True}, |
| 530 | + {"Event": True}, |
| 531 | + {"Epoch": True}, |
| 532 | + {"SpikeTrain": True, |
| 533 | + "AnalogSignal": True, |
| 534 | + "Event": True, |
| 535 | + "Epoch": True}, |
| 536 | + True |
| 537 | + ] |
| 538 | + expected_outcomes = [ |
| 539 | + None, |
| 540 | + None, |
| 541 | + NotImplementedError, |
| 542 | + NotImplementedError, |
| 543 | + NotImplementedError, |
| 544 | + NotImplementedError, |
| 545 | + ] |
| 546 | + |
| 547 | + mock_test_case = unittest.TestCase() |
| 548 | + if issubclass(self.ioclass, BaseFromRaw): |
| 549 | + for obj, reader in self.iter_objects(target=Block, |
| 550 | + lazy=self.ioclass.support_lazy, |
| 551 | + return_reader=True): |
| 552 | + if "create_group_across_segment" in inspect.signature(reader).parameters.keys(): |
| 553 | + # Ignore testing readers for IOs where read_block is overridden to exclude |
| 554 | + # the create_group_across_segment functionality, for eg. NixIO_fr |
| 555 | + for case, outcome in zip(test_cases, expected_outcomes): |
| 556 | + if outcome is not None: |
| 557 | + with mock_test_case.assertRaises(outcome): |
| 558 | + reader(lazy=self.ioclass.support_lazy, create_group_across_segment=case) |
| 559 | + else: |
| 560 | + reader(lazy=self.ioclass.support_lazy, create_group_across_segment=case) |
0 commit comments