Tuning ValueHolder as I could not find better option to generate the double-underscore methods.

This commit is contained in:
Romain Dorgueil
2017-05-21 19:22:45 +02:00
parent 2b3ef05fac
commit 4d9b579a60
12 changed files with 177 additions and 117 deletions

View File

@ -5,7 +5,7 @@ from bonobo import Bag
from bonobo.constants import INHERIT_INPUT
from bonobo.structs import Token
args = ('foo', 'bar',)
args = ('foo', 'bar', )
kwargs = dict(acme='corp')
@ -34,29 +34,29 @@ def test_inherit():
bag3 = bag.extend('c', c=3)
bag4 = Bag('d', d=4)
assert bag.args == ('a',)
assert bag.args == ('a', )
assert bag.kwargs == {'a': 1}
assert bag.flags is ()
assert bag2.args == ('a', 'b',)
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.args == ('a', 'c', )
assert bag3.kwargs == {'a': 1, 'c': 3}
assert bag3.flags is ()
assert bag4.args == ('d',)
assert bag4.args == ('d', )
assert bag4.kwargs == {'d': 4}
assert bag4.flags is ()
bag4.set_parent(bag)
assert bag4.args == ('a', 'd',)
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.args == ('a', 'c', 'd', )
assert bag4.kwargs == {'a': 1, 'c': 3, 'd': 4}
assert bag4.flags is ()

View File

@ -1,7 +1,8 @@
from unittest.mock import MagicMock
import bonobo
import pytest
import bonobo
from bonobo.config.processors import ContextCurrifier
from bonobo.constants import NOT_MODIFIED
@ -10,14 +11,12 @@ def test_count():
with pytest.raises(TypeError):
bonobo.count()
context = MagicMock()
currified = ContextCurrifier(bonobo.count)
currified.setup(context)
for i in range(42):
currified()
currified.teardown()
with ContextCurrifier(bonobo.count).as_contextmanager(context) as stack:
for i in range(42):
stack()
assert len(context.method_calls) == 1
bag = context.send.call_args[0][0]
@ -32,18 +31,31 @@ def test_identity():
def test_limit():
limit = bonobo.Limit(2)
results = []
for i in range(42):
results += list(limit())
context, results = MagicMock(), []
with ContextCurrifier(bonobo.Limit(2)).as_contextmanager(context) as stack:
for i in range(42):
results += list(stack())
assert results == [NOT_MODIFIED] * 2
def test_limit_not_there():
limit = bonobo.Limit(42)
results = []
for i in range(10):
results += list(limit())
context, results = MagicMock(), []
with ContextCurrifier(bonobo.Limit(42)).as_contextmanager(context) as stack:
for i in range(10):
results += list(stack())
assert results == [NOT_MODIFIED] * 10
def test_limit_default():
context, results = MagicMock(), []
with ContextCurrifier(bonobo.Limit()).as_contextmanager(context) as stack:
for i in range(20):
results += list(stack())
assert results == [NOT_MODIFIED] * 10

View File

@ -21,4 +21,3 @@ def test_deprecated_alias():
with pytest.warns(DeprecationWarning):
foo()

View File

@ -35,6 +35,7 @@ def test_wrapper_name():
def test_valueholder():
x = ValueHolder(42)
assert x == 42
x += 1
assert x == 43