示例#1
0
文件: base.py 项目: gldnspud/schevo
 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.'
             )
示例#2
0
    def backend_open(test_object):
        """Perform the actual opening of a database for a test
        instance.

        - `test_object`: The instance of the test class we're opening
          a database for.
        """
        format = test_object.format
        use_db_cache = test_object._use_db_cache
        db_name = 'db'
        ex_name = 'ex'
        fpv_name = 'fpv'
        schema = test_object.schemata[-1]
        version = test_object.schema_version
        skip_evolution = test_object.skip_evolution
        suffix = ''
        cache_key = (format, version, skip_evolution, schema, suffix)
        if (use_db_cache
            and cache_key in _db_cache
            and not hasattr(test_object, fpv_name)
            ):
            db, fp = _db_cache[cache_key]
            test_object.fp = fp
            if not hasattr(test_object, 'db'):
                db.backend.open()
                db._reset_all()
            test_object.db = db
        else:
            # Forget existing modules.
            for m in module.MODULES:
                module.forget(m)
            if not skip_evolution:
                # Open database with version 1.
                db = test_object._base_open(suffix, test_object.schemata[0])
                # Evolve to latest.
                for i in xrange(1, len(test_object.schemata)):
                    schema_source = test_object.schemata[i]
                    database.evolve(db, schema_source, version=i+1)
            else:
                # Open database with target version.
                db = test_object._base_open(
                    suffix, schema, schema_version=version)
            if use_db_cache:
                fp = test_object.fp
                _db_cache[cache_key] = (db, fp)
                _cached_dbs.add(db)
        return db
示例#3
0
文件: base.py 项目: gldnspud/schevo
 def evolve(self, schema_source, version):
     """Evolve the database to a new schema source and version."""
     db = self.reopen()
     database.evolve(db, schema_source, version)