Removes unused functions and test bag application to iterables.
This commit is contained in:
@ -108,4 +108,4 @@ class Configurable(metaclass=ConfigurableMeta):
|
|||||||
return self.call(*args, **kwargs)
|
return self.call(*args, **kwargs)
|
||||||
|
|
||||||
def call(self, *args, **kwargs):
|
def call(self, *args, **kwargs):
|
||||||
raise NotImplementedError('Not implemented.')
|
raise AbstractError('Not implemented.')
|
||||||
|
|||||||
@ -65,12 +65,8 @@ class Bag:
|
|||||||
if len(args) == 0 and len(kwargs) == 0:
|
if len(args) == 0 and len(kwargs) == 0:
|
||||||
try:
|
try:
|
||||||
iter(func_or_iter)
|
iter(func_or_iter)
|
||||||
|
|
||||||
def generator():
|
def generator():
|
||||||
nonlocal func_or_iter
|
yield from func_or_iter
|
||||||
for x in func_or_iter:
|
|
||||||
yield x
|
|
||||||
|
|
||||||
return generator()
|
return generator()
|
||||||
except TypeError as exc:
|
except TypeError as exc:
|
||||||
raise TypeError('Could not apply bag to {}.'.format(func_or_iter)) from exc
|
raise TypeError('Could not apply bag to {}.'.format(func_or_iter)) from exc
|
||||||
|
|||||||
@ -1,31 +1,7 @@
|
|||||||
import functools
|
import functools
|
||||||
import struct
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import warnings
|
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):
|
def deprecated_alias(alias, func):
|
||||||
@functools.wraps(func)
|
@functools.wraps(func)
|
||||||
def new_func(*args, **kwargs):
|
def new_func(*args, **kwargs):
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
from unittest.mock import Mock
|
|
||||||
import pickle
|
import pickle
|
||||||
|
from unittest.mock import Mock
|
||||||
|
|
||||||
from bonobo import Bag
|
from bonobo import Bag
|
||||||
from bonobo.constants import INHERIT_INPUT
|
from bonobo.constants import INHERIT_INPUT
|
||||||
from bonobo.structs import Token
|
from bonobo.structs import Token
|
||||||
|
|
||||||
args = ('foo', 'bar', )
|
args = ('foo', 'bar',)
|
||||||
kwargs = dict(acme='corp')
|
kwargs = dict(acme='corp')
|
||||||
|
|
||||||
|
|
||||||
@ -34,29 +34,29 @@ def test_inherit():
|
|||||||
bag3 = bag.extend('c', c=3)
|
bag3 = bag.extend('c', c=3)
|
||||||
bag4 = Bag('d', d=4)
|
bag4 = Bag('d', d=4)
|
||||||
|
|
||||||
assert bag.args == ('a', )
|
assert bag.args == ('a',)
|
||||||
assert bag.kwargs == {'a': 1}
|
assert bag.kwargs == {'a': 1}
|
||||||
assert bag.flags is ()
|
assert bag.flags is ()
|
||||||
|
|
||||||
assert bag2.args == ('a', 'b', )
|
assert bag2.args == ('a', 'b',)
|
||||||
assert bag2.kwargs == {'a': 1, 'b': 2}
|
assert bag2.kwargs == {'a': 1, 'b': 2}
|
||||||
assert INHERIT_INPUT in bag2.flags
|
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.kwargs == {'a': 1, 'c': 3}
|
||||||
assert bag3.flags is ()
|
assert bag3.flags is ()
|
||||||
|
|
||||||
assert bag4.args == ('d', )
|
assert bag4.args == ('d',)
|
||||||
assert bag4.kwargs == {'d': 4}
|
assert bag4.kwargs == {'d': 4}
|
||||||
assert bag4.flags is ()
|
assert bag4.flags is ()
|
||||||
|
|
||||||
bag4.set_parent(bag)
|
bag4.set_parent(bag)
|
||||||
assert bag4.args == ('a', 'd', )
|
assert bag4.args == ('a', 'd',)
|
||||||
assert bag4.kwargs == {'a': 1, 'd': 4}
|
assert bag4.kwargs == {'a': 1, 'd': 4}
|
||||||
assert bag4.flags is ()
|
assert bag4.flags is ()
|
||||||
|
|
||||||
bag4.set_parent(bag3)
|
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.kwargs == {'a': 1, 'c': 3, 'd': 4}
|
||||||
assert bag4.flags is ()
|
assert bag4.flags is ()
|
||||||
|
|
||||||
@ -87,3 +87,11 @@ def test_eq_operator():
|
|||||||
def test_repr():
|
def test_repr():
|
||||||
bag = Bag('a', a=1)
|
bag = Bag('a', a=1)
|
||||||
assert 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
24
tests/util/test_compat.py
Normal 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()
|
||||||
|
|
||||||
Reference in New Issue
Block a user