예제 #1
0
def test_get_output_file_path():
    t = BaseTransform()
    t.output_name = 'output.csv'
    assert os.path.join(
        '/test/path',
        'output.csv') == t.get_output_file_path('/test/path/input.csv')
    assert os.path.join('~/Desktop', 'output.csv') == t.get_output_file_path()
예제 #2
0
def test_get_header_indices():
    t = BaseTransform()
    t.headers = ['A', 'B']
    idx = t.get_header_indices(['A', 'B', 'C'])
    assert 0 == idx['A']
    assert 1 == idx['B']
    assert idx['C'] is None
예제 #3
0
def test_constructors():
    assert BaseTransform() is not None
    assert ColumnMod() is not None
    assert FixedWidthTransform((1, )) is not None
    assert SingleLineFixedWidthTransform((1, )) is not None

    result = BaseResult()
    t = BaseTransform(result)
    assert result == t.result
예제 #4
0
def test_process_input_data():
    t = BaseTransform()
    t.input_validate_func = lambda i, r: (i % 2 == 0, r)
    data = t._process_input_data([
        ['A', 'B'],
        [1, 2],
        [3, 4],
        [5, 6],
        [7, 8],
    ])
    assert [['A', 'B'], [3, 4], [7, 8]] == data
예제 #5
0
def test_apply_column_mods():
    t = BaseTransform()
    assert [['1', '2', '3']] == t._apply_column_mods([['1', '2', '3']])
    t.column_mods[0] = ColumnMod(prefix='A: ')
    t.column_mods[1] = ColumnMod(suffix=' (B)')
    t.column_mods[2] = ColumnMod(func=lambda s: s * 3)
    t.column_mods[3] = ColumnMod(prefix='Extra: ')
    assert [['A: 1', '2 (B)', '333']] == t._apply_column_mods([['1', '2',
                                                                '3']])
예제 #6
0
def test_parse_headers6():
    t = BaseTransform()
    t.header_map = {'A': 'FIRST NAME', 'B': 'LAST NAME'}
    t.headers = ['A', 'B', 'ADDRESS']
    t.valid_headers = ['FIRST NAME', 'LAST NAME', 'SKIP']
    t.default_not_found = 'SKIP'
    assert ['FIRST NAME', 'LAST NAME', 'SKIP'] == t.parse_headers()
예제 #7
0
def test_parse_headers7():
    t = BaseTransform()
    t.header_map = {'A': 'FIRST NAME', 'Column B': 'LAST NAME', 'C': 'NOTES'}
    t.headers = ['A', 'Column  B', 'C']
    t.valid_headers = ['FIRST NAME', 'LAST NAME', 'NOTES']
    t.prefixable_headers.append('NOTES')
    assert ['FIRST NAME', 'LAST NAME', 'NOTES'] == t.parse_headers()
    assert t.column_mods[2].prefix == 'C: '
예제 #8
0
def basic_transform(generated_headers_map):
    t = BaseTransform()
    t.has_headers = True
    t.headers_file_path = generated_headers_map
    return t
예제 #9
0
def test_try_header_variations4():
    t = BaseTransform()
    t.header_map = {'NAME': 'FULL_NAME', 'AME': 'OTHER'}
    assert (True,
            'FULL_NAME') == t.try_header_variations('Full Name', t.header_map,
                                                    ['FULL_NAME'])
예제 #10
0
def test_try_header_variations3():
    t = BaseTransform()
    t.header_map = {'COLUMN A': 'NAME'}
    t._generate_variations = lambda s: [s, 'COLUMN ' + s]
    assert (True, 'NAME') == t.try_header_variations('a', t.header_map,
                                                     ['NAME'])
예제 #11
0
def test_try_header_variations2():
    t = BaseTransform()
    header_map = {'A': 'NAME'}
    assert (True, 'NAME') == t.try_header_variations('name', header_map,
                                                     ['NAME'])
예제 #12
0
def test_remove_token_from_headers_map():
    t = BaseTransform()
    header_map = {'A': '1'}
    t.remove_token_from_headers_map(header_map, '1')
    assert 'A' not in header_map
예제 #13
0
def test_contains_headers():
    t = BaseTransform()
    t.headers = ['A', 'B']
    assert t.contains_headers(['A'])
    assert t.contains_headers(['B', 'A'])
    assert not t.contains_headers(['B', 'C'])
예제 #14
0
def test_parse_headers5():
    t = BaseTransform()
    t.header_map = {'A': 'FIRST NAME', 'B': 'LAST NAME'}
    t.headers = ['A', 'B', 'ADDRESS']
    t.valid_headers = ['FIRST NAME', 'LAST NAME', 'ADDRESS']
    assert ['FIRST NAME', 'LAST NAME', 'ADDRESS'] == t.parse_headers()
예제 #15
0
def test_parse_headers4():
    t = BaseTransform()
    t.header_map = {'A': 'NAME', 'B': 'ADDRESS'}
    t.headers = [None, 'B']
    assert ['', 'ADDRESS'] == t.parse_headers()
예제 #16
0
def test_parse_headers3():
    t = BaseTransform()
    t.header_map = {'A': 'NAME', 'B': 'ADDRESS'}
    assert t.parse_headers() is None
예제 #17
0
def test_parse_headers2():
    t = BaseTransform()
    t.headers = ['A', 'B']
    assert ['A', 'B'] == t.parse_headers()
예제 #18
0
def test_remove_token_from_headers_map2():
    t = BaseTransform()
    t.enumerable_headers.append('ENUM_')
    header_map = {'A': 'ENUM_'}
    t.remove_token_from_headers_map(header_map, 'ENUM_')
    assert 'A' in header_map
예제 #19
0
def test_get_header_idx():
    t = BaseTransform()
    t.headers = ['A', 'B']
    assert 0 == t.get_header_idx('A')
    assert 1 == t.get_header_idx('B')
    assert -1 == t.get_header_idx('C')
예제 #20
0
def test_try_header_variations1():
    t = BaseTransform()
    t.header_map = {'0123456789': 'NAME'}
    assert (False, 'A') == t.try_header_variations('A', t.header_map, ['NAME'])
    assert (True, 'NAME') == t.try_header_variations('1123456789',
                                                     t.header_map, ['NAME'])