def test_write_then_read(self):
        '''
        Test for IO that are able to write and read - here %s:
          1 - Generate a full schema with supported objects.
          2 - Write to a file
          3 - Read from the file
          4 - Check the hierachy
          5 - Check data

        Work only for IO for Block and Segment for the highest object
        (main cases).
        ''' % self.ioclass.__name__

        if not self.able_to_write_or_read(writeread=True):
            return

        for cascade in self.cascade_modes:
            ioobj1 = self.generic_io_object(clean=True)

            if ioobj1 is None:
                return

            ob1 = write_generic(ioobj1, target=self.higher)
            close_object_safe(ioobj1)

            ioobj2 = self.generic_io_object()

            # Read the highest supported object from the file
            obj_reader = create_generic_reader(ioobj2, target=False)
            ob2 = obj_reader(cascade=cascade)[0]
            if self.higher == Segment:
                ob2 = ob2.segments[0]

            # some formats (e.g. elphy) do not support double floating
            # point spiketrains
            try:
                assert_same_sub_schema(ob1, ob2, True, 1e-8)
                assert_neo_object_is_compliant(ob1)
                assert_neo_object_is_compliant(ob2)
            # intercept exceptions and add more information
            except BaseException as exc:
                exc.args += ('with cascade=%s ' % cascade,)
                raise

            close_object_safe(ioobj2)
Example #2
0
    def test_write_then_read(self):
        '''
        Test for IO that are able to write and read - here %s:
          1 - Generate a full schema with supported objects.
          2 - Write to a file
          3 - Read from the file
          4 - Check the hierachy
          5 - Check data

        Work only for IO for Block and Segment for the highest object
        (main cases).
        ''' % self.ioclass.__name__

        if not self.able_to_write_or_read(writeread=True):
            return

        for cascade in self.cascade_modes:
            ioobj1 = self.generic_io_object(clean=True)

            if ioobj1 is None:
                return

            ob1 = write_generic(ioobj1, target=self.higher)
            close_object_safe(ioobj1)

            ioobj2 = self.generic_io_object()

            # Read the highest supported object from the file
            obj_reader = create_generic_reader(ioobj2, target=False)
            ob2 = obj_reader(cascade=cascade)[0]
            if self.higher == Segment:
                ob2 = ob2.segments[0]

            # some formats (e.g. elphy) do not support double floating
            # point spiketrains
            try:
                assert_same_sub_schema(ob1, ob2, True, 1e-8)
                assert_neo_object_is_compliant(ob1)
                assert_neo_object_is_compliant(ob2)
            # intercept exceptions and add more information
            except BaseException as exc:
                exc.args += ('with cascade=%s ' % cascade, )
                raise

            close_object_safe(ioobj2)
Example #3
0
    def generate_files_for_io_able_to_write(self):
        '''
        Write files for use in testing.
        '''
        self.files_generated = []
        if not self.able_to_write_or_read():
            return

        generate_from_supported_objects(self.ioclass.supported_objects)

        ioobj, path = self.generic_io_object(return_path=True, clean=True)
        if ioobj is None:
            return

        self.files_generated.append(path)

        write_generic(ioobj, target=self.higher)

        close_object_safe(ioobj)
    def generate_files_for_io_able_to_write(self):
        '''
        Write files for use in testing.
        '''
        self.files_generated = []
        if not self.able_to_write_or_read():
            return

        generate_from_supported_objects(self.ioclass.supported_objects)

        ioobj, path = self.generic_io_object(return_path=True, clean=True)
        if ioobj is None:
            return

        self.files_generated.append(path)

        write_generic(ioobj, target=self.higher)

        close_object_safe(ioobj)