Exemplo n.º 1
0
def test_file_reader(tmpdir):
    fs, filename, services = txt_tester.get_services_for_reader(tmpdir)

    with BufferingNodeExecutionContext(FileReader(path=filename),
                                       services=services) as context:
        context.write_sync(EMPTY)

    output = context.get_buffer()
    assert len(output) == 2
    assert output[0] == ('Hello', )
    assert output[1] == ('World', )
Exemplo n.º 2
0
def test_file_reader(tmpdir):
    fs, filename, services = txt_tester.get_services_for_reader(tmpdir)

    with CapturingNodeExecutionContext(FileReader(path=filename), services=services) as context:
        context.write(BEGIN, Bag(), END)
        context.step()

    assert len(context.send.mock_calls) == 2

    args0, kwargs0 = context.send.call_args_list[0]
    assert len(args0) == 1 and not len(kwargs0)
    args1, kwargs1 = context.send.call_args_list[1]
    assert len(args1) == 1 and not len(kwargs1)

    assert args0[0].args[0] == 'Hello'
    assert args1[0].args[0] == 'World'
Exemplo n.º 3
0
def test_file_reader_in_context(tmpdir):
    file = tmpdir.join('input.txt')
    file.write('Hello\nWorld\n')

    reader = FileReader(path=str(file))
    context = CapturingNodeExecutionContext(reader, None)

    context.start()
    context.recv(BEGIN, Bag(), END)
    context.step()
    context.stop()

    assert len(context.send.mock_calls) == 2

    args0, kwargs0 = context.send.call_args_list[0]
    assert len(args0) == 1 and not len(kwargs0)
    args1, kwargs1 = context.send.call_args_list[1]
    assert len(args1) == 1 and not len(kwargs1)

    assert args0[0].args[0] == 'Hello'
    assert args1[0].args[0] == 'World'
Exemplo n.º 4
0
def test_file_reader_in_context(tmpdir):
    fs, filename = open_fs(tmpdir), 'input.txt'

    fs.open(filename, 'w').write('Hello\nWorld\n')

    reader = FileReader(path=filename)
    context = CapturingNodeExecutionContext(reader, services={'fs': fs})

    context.start()
    context.recv(BEGIN, Bag(), END)
    context.step()
    context.stop()

    assert len(context.send.mock_calls) == 2

    args0, kwargs0 = context.send.call_args_list[0]
    assert len(args0) == 1 and not len(kwargs0)
    args1, kwargs1 = context.send.call_args_list[1]
    assert len(args1) == 1 and not len(kwargs1)

    assert args0[0].args[0] == 'Hello'
    assert args1[0].args[0] == 'World'
Exemplo n.º 5
0
Arquivo: text.py Projeto: niejn/bonobo
from bonobo import FileReader, Graph, get_examples_path


def skip_comments(line):
    if not line.startswith('#'):
        yield line


graph = Graph(
    FileReader(path=get_examples_path('datasets/passwd.txt')),
    skip_comments,
    lambda s: s.split(':'),
    lambda l: l[0],
    print,
)

if __name__ == '__main__':
    import bonobo

    bonobo.run(graph)