Ejemplo n.º 1
0
def test_file_writer_in_context(tmpdir, lines, output):
    fs, filename, services = txt_tester.get_services_for_writer(tmpdir)

    with NodeExecutionContext(FileWriter(path=filename),
                              services=services) as context:
        context.write_sync(*lines)

    with fs.open(filename) as fp:
        assert fp.read() == output
Ejemplo n.º 2
0
def test_node_lifecycle_with_kill():
    func = MagicMock(spec=object())

    ctx = NodeExecutionContext(func)
    assert not any((ctx.started, ctx.stopped, ctx.killed, ctx.alive))

    # cannot kill before start
    with pytest.raises(RuntimeError):
        ctx.kill()
    assert not any((ctx.started, ctx.stopped, ctx.killed, ctx.alive))

    # turn the key
    ctx.start()
    assert all((ctx.started, ctx.alive)) and not any((ctx.stopped, ctx.killed))

    ctx.kill()
    assert all((ctx.started, ctx.killed, ctx.alive)) and not ctx.stopped

    ctx.stop()
    assert all((ctx.started, ctx.killed, ctx.stopped)) and not ctx.alive
Ejemplo n.º 3
0
def test_write_pickled_dict_to_file(tmpdir):
    fs, filename, services = pickle_tester.get_services_for_writer(tmpdir)

    with NodeExecutionContext(PickleWriter(filename),
                              services=services) as context:
        context.write_sync({'foo': 'bar'}, {'foo': 'baz', 'ignore': 'this'})

    with fs.open(filename, 'rb') as fp:
        assert pickle.loads(fp.read()) == {'foo': 'bar'}

    with pytest.raises(AttributeError):
        getattr(context, 'file')
Ejemplo n.º 4
0
def test_write_pickled_dict_to_file(tmpdir):
    fs, filename, services = pickle_tester.get_services_for_writer(tmpdir)

    with NodeExecutionContext(PickleWriter(filename),
                              services=services) as context:
        context.write_sync({"foo": "bar"}, {"foo": "baz", "ignore": "this"})

    with fs.open(filename, "rb") as fp:
        assert pickle.loads(fp.read()) == {"foo": "bar"}

    with pytest.raises(AttributeError):
        getattr(context, "file")
Ejemplo n.º 5
0
def test_node_lifecycle_with_kill():
    func = MagicMock(spec=object())

    ctx = NodeExecutionContext(func)
    assert not any((ctx.started, ctx.stopped, ctx.killed, ctx.alive))

    # cannot kill before start
    with pytest.raises(RuntimeError):
        ctx.kill()
    assert not any((ctx.started, ctx.stopped, ctx.killed, ctx.alive))

    # turn the key
    ctx.start()
    assert all((ctx.started, ctx.alive)) and not any((ctx.stopped, ctx.killed))

    ctx.kill()
    assert all((ctx.started, ctx.killed, ctx.alive)) and not ctx.stopped

    ctx.stop()
    assert all((ctx.started, ctx.killed, ctx.stopped)) and not ctx.alive
Ejemplo n.º 6
0
 def __init__(self, *args, buffer=None, **kwargs):
     BufferingContext.__init__(self, buffer)
     NodeExecutionContext.__init__(self,
                                   *args,
                                   **kwargs,
                                   _outputs=[self.buffer])
Ejemplo n.º 7
0
 def __init__(self, *args, buffer=None, **kwargs):
     BufferingContext.__init__(self, buffer)
     NodeExecutionContext.__init__(self, *args, **kwargs, _outputs=[self.buffer])