Exemple #1
0
def test_pipeline_add_and_run_multiple_steps():
    class TestStep1(AbstractStep):
        def run(self, ctrl, log, acc):
            pass

    class TestStep2(AbstractStep):
        def run(self, ctrl, log, acc):
            raise Success

    pipeline = Pipeline({})
    pipeline.add_steps([TestStep1('Test Step 1'), TestStep2('Test Step 2')])

    with pytest.raises(Success):
        pipeline.run()
Exemple #2
0
def test_extract():
    source_iter: Callable[[List[str]],
                          Iterator[IO[AnyStr]]] = lambda file_paths: MakeIter(
                              mock_file_gen)(file_paths)
    mock_output_handler = Mock()
    output_handler: Callable[[str, Dict[str, Any]], None] = mock_output_handler
    pipeline = Pipeline(CONTROL_DATA)
    pipeline.add_steps([
        ExtractStep('Extract text',
                    'files',
                    source_iter=source_iter,
                    output_handler=output_handler)
    ])
    pipeline.run()
    call_args = mock_output_handler.call_args[0]
    content = call_args[1]

    # noinspection SpellCheckingInspection
    assert content['metadata']['doc_type'] == 'CHANNEL_ANSWERFLOW_STEPS'
    assert content['data']['reference_table']['structured_content'][0][
        'type'] == 'heading'
    assert content['data']['reference_table']['structured_content'][0][
        'text'] == 'My Heading'
    assert content['data']['reference_table']['text'][1] == 'First line'