Example #1
0
    def backend_convert_format(test_object, suffix, format):
        """Convert the internal structure format of an already-open database.

        - `test_object`: The instance of the test class we're
          converting a database for.
        - `suffix`: The suffix to use on variable names when finding
          the database and auxiliary information for it.
        """
        # Get the contents of the database from the fpv attribute.
        contents = TestMethods_CreatesDatabase.backend_db_contents(
            test_object, suffix)
        # Turn it into a fresh StringIO.
        fp = StringIO(contents)
        # Hack StringIO so that it keeps its buffer around even after
        # closing.
        def close():
            if not fp.closed:
                fp.closed = True
                del fp.pos #, but not fp.buf
        fp.close = close
        # Convert it to the requested format.
        database.convert_format(
            filename=None,
            backend_name='schevo.store',
            backend_args=dict(fp=fp),
            format=format,
            )
        # Turn it back into a fpv attribute.
        setattr(test_object, 'fpv' + suffix, fp.getvalue())
    def backend_convert_format(test_object, suffix, format):
        """Convert the internal structure format of an already-open database.

        - `test_object`: The instance of the test class we're
          converting a database for.
        - `suffix`: The suffix to use on variable names when finding
          the database and auxiliary information for it.
        """
        filename = getattr(test_object, 'filename' + suffix)
        # Convert it to the requested format.
        database.convert_format(
            filename = filename,
            backend_args = test_object.backend_args,
            format = format,
            )