def test_extract_rightward_table(rightward_table_wb, cell_loc): tt = TableExtractionTask( key="some_table", locator=AtCommentCellLocator(), columns={ CellOffset(row=0, col=0): CellExtractionTask.simple(key='some_key', parser=StringParser()) }, end_condition=EndConditionCollection([AllBlankTableEndCondition()]), item_direction=TableItemDirection.RIGHTWARD) result = tt.process(cell_loc, rightward_table_wb) assert len(result.row_results) == 10
def test_table_extraction_fail_locating(workbook, cell_loc): tt = TableExtractionTask(key="some_table", locator=RightOfLocator(label='Non Existent'), columns={ CellOffset(0, 0): CellExtractionTask.simple( key='some_key', parser=StringParser()) }, end_condition=EndConditionCollection.default(), item_direction=TableItemDirection.DOWNWARD) result = tt.process(cell_loc, workbook) assert not result.locating_result.is_ok
def test_table_extraction_task_hit_infinite_loop_guard(workbook, cell_loc): tt = TableExtractionTask(key="some_table", locator=AtCommentCellLocator(), columns={ CellOffset(row=0, col=0): CellExtractionTask.simple( key='some_key', parser=StringParser()) }, end_condition=EndConditionCollection([]), item_direction=TableItemDirection.DOWNWARD) with pytest.raises(TooManyRowRead): tt.process(cell_loc, workbook)
def test_table_extraction_task(workbook, cell_loc): tt = TableExtractionTask( key="some_table", locator=AtCommentCellLocator(), columns={ CellOffset(row=0, col=0): CellExtractionTask.simple(key='some_key', parser=StringParser()) }, end_condition=EndConditionCollection([MaxRowTableEndCondition(n=3)]), item_direction=TableItemDirection.DOWNWARD) result = tt.process(cell_loc, workbook) assert len(result.row_results) == 3
def test_shift_cell_rightward(cell_loc): tt = TableExtractionTask(key="some_table", locator=AtCommentCellLocator(), columns={ CellOffset(0, 0): CellExtractionTask.simple( key='some_key', parser=StringParser()) }, end_condition=EndConditionCollection.default(), item_direction=TableItemDirection.RIGHTWARD) cl = CellLocation(sheet_name='Sheet', coordinate='A1') assert tt.shift_column_direction(cl, 1).coordinate == 'A2' assert tt.shift_item_direction(cl, 1).coordinate == 'B1'
def test_string_parser_simple(): sp = StringParser() assert sp.parse_value('hello') == 'hello'
def test_string_parser_should_return_empty_string_on_empty_cell(): sp = StringParser() assert sp.parse_value(None) == ''
def test_parser_parse_str(): assert StringParser().parse_value('a') == str('a')