Attempt to refactor a bit of context, new count transform that counts the calls, new bonobo.structs package with basic data structures, removal of blessings.

This commit is contained in:
Romain Dorgueil
2017-04-24 23:44:29 +02:00
parent cff32c1612
commit ef2c881075
37 changed files with 405 additions and 145 deletions

View File

@ -1,64 +0,0 @@
from mock import Mock
from bonobo import Bag
from bonobo.core.bags import INHERIT_INPUT
args = ('foo', 'bar', )
kwargs = dict(acme='corp')
def test_basic():
my_callable1 = Mock()
my_callable2 = Mock()
bag = Bag(*args, **kwargs)
assert not my_callable1.called
result1 = bag.apply(my_callable1)
assert my_callable1.called and result1 is my_callable1.return_value
assert not my_callable2.called
result2 = bag.apply(my_callable2)
assert my_callable2.called and result2 is my_callable2.return_value
assert result1 is not result2
my_callable1.assert_called_once_with(*args, **kwargs)
my_callable2.assert_called_once_with(*args, **kwargs)
def test_inherit():
bag = Bag('a', a=1)
bag2 = Bag.inherit('b', b=2, _parent=bag)
bag3 = bag.extend('c', c=3)
bag4 = Bag('d', d=4)
assert bag.args == ('a', )
assert bag.kwargs == {'a': 1}
assert bag.flags is ()
assert bag2.args == ('a', 'b', )
assert bag2.kwargs == {'a': 1, 'b': 2}
assert INHERIT_INPUT in bag2.flags
assert bag3.args == ('a', 'c', )
assert bag3.kwargs == {'a': 1, 'c': 3}
assert bag3.flags is ()
assert bag4.args == ('d', )
assert bag4.kwargs == {'d': 4}
assert bag4.flags is ()
bag4.set_parent(bag)
assert bag4.args == ('a', 'd', )
assert bag4.kwargs == {'a': 1, 'd': 4}
assert bag4.flags is ()
bag4.set_parent(bag3)
assert bag4.args == ('a', 'c', 'd', )
assert bag4.kwargs == {'a': 1, 'c': 3, 'd': 4}
assert bag4.flags is ()
def test_repr():
bag = Bag('a', a=1)
assert repr(bag) == "<Bag ('a', a=1)>"

View File

@ -1,6 +1,6 @@
from bonobo import Graph, NaiveStrategy, Bag, contextual
from bonobo.constants import BEGIN, END
from bonobo.context.execution import GraphExecutionContext
from bonobo.util.tokens import BEGIN, END
def generate_integers():

View File

@ -1,43 +0,0 @@
import pytest
from bonobo.core.graphs import Graph
from bonobo.util.tokens import BEGIN
identity = lambda x: x
def test_graph_outputs_of():
g = Graph()
# default graph only node
assert len(g.outputs_of(BEGIN)) == 0
# unexisting node
with pytest.raises(KeyError):
g.outputs_of(0)
# create node
assert len(g.outputs_of(0, create=True)) == 0
assert len(g.outputs_of(0)) == 0
def test_graph_add_component():
g = Graph()
assert len(g.nodes) == 0
g.add_node(identity)
assert len(g.nodes) == 1
g.add_node(identity)
assert len(g.nodes) == 2
def test_graph_add_chain():
g = Graph()
assert len(g.nodes) == 0
g.add_chain(identity, identity, identity)
assert len(g.nodes) == 3
assert len(g.outputs_of(BEGIN)) == 1

View File

@ -18,9 +18,9 @@ from queue import Empty
import pytest
from bonobo.core.errors import InactiveWritableError, InactiveReadableError
from bonobo.constants import BEGIN, END
from bonobo.core.inputs import Input
from bonobo.util.tokens import BEGIN, END
from bonobo.errors import InactiveWritableError, InactiveReadableError
def test_input_runlevels():

View File

@ -1,6 +0,0 @@
from bonobo.util.tokens import Token
def test_token_repr():
t = Token('Acme')
assert repr(t) == '<Acme>'