Ejemplo n.º 1
0
    def write_file(self,
                   obj=None,
                   filename=None,
                   return_path=False,
                   clean=False,
                   target=None):
        '''
        Write the target object to a file using the given neo io object ioobj.

        If filename is None, create a filename (default).

        If return_path is True, return the full path of the file along with
        the object.  return obj, path.  Default is False.

        If clean is True, try to delete existing versions of the file
        before creating the io object.  Default is False.

        If target is None, use the first supported_objects from ioobj
        If target is False, use the 'read' method.
        If target is the Block or Segment class, use read_block or
        read_segment, respectively.
        If target is a string, use 'read_'+target.

        obj is the object to write.  If obj is None, an object is created
        automatically for the io class.
        '''
        ioobj, path = self.generic_io_object(filename=filename,
                                             return_path=True,
                                             clean=clean)
        obj = write_generic(ioobj, target=target, return_reader=False)

        if return_path:
            return obj, path
        return obj
    def write_file(self, obj=None, filename=None, return_path=False,
                   clean=False, target=None):
        '''
        Write the target object to a file using the given neo io object ioobj.

        If filename is None, create a filename (default).

        If return_path is True, return the full path of the file along with
        the object.  return obj, path.  Default is False.

        If clean is True, try to delete existing versions of the file
        before creating the io object.  Default is False.

        If target is None, use the first supported_objects from ioobj
        If target is False, use the 'read' method.
        If target is the Block or Segment class, use read_block or
        read_segment, respectively.
        If target is a string, use 'read_'+target.

        obj is the object to write.  If obj is None, an object is created
        automatically for the io class.
        '''
        ioobj, path = self.generic_io_object(filename=filename,
                                             return_path=True, clean=clean)
        obj = write_generic(ioobj, target=target, return_reader=False)

        if return_path:
            return obj, path
        return obj
Ejemplo n.º 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)
Ejemplo n.º 5
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)
    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)