Exemplo n.º 1
0
 def test(self):
     location = self.schemata
     # Keep track of lack of failures.
     failed = False
     # Get the maximum schema version.
     final_version = max(
         schevo.schema.latest_version(location), self.max_version)
     # For schema version N from 2 to maximum,
     for N in xrange(2, final_version + 1):
         # Read schema version N.
         schema_N = schevo.schema.read(location, N)
         # Create a database directly at version N.
         fp_direct = StringIO()
         db_direct = database.create(
             filename=None,
             backend_name='schevo.store',
             backend_args=dict(fp=fp_direct, cache_size=100000),
             schema_source=schema_N,
             schema_version=N,
             )
         # Read schema version N - 1.
         schema_N1 = schevo.schema.read(location, N - 1)
         # Create a database at version N - 1.
         fp_evolved = StringIO()
         db_evolved = database.create(
             filename=None,
             backend_name='schevo.store',
             backend_args=dict(fp=fp_evolved, cache_size=100000),
             schema_source=schema_N1,
             schema_version=N - 1,
             )
         # Evolve database to version N.
         database.evolve(db_evolved, schema_N, N)
         # Compare the databases.
         is_equivalent = database.equivalent(db_direct, db_evolved)
         # If failure,
         if not is_equivalent:
             if self.expected_failure:
                 # If failure expected, keep track of failure.
                 failed = True
             else:
                 # If failure not expected, raise an exception.
                 raise Exception(
                     'Database created directly at version %i is not '
                     'the same as database created at version %i then '
                     'evolved to version %i.'
                     % (N, N - 1, N)
                     )
         db_direct.close()
         db_evolved.close()
     # If failure expected, but no failures,
     if self.expected_failure and not failed:
         # Raise an exception.
         raise Exception(
             'Expected databases to be unequal at some point, but '
             'they are all functionally equivalent.'
             )
Exemplo n.º 2
0
    def backend_base_open(test_object, suffix, schema_source, schema_version):
        """Perform the actual opening of a database, then return it.

        - `test_object`: The instance of the test class we're opening
          a database for.
        - `suffix`: The suffix to use on variable names when storing
          open databases and auxiliary information.
        - `schema_source`: Schema source code to use.
        - `schema_version`: Version of the schema to use.
        """
        db_name = 'db' + suffix
        filename = getattr(test_object, 'filename' + suffix, None)
        if filename is None:
            filename = random_filename()
            db = database.create(
                filename = filename,
                backend_name = 'durus',
                backend_args = test_object.backend_args,
                schema_source = schema_source,
                schema_version = schema_version,
                format = test_object.format,
                )
        else:
            db = database.open(
                filename = filename,
                backend_name = 'durus',
                backend_args = test_object.backend_args,
                )
        setattr(test_object, db_name, db)
        setattr(test_object, 'filename' + suffix, filename)
        return db
Exemplo n.º 3
0
    def backend_base_open(test_object, suffix, schema_source, schema_version):
        """Perform the actual opening of a database, then return it.

        - `test_object`: The instance of the test class we're opening
          a database for.
        - `suffix`: The suffix to use on variable names when storing
          open databases and auxiliary information.
        - `schema_source`: Schema source code to use.
        - `schema_version`: Version of the schema to use.
        """
        db_name = 'db' + suffix
        contents = TestMethods_CreatesDatabase.backend_db_contents(
            test_object, suffix)
        fp = StringIO(contents)
        if len(contents) == 0:
            db = database.create(
                filename=None,
                backend_name='schevo.store',
                backend_args=dict(fp=fp, cache_size=100000),
                schema_source=schema_source,
                schema_version=schema_version,
                format=test_object.format,
                )
        else:
            db = database.open(
                filename=None,
                backend_name='schevo.store',
                backend_args=dict(fp=fp, cache_size=100000),
                )
        setattr(test_object, db_name, db)
        setattr(test_object, 'fp' + suffix, fp)
        return db