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()
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
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
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
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']])
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()
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: '
def basic_transform(generated_headers_map): t = BaseTransform() t.has_headers = True t.headers_file_path = generated_headers_map return t
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'])
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'])
def test_try_header_variations2(): t = BaseTransform() header_map = {'A': 'NAME'} assert (True, 'NAME') == t.try_header_variations('name', header_map, ['NAME'])
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
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'])
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()
def test_parse_headers4(): t = BaseTransform() t.header_map = {'A': 'NAME', 'B': 'ADDRESS'} t.headers = [None, 'B'] assert ['', 'ADDRESS'] == t.parse_headers()
def test_parse_headers3(): t = BaseTransform() t.header_map = {'A': 'NAME', 'B': 'ADDRESS'} assert t.parse_headers() is None
def test_parse_headers2(): t = BaseTransform() t.headers = ['A', 'B'] assert ['A', 'B'] == t.parse_headers()
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
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')
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'])