def test_skips_custom_comment_lines(): assert readcol(filename=os.path.join(abs_path, 'test_files/comments_custom.txt'), comment='%') == ([], []) assert readcol(filename=os.path.join(abs_path, 'test_files/comments_custom2.txt'), comment='%') == (['x', 'y'], [['1', '2', '3'], ['.1', '.2', '.3']])
def test_writes_nominal_file(): """ If this test does not work, all remaining tests will fail because rely on generation of a nominal file. """ filename = 'nominal_write.txt' writecol(filename=filename, data=[['1', '2', '3', '4'], ['.1', '.2', '.3', '.4']], header=['x', 'y']) assert readcol(filename=filename) == (['x', 'y'], [['1', '2', '3', '4'], ['.1', '.2', '.3', '.4']]) os.remove(filename)
def test_does_overwrite_file_if_overwrite_True(): """ writer = 'w' """ filename = 'test_writer_overwrite_true.txt' writecol(filename=filename, data=[['1', '2', '3', '4'], ['.1', '.2', '.3', '.4']], header=['x', 'y']) with capture_output() as c: writecol(filename=filename, data=[['5', '6'], ['.5', '.6']], header=['x', 'y'], writer='w', overwrite=True) c() out = c.stdout assert out.split('\n')[0] == "File '{}' already exists but overwriting/appending with '{}'..."\ .format(filename, 'w') assert readcol(filename=filename) == (['x', 'y'], [['5', '6'], ['.5', '.6']]) os.remove(filename)
def test_can_read_no_header(): assert readcol(filename=os.path.join(abs_path, 'test_files/noheader.txt'), headerstart=0, datastart=0) == (['0', '1'], [['1', '2', '3', '4'], ['.1', '.2', '.3', '.4']])
def test_can_read_single_column_file(): assert readcol( filename=os.path.join(abs_path, 'test_files/single_col.txt')) == ([ 'x' ], [['1', '2', '3', '4']])
def test_can_read_custom_deliminator(): assert readcol(filename=os.path.join(abs_path, 'test_files/custom_deliminator.txt'), deliminator="|") == (['x', 'y'], [['1', '2', '3', '4'], ['.1', '.2', '.3', '.4']])
def test_can_mix_space_and_tab(): assert readcol( filename=os.path.join(abs_path, 'test_files/mixed_space_tab.txt')) == ( ['x', 'y'], [['1', '2', '3', '4'], ['.1', '.2', '.3', '.4']])
def test_reads_empty_file_gracefully(): assert readcol( filename=os.path.join(abs_path, 'test_files/empty.txt')) == ([], [])
def test_finds_header_and_data_if_not_default(): assert readcol(filename=os.path.join(abs_path, 'test_files/nondefault_start.txt'), headerstart=4, datastart=6) == (['x', 'y'], [['1', '2', '3', '4'], ['.1', '.2', '.3', '.4']])
def test_exits_gracefully_if_no_file(): assert readcol( filename=os.path.join(abs_path, 'test_files/noexistence.txt')) == ([], [])
def test_reads_nominal_file(): assert readcol( filename=os.path.join(abs_path, 'test_files/nominal.txt')) == ([ 'x', 'y' ], [['1', '2', '3', '4'], ['.1', '.2', '.3', '.4']])