def _assert_baseline_dataframe(result, force_update=False): with tempfile.NamedTemporaryFile(mode="w", delete=False) as fp: result.to_csv(fp.name, index=False) fp.flush() baseline_filename = create_baseline(fp.name, force_update=force_update) pd.testing.assert_frame_equal( result, pd.read_csv(baseline_filename, dtype=np.RESULT_DTYPES))
def _assert_baseline(result, force_update=False): with tempfile.NamedTemporaryFile(mode="w", delete=False) as fp: json.dump(result, fp, indent=4) baseline_filename = create_baseline(fp.name, force_update=force_update) with open(baseline_filename) as fp: assert result == pytest.approx(json.load(fp))
def test_run_seeded(base_data_dir): try: sampleUseOfModel.main(["-c", str(base_data_dir / "config.yaml")]) test_data = base_data_dir / "output" / "simple_network_sim" / "outbreak-timeseries" / "data.csv" baseline = create_baseline(test_data) test_df = pd.read_csv(test_data) baseline_df = pd.read_csv(baseline) pd.testing.assert_frame_equal( test_df.set_index(["time", "node", "age", "state"]), baseline_df.set_index(["time", "node", "age", "state"]), check_like=True, ) finally: # TODO; remove this once https://github.com/ScottishCovidResponse/data_pipeline_api/issues/12 is done (base_data_dir / "access.log").unlink()
def test_stochastic_cli_run(base_data_dir): try: sampleUseOfModel.main(["-c", str(base_data_dir / "config_stochastic.yaml")]) h5_file = base_data_dir / "output" / "simple_network_sim" / "outbreak-timeseries" / "data.h5" csv_file = base_data_dir / "output" / "simple_network_sim" / "outbreak-timeseries" / "data.csv" hdf5_to_csv.main([str(h5_file), str(csv_file)]) baseline = create_baseline(csv_file) test_df = pd.read_csv(csv_file) baseline_df = pd.read_csv(baseline) pd.testing.assert_frame_equal( test_df.set_index(["date", "node", "age", "state"]), baseline_df.set_index(["date", "node", "age", "state"]), check_like=True, ) finally: # TODO; remove this once https://github.com/ScottishCovidResponse/data_pipeline_api/issues/12 is done (base_data_dir / "access.log").unlink() h5_file.unlink() csv_file.unlink()