예제 #1
0
    def backend_open(test_object, suffix, schema):
        """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.
        - `suffix`: The suffix to use on variable names when storing
          open databases and auxiliary information.
        - `schema`: Schema source code to use.
        """
        format = test_object.format
        db_name = 'db' + suffix
        filename_name = 'filename' + suffix
        cache_key = (tuple(sorted(test_object.backend_args.items())),
                     format, 1, None, schema, suffix)
        if (test_object._use_db_cache
            and cache_key in _db_cache
            and not hasattr(test_object, filename_name)
            ):
            db, filename = _db_cache[cache_key]
            setattr(test_object, filename_name, filename)
            if not hasattr(test_object, db_name):
                db._reset_all()
            setattr(test_object, db_name, db)
        else:
            # Forget existing modules.
            for m in module.MODULES:
                module.forget(m)
            db = test_object._base_open(suffix, schema)
        if test_object._use_db_cache:
            filename = getattr(test_object, filename_name)
            db_info = (db, filename)
            _db_cache[cache_key] = db_info
            _cached_dbs.add(db)
        return db
예제 #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
def test_remember_forget():
    m = module.from_string(MODULE_SRC, 'some_module')
    module.remember(m)
    assert m.__name__ in sys.modules
    module.forget(m)
    assert m.__name__ not in sys.modules