def test_extract_fields_match_lineno_toosmall(): lines = [(1, 'c1 c2 c3'), (2, '1 2 3')] expected_result = [] result = list(wcut.extract_fields(lines, ' ', ['c1'], match_lineno=0)) assert result == expected_result
def test_extract_fields_no_matches_preheader_wronglineno(): lines = [(1, 'preheader'), (2, 'c1 c2 c3'), (3, '1 2 3')] expected_result = [['preheader']] with pytest.raises(wcut._core.WcutError): result = list(wcut.extract_fields(lines, ' ', ['c1'], match_lineno=1))
def test_extract_fields_no_matches(): lines = [(1, 'c1 c2 c3'), (2, '1 2 3')] expected_result = [] result = list(wcut.extract_fields(lines, ' ', ['notmatched'])) assert result == expected_result
def test_extract_fields_match_in_reverse_order(): lines = [(1, 'c1 c2 c3'), (2, '1 2 3')] expected_result = [['c2', 'c1'], ['2', '1']] result = list(wcut.extract_fields(lines, ' ', ['c2', 'c1'])) assert result == expected_result
def test_extract_fields_lines_ends_with_blank_line(): lines = [(1, 'c1 c2 c3'), (2, '\n')] expected_result = [['c1', 'c2'], ['\n']] result = list(wcut.extract_fields(lines, ' ', ['c1', 'c2'])) assert result == expected_result
def test_extract_fields_match_lineno_toobig(): lines = [(1, 'c1 c2 c3'), (2, '1 2 3')] ## Treated as preheader. expected_result = [[i[1]] for i in lines] result = list(wcut.extract_fields(lines, ' ', ['c1'], match_lineno=3)) assert result == expected_result
def test_extract_fields_no_matches_preheader(): lines = [(1, 'preheader'), (2, 'c1 c2 c3'), (3, '1 2 3')] expected_result = [['preheader']] result = list(wcut.extract_fields(lines, ' ', ['notmatched'], match_lineno=2)) assert result == expected_result
def test_extract_fields_match_second_line_match(): lines = [(1, 'not considered'), (2, 'matched nomatch'), (3, '1 2')] expected_result = [['not considered'], ['matched',], ['1',]] result = list(wcut.extract_fields(lines, ' ', ['matched',], match_lineno=2)) assert result == expected_result
def test_extract_fields_delims(delim): expected = [['c1', 'c2', 'c3'], ['1', '2', '3']] lines = [(lineno, delim.join(line)) for lineno, line in enumerate(expected, 1)] result = list(wcut.extract_fields(lines, delim, ['c1', 'c2', 'c3'])) assert result == expected