def test_parse_file(): datpath = pathlib.Path(get_test_file("sample_asos.dat")) csvpath = pathlib.Path(get_test_file("sample_asos.csv")) result = asos.parse_file(datpath) expected = ( pandas.read_csv(csvpath, parse_dates=True, index_col=["datetime"]) .resample("5min") .asfreq() ) pdtest.assert_frame_equal( result.fillna(-9999).sort_index(axis="columns"), expected.fillna(-9999).sort_index(axis="columns"), )
def test_NCDCtoCSV(): inputfile = get_test_file("sample_NCDC_data.NCD") knownfile = get_test_file("known_CSV_from_NCDC.csv") with tempfile.TemporaryDirectory() as datadir: outfile = os.path.join(datadir, "test_out.dat") exporters.NCDCtoCSV(inputfile, outfile) with open(knownfile, "r") as f: known_data = f.read() with open(outfile, "r") as f: test_data = f.read() assert known_data == test_data
def test_dumpNCDCFormat(fivemin): knownfile = get_test_file("known_hourly_NCDC.dat") with tempfile.TemporaryDirectory() as datadir: outfile = os.path.join(datadir, "test_dumpNCDC.dat") exporters.NCDCFormat( fivemin.resample("1H").sum(), "041685", "California", col="precip", filename=outfile, ) with open(knownfile, "r") as f: known_data = f.read() with open(outfile, "r") as f: test_data = f.read() assert known_data == test_data
def test_dumpSWMM5Format_results(fivemin, freq, expected_file): if freq == "hourly": data = fivemin.resample("1H").sum() else: data = fivemin with tempfile.TemporaryDirectory() as datadir: outfile = os.path.join(datadir, "test_dumpSWMM.dat") data = exporters.SWMM5Format( data, "Test-Station", col="precip", freq=freq, dropzeros=True, filename=outfile, ) pdtest.assert_frame_equal( data.reset_index(drop=True), pandas.read_table(get_test_file(expected_file), sep="\t"), )
def test_parse_file(expected_hydra): filepath = Path(get_test_file("sample_hydra.txt")) result = hydra.parse_file(filepath) pdtest.assert_frame_equal(expected_hydra, result)
def test_file_status(filename, expected): fn = get_test_file(filename) validate.file_status(fn) == expected
def sample_data(): fname = get_test_file("sample_ncdc_data.csv") return pandas.read_csv(fname, parse_dates=["date"])
def fivemin(): return pandas.read_csv(get_test_file("data_for_tests.csv"), parse_dates=True, index_col=0)
def test_data(): csvfile = get_test_file("data_for_viz_tests.csv") df = pandas.read_csv(csvfile, parse_dates=True, index_col=0) return df