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)
|
||||
|
||||
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:
|
||||
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
|
||||
|
||||
@ -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):
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
from unittest.mock import Mock
|
||||
import pickle
|
||||
from unittest.mock import Mock
|
||||
|
||||
from bonobo import Bag
|
||||
from bonobo.constants import INHERIT_INPUT
|
||||
@ -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
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