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
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
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
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
def make_hist(): h = History("sqlite:///" + path) h.store_initial_data(0, {}, {}, {}, model_names, "", "", "") return h