コード例 #1
0
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']])
コード例 #2
0
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)
コード例 #3
0
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)
コード例 #4
0
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']])
コード例 #5
0
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']])
コード例 #6
0
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']])
コード例 #7
0
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']])
コード例 #8
0
def test_reads_empty_file_gracefully():
    assert readcol(
        filename=os.path.join(abs_path, 'test_files/empty.txt')) == ([], [])
コード例 #9
0
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']])
コード例 #10
0
def test_exits_gracefully_if_no_file():
    assert readcol(
        filename=os.path.join(abs_path, 'test_files/noexistence.txt')) == ([],
                                                                           [])
コード例 #11
0
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']])