def test_cell_location_offset_to(): c1 = exco.CellLocation('SHEET1', 'A1') c2 = exco.CellLocation('SHEET1', 'C9') offset = c1.offset_to(c2) assert offset == CellOffset(8, 2) c3 = c1.shift(offset) assert c3 == c2
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'