|
| 1 | +import pytest |
| 2 | + |
| 3 | +from unstructured.metrics.table.table_formats import SimpleTableCell |
| 4 | + |
| 5 | + |
| 6 | +@pytest.mark.parametrize( |
| 7 | + ("row_nums", "column_nums", "x", "y", "w", "h"), |
| 8 | + [ |
| 9 | + ([3, 2, 1], [6, 7], 6, 1, 2, 3), |
| 10 | + ([2], [6, 7], 6, 2, 2, 1), |
| 11 | + ([1, 2, 3], [20], 20, 1, 1, 3), |
| 12 | + ([5], [5], 5, 5, 1, 1), |
| 13 | + ], |
| 14 | +) |
| 15 | +def test_simple_table_cell_parsing_from_table_transformer_when_expected_input( |
| 16 | + row_nums, column_nums, x, y, w, h |
| 17 | +): |
| 18 | + table_transformer_cell = {"row_nums": row_nums, "column_nums": column_nums, "cell text": "text"} |
| 19 | + transformed_cell = SimpleTableCell.from_table_transformer_cell(table_transformer_cell) |
| 20 | + expected_cell = SimpleTableCell(x=x, y=y, w=w, h=h, content="text") |
| 21 | + assert expected_cell == transformed_cell |
| 22 | + |
| 23 | + |
| 24 | +def test_simple_table_cell_parsing_from_table_transformer_when_missing_row_nums(): |
| 25 | + cell = {"row_nums": [], "column_nums": [1], "cell text": "text"} |
| 26 | + with pytest.raises(ValueError, match='has missing values under "row_nums" key'): |
| 27 | + SimpleTableCell.from_table_transformer_cell(cell) |
| 28 | + |
| 29 | + |
| 30 | +def test_simple_table_cell_parsing_from_table_transformer_when_missing_column_nums(): |
| 31 | + cell = {"row_nums": [1], "column_nums": [], "cell text": "text"} |
| 32 | + with pytest.raises(ValueError, match='has missing values under "column_nums" key'): |
| 33 | + SimpleTableCell.from_table_transformer_cell(cell) |
0 commit comments