def test_tdiv_to_list_simple(): table = bs(tables.flat, 'html.parser') table_list = t.tdiv_to_table_list(table) expected_table_list = [ ['<td>1</td>', '<td>2</td>', '<td>3</td>', '<td>4</td>'], ['<td>1</td>', '<td>2</td>', '<td>3</td>', '<td>4</td>'], ['<td>1</td>', '<td>2</td>', '<td>3</td>', '<td>4</td>'] ] assert t.stringify_table(table_list) == expected_table_list
def test_expand_both(): table = bs(tables.bothspan, 'html.parser') table_list = t.expand_spans(t.tdiv_to_table_list(table)) expected_table_list = [ [ '<td colspan="1" rowspan="1"><a href="somelink">1</a></td>', 'None', 'None', '<td>4</td>' ], [ '<td colspan="1" rowspan="1"><a href="somelink">1</a></td>', 'None', 'None', '<td>4</td>' ], ['<td>1</td>', '<td>2</td>', '<td>3</td>', '<td>4</td>'] ] assert t.stringify_table(table_list) == expected_table_list
def test_expand_colspan(): colspan_table = parsed_html_table(tables.colspan) expanded_table = t.stringify_table(t.expand_spans(colspan_table)) expected_table = [ [ '<td colspan="1"><a href="somelink">1</a></td>', 'None', 'None', '<td>4</td>' ], ['<td>1</td>', '<td>2</td>', '<td>3</td>', '<td>4</td>'], [ '<td colspan="1"><a href="somelink">1</a></td>', 'None', 'None', '<td>4</td>' ], ['<td>1</td>', '<td>2</td>', '<td>3</td>', '<td>4</td>'], ] assert expanded_table == expected_table
def test_tdiv_to_list_with_cell_content(): table = bs(tables.with_links, 'html.parser') table_list = t.tdiv_to_table_list(table) expected_table_list = [[ '<td><a href="somelink">1</a></td>', '<td>2</td>', '<td>3</td>', '<td>4</td>' ], [ '<td><a href="somelink">1</a></td>', '<td>2</td>', '<td>3</td>', '<td>4</td>' ], [ '<td><a href="somelink">1</a></td>', '<td>2</td>', '<td>3</td>', '<td>4</td>' ]] assert t.stringify_table(table_list) == expected_table_list