예제 #1
0
def test_update_nr_samples(history: History):
    history.store_initial_data(None, {}, {}, {}, ["m0"], "", "", "")
    pops = history.get_all_populations()
    assert 0 == pops[pops['t'] == History.PRE_TIME]['samples'].values
    history.update_nr_samples(History.PRE_TIME, 43)
    pops = history.get_all_populations()
    assert 43 == pops[pops['t'] == History.PRE_TIME]['samples'].values
예제 #2
0
def test_update_after_calibration(history: History):
    history.store_initial_data(None, {}, {}, {}, ["m0"], "", "", "")
    pops = history.get_all_populations()
    assert 0 == pops[pops['t'] == History.PRE_TIME]['samples'].values
    time = datetime.datetime.now()
    history.update_after_calibration(43, end_time=time)
    pops = history.get_all_populations()
    assert 43 == pops[pops['t'] == History.PRE_TIME]['samples'].values
    assert pops.population_end_time[0] == time
예제 #3
0
def history():
    # Don't use memory database for testing.
    # A real file with disconnect and reconnect is closer to the real scenario
    this_path = path()
    model_names = ["fake_name_{}".format(k) for k in range(50)]
    h = History("sqlite:///" + this_path)
    h.store_initial_data(0, {}, {}, {}, model_names, "", "",
                         '{"name": "pop_strategy_str_test"}')
    yield h
    try:
        os.remove(this_path)
    except FileNotFoundError:
        pass
예제 #4
0
def history(request):
    # Test in-memory and filesystem based database
    if request.param == "file":
        this_path = "/" + path()
    elif request.param == "memory":
        this_path = ""
    else:
        raise Exception(f"Bad database type for testing: {request.param}")
    model_names = ["fake_name_{}".format(k) for k in range(50)]
    h = History("sqlite://" + this_path)
    h.store_initial_data(0, {}, {}, {}, model_names, "", "",
                         '{"name": "pop_strategy_str_test"}')
    yield h
    if request.param == "file":
        try:
            os.remove(this_path)
        except FileNotFoundError:
            pass
예제 #5
0
    def make_hist():

        h = History("sqlite:///" + path)
        h.store_initial_data(0, {}, {}, {}, model_names, "", "", "")
        return h