def test_pdwrire_cols(tmpdir): """Test writer that can take variable column numbers.""" tmpfile = tmpdir.join("pd_multicol_test.dat") pd_multicol_name = str(tmpfile) data1 = range(5) data2 = range(5, 10) # 0 means successful write assert 0 == io.pdwrite_cols(pd_multicol_name, data1, data2, data1) assert 0 == io.pdwrite_cols(pd_multicol_name, data1) assert 0 == io.pdwrite_cols( pd_multicol_name, data1, data2, data1, data2, header=["headers", "for", "column", "labels"], ) assert 0 == io.pdwrite_cols(pd_multicol_name, data1, data2, sep=",", index=True) # clean-up utils.silent_remove(pd_multicol_name)
def test_pdwriter(): """Check pd_writer same write_col with with exponential flag.""" filedir = "data/test_data/obsolete/" data = np.random.randn(3, 100) * 1e7 pd2col_name = filedir + "pd2col_test.dat" pd3col_name = filedir + "pd3col_test.dat" twocol_name = filedir + "2col_test.dat" threecol_name = filedir + "3col_test.dat" # write files io.pdwrite_2col(pd2col_name, data[0], data[1]) io.pdwrite_3col(pd3col_name, data[0], data[1], data[2]) eniric.obsolete.IOmodule.write_e_2col(twocol_name, data[0], data[1]) eniric.obsolete.IOmodule.write_e_3col(threecol_name, data[0], data[1], data[2]) # re-read files a = io.pdread_2col(pd2col_name) b = io.pdread_2col(twocol_name) c = io.pdread_3col(pd3col_name) d = io.pdread_3col(threecol_name) # check results the same assert np.allclose(a[0], b[0]) assert np.allclose(a[1], b[1]) assert np.allclose(c[0], d[0]) assert np.allclose(c[1], d[1]) assert np.allclose(c[2], d[2]) # clean-up utils.silent_remove(pd2col_name) utils.silent_remove(pd3col_name) utils.silent_remove(twocol_name) utils.silent_remove(threecol_name)
def test_write_read_2col(tmpdir): """Check pd_writer same write_col with with exponential flag.""" data = np.random.randn(2, 100) * 1e7 tmp_file = tmpdir.join("file_col2.dat") tmp_file_name = str(tmp_file) # write files io.pdwrite_2col(tmp_file_name, data[0], data[1]) # re-read files a = io.pdread_2col(tmp_file_name) # check results the same assert np.allclose(a[0], data[0]) assert np.allclose(a[1], data[1]) # clean-up utils.silent_remove(tmp_file_name)
def test_pdwrire_cols(): """Test writer that can take variable column numbers.""" filedir = "data/test_data" pd_multicol_name = os.path.join(filedir, "pd_multicol_test.dat") data1 = range(5) data2 = range(5, 10) bad_data = range(6) # Different length # 0 means successful write assert 0 == io.pdwrite_cols(pd_multicol_name, data1, data2, data1) assert 0 == io.pdwrite_cols(pd_multicol_name, data1) assert 0 == io.pdwrite_cols( pd_multicol_name, data1, data2, data1, data2, header=["headers", "for", "column", "labels"], ) assert 0 == io.pdwrite_cols(pd_multicol_name, data1, data2, sep=",", index=True) # test uneven data lengths with pytest.raises(ValueError): io.pdwrite_cols(pd_multicol_name, data1, data2, bad_data) # test bad header with pytest.raises(ValueError): io.pdwrite_cols(pd_multicol_name, data1, data2, bad_data, header=["too", "many", "values"]) with pytest.raises(TypeError): io.pdwrite_cols(pd_multicol_name, data1, bad="keyword") # clean-up utils.silent_remove(pd_multicol_name)
def test_silent_remove(): """Test this doesn't raise and issue. Not really a good test.""" utils.silent_remove("a_fake_filename_that_doesnt_exist.fake") assert True