Big refactoring, way simpler management of transformations. Early branch for upcoming version 0.2.

This commit is contained in:
Romain Dorgueil
2017-01-17 22:45:10 +01:00
parent b6e84c66e3
commit 8532520aae
41 changed files with 627 additions and 433 deletions

View File

@ -1,6 +1,5 @@
from bonobo import Graph, NaiveStrategy, Bag
from bonobo.core.contexts import ExecutionContext
from bonobo.util.lifecycle import with_context
from bonobo import Graph, NaiveStrategy, Bag, contextual
from bonobo.context.execution import GraphExecutionContext
from bonobo.util.tokens import BEGIN, END
@ -12,11 +11,16 @@ def square(i: int) -> int:
return i**2
@with_context
def push_result(ctx, i: int):
if not hasattr(ctx.parent, 'results'):
ctx.parent.results = []
ctx.parent.results.append(i)
@contextual
def push_result(results, i: int):
results.append(i)
@push_result.__processors__.append
def results(f, context):
results = []
yield results
context.parent.results = results
chain = (generate_integers, square, push_result)
@ -25,8 +29,8 @@ chain = (generate_integers, square, push_result)
def test_empty_execution_context():
graph = Graph()
ctx = ExecutionContext(graph)
assert not len(ctx.components)
ctx = GraphExecutionContext(graph)
assert not len(ctx.nodes)
assert not len(ctx.plugins)
assert not ctx.alive
@ -46,15 +50,19 @@ def test_simple_execution_context():
graph = Graph()
graph.add_chain(*chain)
ctx = ExecutionContext(graph)
assert len(ctx.components) == len(chain)
ctx = GraphExecutionContext(graph)
assert len(ctx.nodes) == len(chain)
assert not len(ctx.plugins)
for i, component in enumerate(chain):
assert ctx[i].component is component
for i, node in enumerate(chain):
assert ctx[i].wrapped is node
assert not ctx.alive
ctx.recv(BEGIN, Bag(), END)
assert not ctx.alive
ctx.start()
assert ctx.alive

View File

@ -24,20 +24,20 @@ def test_graph_outputs_of():
def test_graph_add_component():
g = Graph()
assert len(g.components) == 0
assert len(g.nodes) == 0
g.add_component(identity)
assert len(g.components) == 1
g.add_node(identity)
assert len(g.nodes) == 1
g.add_component(identity)
assert len(g.components) == 2
g.add_node(identity)
assert len(g.nodes) == 2
def test_graph_add_chain():
g = Graph()
assert len(g.components) == 0
assert len(g.nodes) == 0
g.add_chain(identity, identity, identity)
assert len(g.components) == 3
assert len(g.nodes) == 3
assert len(g.outputs_of(BEGIN)) == 1

View File

@ -1,8 +1,8 @@
from bonobo.core.stats import WithStatistics
from bonobo.core.statistics import WithStatistics
class MyThingWithStats(WithStatistics):
def get_stats(self, *args, **kwargs):
def get_statistics(self, *args, **kwargs):
return (
('foo', 42),
('bar', 69),
@ -11,4 +11,4 @@ class MyThingWithStats(WithStatistics):
def test_with_statistics():
o = MyThingWithStats()
assert o.get_stats_as_string() == 'foo=42 bar=69'
assert o.get_statistics_as_string() == 'foo=42 bar=69'