def test_droppop_with_metamodels(): with test_core.t1() as (bdb, _population_id, _generator_id): distinctive_name = 'frobbledithorpequack' bdb.execute('create metamodel %s for p1 using crosscat' % (distinctive_name, )) with pytest.raises(bayeslite.BQLError): try: bdb.execute('drop population p1') except bayeslite.BQLError as e: assert 'metamodels' in str(e) assert distinctive_name in str(e) raise
def test_mutinf_smoke(seed): with test_core.t1(seed=seed) as (bdb, population_id, _generator_id): def checkmi(n, q, *p): i = 0 for r in bdb.sql_execute(q, *p): assert len(r) == 1 assert isinstance(r[0], float) i += 1 assert i == n, '%r =/= %r' % (i, n) bdb.execute('initialize 10 models for p1_cc') checkmi( 10, ''' select mi from bql_mutinf where population_id = ? and target_vars = '[1]' and reference_vars = '[2]' ''', (population_id, )) bdb.execute('initialize 11 models if not exists for p1_cc') checkmi( 11, ''' select mi from bql_mutinf where population_id = ? and target_vars = '[1]' and reference_vars = '[2]' and conditions = '{"3": 42}' ''', (population_id, )) bdb.execute('initialize 12 models if not exists for p1_cc') checkmi( 12, ''' select mi from bql_mutinf where population_id = ? and target_vars = '[1]' and reference_vars = '[2]' and nsamples = 2 ''', (population_id, )) bdb.execute('initialize 13 models if not exists for p1_cc') checkmi( 13, ''' select mi from bql_mutinf where population_id = ? and target_vars = '[1]' and reference_vars = '[2]' and conditions = '{"3": 42}' and nsamples = 2 ''', (population_id, ))
def test_sessions_error_metamodel(): with test_core.t1() as (bdb, _generator_id): bayeslite.bayesdb_register_metamodel(bdb, ErroneousMetamodel()) bdb.execute(''' CREATE GENERATOR t1_err FOR t1 USING erroneous(age NUMERICAL) ''') tr = sescap.SessionOrchestrator(bdb) cursor = bdb.execute(''' ESTIMATE PREDICTIVE PROBABILITY OF age FROM t1_err ''') with pytest.raises(Boom): cursor.fetchall() #tr._start_new_session() assert tr._check_error_entries(tr.session_id) > 0
def test_sessions_no_errors(): with test_core.analyzed_bayesdb_population(test_core.t1(), 10, None, max_seconds=1) as (bdb, population_id, generator_id): tr = sescap.SessionOrchestrator(bdb) # simple query cursor = bdb.execute(''' SELECT age, weight FROM t1 WHERE label = 'frotz' ORDER BY weight ''') cursor.fetchall() # add a metamodel and do a query cursor = bdb.execute(''' ESTIMATE PREDICTIVE PROBABILITY OF age FROM p1 ''') cursor.fetchall() # there should be no error entries in the previous session #tr._start_new_session() assert tr._check_error_entries(tr.session_id) == 0