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'
Ejemplo n.º 6
0
 def create_table_extraction_task(
         self, spec: TableExtractionSpec) -> TableExtractionTask:
     columns = {
         k: self.create_extraction_task(CellExtractionSpec(v))
         for k, v in spec.columns.items()
     }
     try:
         return TableExtractionTask(
             key=spec.key,
             locator=self.locator_factory.create_from_spec(
                 spec=spec.locator),
             columns=columns,
             end_condition=EndConditionCollection.from_spec(
                 spec.end_conditions,
                 factory=self.table_end_condition_factory),
             item_direction=spec.item_direction)
     except ExcoException as e:
         raise TableExtractionTaskCreationException(
             f'Unable to create TableExtractionTask for {spec.key} cf\n {spec.source.describe()}'
         ) from e