def test_schema_compatible(): for i, old_version in enumerate(USABLE_VERSIONS[:-1]): for new_version in USABLE_VERSIONS[i + 1:]: with tempfile.NamedTemporaryFile(prefix='bayeslite') as f: with bayesdb_open(pathname=f.name, version=old_version) as bdb: for same_or_older_version in USABLE_VERSIONS[:i + 1]: bayesdb_schema_required( bdb, same_or_older_version, 'has%s needs% ok' % (old_version, same_or_older_version)) msg = 'has%s needs%s should fail' % (old_version, new_version) try: with pytest.raises(BayesDBException): bayesdb_schema_required(bdb, new_version, msg) except: print msg raise # Now open it in compatible mode. Nothing should change. with bayesdb_open(pathname=f.name, compatible=True) as bdb: bayesdb_schema_required(bdb, old_version, 'opened compatible, old still ok') with pytest.raises(BayesDBException): bayesdb_schema_required( bdb, new_version, 'opened compatible, needs%s still fails' % (new_version, )) # Now explicitly upgrade. Then everything should be okay. bayesdb_upgrade_schema(bdb) with bayesdb_open(pathname=f.name, compatible=True) as bdb: for v in USABLE_VERSIONS: bayesdb_schema_required( bdb, v, 'after explicit upgrade, needs%s ok' % (v, ))
def test_schema_compatible(): for i, old_version in enumerate(USABLE_VERSIONS[:-1]): for new_version in USABLE_VERSIONS[i+1:]: with tempfile.NamedTemporaryFile(prefix='bayeslite') as f: with bayesdb_open(pathname=f.name, version=old_version) as bdb: for same_or_older_version in USABLE_VERSIONS[:i+1]: bayesdb_schema_required( bdb, same_or_older_version, 'has%s needs% ok' % (old_version, same_or_older_version)) msg = 'has%s needs%s should fail' % ( old_version, new_version) try: with pytest.raises(BayesDBException): bayesdb_schema_required(bdb, new_version, msg) except: print msg raise # Now open it in compatible mode. Nothing should change. with bayesdb_open(pathname=f.name, compatible=True) as bdb: bayesdb_schema_required(bdb, old_version, 'opened compatible, old still ok') with pytest.raises(BayesDBException): bayesdb_schema_required( bdb, new_version, 'opened compatible, needs%s still fails' % ( new_version,)) # Now explicitly upgrade. Then everything should be okay. bayesdb_upgrade_schema(bdb) with bayesdb_open(pathname=f.name, compatible=True) as bdb: for v in USABLE_VERSIONS: bayesdb_schema_required( bdb, v, 'after explicit upgrade, needs%s ok' % (v,))
def test_schema_incompatible(): with tempfile.NamedTemporaryFile(prefix='bayeslite') as f: with bayesdb_open(pathname=f.name, version=6) as bdb: bayesdb_schema_required(bdb, 6, 'test incompatible 0/6') with pytest.raises(BayesDBException): bayesdb_schema_required(bdb, 7, 'test incompatible 0/7') with bayesdb_open(pathname=f.name) as bdb: bayesdb_schema_required(bdb, 6, 'test incompatible 1/6') bayesdb_schema_required(bdb, 7, 'test incompatible 1/7') bayesdb_upgrade_schema(bdb) with bayesdb_open(pathname=f.name) as bdb: bayesdb_schema_required(bdb, 6, 'test incompatible 2/6') bayesdb_schema_required(bdb, 7, 'test incompatible 2/7')
def test_schema_upgrade(): with bayesdb_open(version=6) as bdb: bayesdb_schema_required(bdb, 6, 'test pre-upgrade 6') with pytest.raises(BayesDBException): bayesdb_schema_required(bdb, 7, 'test pre-upgrade 7') test_core.t1_schema(bdb) test_core.t1_data(bdb) bayesdb_upgrade_schema(bdb) bayesdb_schema_required(bdb, 6, 'test post-upgrade 6') bayesdb_schema_required(bdb, 7, 'test post-upgrade 7') with pytest.raises(BayesDBException): # Nobody'll ever bump the schema version this many times, # right? bayesdb_schema_required(bdb, 1000000, 'test a gazillion')