Removes unused functions and test bag application to iterables.

This commit is contained in:
Romain Dorgueil
2017-05-20 14:47:30 +02:00
parent 4342035f12
commit 2b3ef05fac
5 changed files with 42 additions and 38 deletions

View File

@ -108,4 +108,4 @@ class Configurable(metaclass=ConfigurableMeta):
return self.call(*args, **kwargs)
def call(self, *args, **kwargs):
raise NotImplementedError('Not implemented.')
raise AbstractError('Not implemented.')

View File

@ -65,12 +65,8 @@ class Bag:
if len(args) == 0 and len(kwargs) == 0:
try:
iter(func_or_iter)
def generator():
nonlocal func_or_iter
for x in func_or_iter:
yield x
yield from func_or_iter
return generator()
except TypeError as exc:
raise TypeError('Could not apply bag to {}.'.format(func_or_iter)) from exc

View File

@ -1,31 +1,7 @@
import functools
import struct
import sys
import warnings
def is_platform_little_endian():
""" am I little endian """
return sys.byteorder == 'little'
def is_platform_windows():
return sys.platform == 'win32' or sys.platform == 'cygwin'
def is_platform_linux():
return sys.platform == 'linux2'
def is_platform_mac():
return sys.platform == 'darwin'
def is_platform_32bit():
return struct.calcsize("P") * 8 < 64
def deprecated_alias(alias, func):
@functools.wraps(func)
def new_func(*args, **kwargs):

View File

@ -1,11 +1,11 @@
from unittest.mock import Mock
import pickle
from unittest.mock import Mock
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 ()
@ -87,3 +87,11 @@ def test_eq_operator():
def test_repr():
bag = Bag('a', a=1)
assert repr(bag) == "<Bag ('a', a=1)>"
def test_iterator():
bag = Bag()
assert list(bag.apply([1, 2, 3])) == [1, 2, 3]
assert list(bag.apply((1, 2, 3))) == [1, 2, 3]
assert list(bag.apply(range(5))) == [0, 1, 2, 3, 4]
assert list(bag.apply('azerty')) == ['a', 'z', 'e', 'r', 't', 'y']

24
tests/util/test_compat.py Normal file
View File

@ -0,0 +1,24 @@
import pytest
from bonobo.util.compat import deprecated, deprecated_alias
def test_deprecated():
@deprecated
def foo():
pass
foo = deprecated(foo)
with pytest.warns(DeprecationWarning):
foo()
def test_deprecated_alias():
def foo():
pass
foo = deprecated_alias('bar', foo)
with pytest.warns(DeprecationWarning):
foo()