style: switching from yapf to isort/black
This commit is contained in:
@ -147,14 +147,14 @@ class TestBagType(unittest.TestCase):
|
||||
self.assertEqual(Zero()._asdict(), {})
|
||||
self.assertEqual(Zero()._fields, ())
|
||||
|
||||
Dot = BagType('Dot', ('d', ))
|
||||
self.assertEqual(Dot(1), (1, ))
|
||||
self.assertEqual(Dot._make([1]), (1, ))
|
||||
Dot = BagType('Dot', ('d',))
|
||||
self.assertEqual(Dot(1), (1,))
|
||||
self.assertEqual(Dot._make([1]), (1,))
|
||||
self.assertEqual(Dot(1).d, 1)
|
||||
self.assertEqual(repr(Dot(1)), 'Dot(d=1)')
|
||||
self.assertEqual(Dot(1)._asdict(), {'d': 1})
|
||||
self.assertEqual(Dot(1)._replace(d=999), (999, ))
|
||||
self.assertEqual(Dot(1)._fields, ('d', ))
|
||||
self.assertEqual(Dot(1)._replace(d=999), (999,))
|
||||
self.assertEqual(Dot(1)._fields, ('d',))
|
||||
|
||||
n = 5000 if sys.version_info >= (3, 7) else 254
|
||||
names = list(set(''.join([choice(string.ascii_letters) for j in range(10)]) for i in range(n)))
|
||||
@ -178,7 +178,7 @@ class TestBagType(unittest.TestCase):
|
||||
|
||||
def test_pickle(self):
|
||||
p = TBag(x=10, y=20, z=30)
|
||||
for module in (pickle, ):
|
||||
for module in (pickle,):
|
||||
loads = getattr(module, 'loads')
|
||||
dumps = getattr(module, 'dumps')
|
||||
for protocol in range(-1, module.HIGHEST_PROTOCOL + 1):
|
||||
@ -206,25 +206,191 @@ class TestBagType(unittest.TestCase):
|
||||
# Broader test of all interesting names taken from the code, old
|
||||
# template, and an example
|
||||
words = {
|
||||
'Alias', 'At', 'AttributeError', 'Build', 'Bypass', 'Create', 'Encountered', 'Expected', 'Field', 'For',
|
||||
'Got', 'Helper', 'IronPython', 'Jython', 'KeyError', 'Make', 'Modify', 'Note', 'OrderedDict', 'Point',
|
||||
'Return', 'Returns', 'Type', 'TypeError', 'Used', 'Validate', 'ValueError', 'Variables', 'a', 'accessible',
|
||||
'add', 'added', 'all', 'also', 'an', 'arg_list', 'args', 'arguments', 'automatically', 'be', 'build',
|
||||
'builtins', 'but', 'by', 'cannot', 'class_namespace', 'classmethod', 'cls', 'collections', 'convert',
|
||||
'copy', 'created', 'creation', 'd', 'debugging', 'defined', 'dict', 'dictionary', 'doc', 'docstring',
|
||||
'docstrings', 'duplicate', 'effect', 'either', 'enumerate', 'environments', 'error', 'example', 'exec', 'f',
|
||||
'f_globals', 'field', 'field_names', 'fields', 'formatted', 'frame', 'function', 'functions', 'generate',
|
||||
'getter', 'got', 'greater', 'has', 'help', 'identifiers', 'indexable', 'instance', 'instantiate',
|
||||
'interning', 'introspection', 'isidentifier', 'isinstance', 'itemgetter', 'iterable', 'join', 'keyword',
|
||||
'keywords', 'kwds', 'len', 'like', 'list', 'map', 'maps', 'message', 'metadata', 'method', 'methods',
|
||||
'module', 'module_name', 'must', 'name', 'named', 'namedtuple', 'namedtuple_', 'names', 'namespace',
|
||||
'needs', 'new', 'nicely', 'num_fields', 'number', 'object', 'of', 'operator', 'option', 'p', 'particular',
|
||||
'pickle', 'pickling', 'plain', 'pop', 'positional', 'property', 'r', 'regular', 'rename', 'replace',
|
||||
'replacing', 'repr', 'repr_fmt', 'representation', 'result', 'reuse_itemgetter', 's', 'seen', 'sequence',
|
||||
'set', 'side', 'specified', 'split', 'start', 'startswith', 'step', 'str', 'string', 'strings', 'subclass',
|
||||
'sys', 'targets', 'than', 'the', 'their', 'this', 'to', 'tuple_new', 'type', 'typename', 'underscore',
|
||||
'unexpected', 'unpack', 'up', 'use', 'used', 'user', 'valid', 'values', 'variable', 'verbose', 'where',
|
||||
'which', 'work', 'x', 'y', 'z', 'zip'
|
||||
'Alias',
|
||||
'At',
|
||||
'AttributeError',
|
||||
'Build',
|
||||
'Bypass',
|
||||
'Create',
|
||||
'Encountered',
|
||||
'Expected',
|
||||
'Field',
|
||||
'For',
|
||||
'Got',
|
||||
'Helper',
|
||||
'IronPython',
|
||||
'Jython',
|
||||
'KeyError',
|
||||
'Make',
|
||||
'Modify',
|
||||
'Note',
|
||||
'OrderedDict',
|
||||
'Point',
|
||||
'Return',
|
||||
'Returns',
|
||||
'Type',
|
||||
'TypeError',
|
||||
'Used',
|
||||
'Validate',
|
||||
'ValueError',
|
||||
'Variables',
|
||||
'a',
|
||||
'accessible',
|
||||
'add',
|
||||
'added',
|
||||
'all',
|
||||
'also',
|
||||
'an',
|
||||
'arg_list',
|
||||
'args',
|
||||
'arguments',
|
||||
'automatically',
|
||||
'be',
|
||||
'build',
|
||||
'builtins',
|
||||
'but',
|
||||
'by',
|
||||
'cannot',
|
||||
'class_namespace',
|
||||
'classmethod',
|
||||
'cls',
|
||||
'collections',
|
||||
'convert',
|
||||
'copy',
|
||||
'created',
|
||||
'creation',
|
||||
'd',
|
||||
'debugging',
|
||||
'defined',
|
||||
'dict',
|
||||
'dictionary',
|
||||
'doc',
|
||||
'docstring',
|
||||
'docstrings',
|
||||
'duplicate',
|
||||
'effect',
|
||||
'either',
|
||||
'enumerate',
|
||||
'environments',
|
||||
'error',
|
||||
'example',
|
||||
'exec',
|
||||
'f',
|
||||
'f_globals',
|
||||
'field',
|
||||
'field_names',
|
||||
'fields',
|
||||
'formatted',
|
||||
'frame',
|
||||
'function',
|
||||
'functions',
|
||||
'generate',
|
||||
'getter',
|
||||
'got',
|
||||
'greater',
|
||||
'has',
|
||||
'help',
|
||||
'identifiers',
|
||||
'indexable',
|
||||
'instance',
|
||||
'instantiate',
|
||||
'interning',
|
||||
'introspection',
|
||||
'isidentifier',
|
||||
'isinstance',
|
||||
'itemgetter',
|
||||
'iterable',
|
||||
'join',
|
||||
'keyword',
|
||||
'keywords',
|
||||
'kwds',
|
||||
'len',
|
||||
'like',
|
||||
'list',
|
||||
'map',
|
||||
'maps',
|
||||
'message',
|
||||
'metadata',
|
||||
'method',
|
||||
'methods',
|
||||
'module',
|
||||
'module_name',
|
||||
'must',
|
||||
'name',
|
||||
'named',
|
||||
'namedtuple',
|
||||
'namedtuple_',
|
||||
'names',
|
||||
'namespace',
|
||||
'needs',
|
||||
'new',
|
||||
'nicely',
|
||||
'num_fields',
|
||||
'number',
|
||||
'object',
|
||||
'of',
|
||||
'operator',
|
||||
'option',
|
||||
'p',
|
||||
'particular',
|
||||
'pickle',
|
||||
'pickling',
|
||||
'plain',
|
||||
'pop',
|
||||
'positional',
|
||||
'property',
|
||||
'r',
|
||||
'regular',
|
||||
'rename',
|
||||
'replace',
|
||||
'replacing',
|
||||
'repr',
|
||||
'repr_fmt',
|
||||
'representation',
|
||||
'result',
|
||||
'reuse_itemgetter',
|
||||
's',
|
||||
'seen',
|
||||
'sequence',
|
||||
'set',
|
||||
'side',
|
||||
'specified',
|
||||
'split',
|
||||
'start',
|
||||
'startswith',
|
||||
'step',
|
||||
'str',
|
||||
'string',
|
||||
'strings',
|
||||
'subclass',
|
||||
'sys',
|
||||
'targets',
|
||||
'than',
|
||||
'the',
|
||||
'their',
|
||||
'this',
|
||||
'to',
|
||||
'tuple_new',
|
||||
'type',
|
||||
'typename',
|
||||
'underscore',
|
||||
'unexpected',
|
||||
'unpack',
|
||||
'up',
|
||||
'use',
|
||||
'used',
|
||||
'user',
|
||||
'valid',
|
||||
'values',
|
||||
'variable',
|
||||
'verbose',
|
||||
'where',
|
||||
'which',
|
||||
'work',
|
||||
'x',
|
||||
'y',
|
||||
'z',
|
||||
'zip',
|
||||
}
|
||||
sorted_words = tuple(sorted(words))
|
||||
T = BagType('T', sorted_words)
|
||||
@ -252,7 +418,7 @@ class TestBagType(unittest.TestCase):
|
||||
self.assertEqual(t.__getnewargs__(), values)
|
||||
|
||||
def test_repr(self):
|
||||
A = BagType('A', ('x', ))
|
||||
A = BagType('A', ('x',))
|
||||
self.assertEqual(repr(A(1)), 'A(x=1)')
|
||||
|
||||
# repr should show the name of the subclass
|
||||
@ -273,6 +439,18 @@ class TestBagType(unittest.TestCase):
|
||||
|
||||
def test_annoying_attribute_names(self):
|
||||
self._create(
|
||||
'__slots__', '__getattr__', '_attrs', '_fields', '__new__', '__getnewargs__', '__repr__', '_make', 'get',
|
||||
'_replace', '_asdict', '_cls', 'self', 'tuple'
|
||||
'__slots__',
|
||||
'__getattr__',
|
||||
'_attrs',
|
||||
'_fields',
|
||||
'__new__',
|
||||
'__getnewargs__',
|
||||
'__repr__',
|
||||
'_make',
|
||||
'get',
|
||||
'_replace',
|
||||
'_asdict',
|
||||
'_cls',
|
||||
'self',
|
||||
'tuple',
|
||||
)
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
|
||||
from bonobo.util import sortedlist, ensure_tuple
|
||||
from bonobo.util.collections import tuplize, cast
|
||||
from bonobo.util import ensure_tuple, sortedlist
|
||||
from bonobo.util.collections import cast, tuplize
|
||||
|
||||
|
||||
def test_sortedlist():
|
||||
@ -14,8 +14,8 @@ def test_sortedlist():
|
||||
|
||||
|
||||
def test_ensure_tuple():
|
||||
assert ensure_tuple('a') == ('a', )
|
||||
assert ensure_tuple(('a', )) == ('a', )
|
||||
assert ensure_tuple('a') == ('a',)
|
||||
assert ensure_tuple(('a',)) == ('a',)
|
||||
assert ensure_tuple(()) is ()
|
||||
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ import operator
|
||||
|
||||
import pytest
|
||||
|
||||
from bonobo.util.objects import Wrapper, get_name, ValueHolder, get_attribute_or_create
|
||||
from bonobo.util.objects import ValueHolder, Wrapper, get_attribute_or_create, get_name
|
||||
from bonobo.util.testing import optional_contextmanager
|
||||
|
||||
|
||||
@ -65,10 +65,7 @@ def test_valueholder_notequal():
|
||||
assert not (x != 42)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('rlo,rhi', [
|
||||
(1, 2),
|
||||
('a', 'b'),
|
||||
])
|
||||
@pytest.mark.parametrize('rlo,rhi', [(1, 2), ('a', 'b')])
|
||||
def test_valueholder_ordering(rlo, rhi):
|
||||
vlo, vhi = ValueHolder(rlo), ValueHolder(rhi)
|
||||
|
||||
@ -129,15 +126,27 @@ def test_get_attribute_or_create():
|
||||
unsupported_operations = {
|
||||
int: {operator.matmul},
|
||||
str: {
|
||||
operator.sub, operator.mul, operator.matmul, operator.floordiv, operator.truediv, operator.mod, divmod,
|
||||
operator.pow, operator.lshift, operator.rshift, operator.and_, operator.xor, operator.or_
|
||||
operator.sub,
|
||||
operator.mul,
|
||||
operator.matmul,
|
||||
operator.floordiv,
|
||||
operator.truediv,
|
||||
operator.mod,
|
||||
divmod,
|
||||
operator.pow,
|
||||
operator.lshift,
|
||||
operator.rshift,
|
||||
operator.and_,
|
||||
operator.xor,
|
||||
operator.or_,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize('x,y', [(5, 3), (0, 10), (0, 0), (1, 1), ('foo', 'bar'), ('', 'baz!')])
|
||||
@pytest.mark.parametrize(
|
||||
'operation,inplace_operation', [
|
||||
'operation,inplace_operation',
|
||||
[
|
||||
(operator.add, operator.iadd),
|
||||
(operator.sub, operator.isub),
|
||||
(operator.mul, operator.imul),
|
||||
@ -152,7 +161,7 @@ unsupported_operations = {
|
||||
(operator.and_, operator.iand),
|
||||
(operator.xor, operator.ixor),
|
||||
(operator.or_, operator.ior),
|
||||
]
|
||||
],
|
||||
)
|
||||
def test_valueholder_integer_operations(x, y, operation, inplace_operation):
|
||||
v = ValueHolder(x)
|
||||
|
||||
@ -15,4 +15,4 @@ def test_resolve_options():
|
||||
|
||||
|
||||
def test_resolve_transformations():
|
||||
assert _resolve_transformations(('PrettyPrinter', )) == (bonobo.PrettyPrinter, )
|
||||
assert _resolve_transformations(('PrettyPrinter',)) == (bonobo.PrettyPrinter,)
|
||||
|
||||
@ -3,10 +3,7 @@ from bonobo.util.statistics import WithStatistics
|
||||
|
||||
class MyThingWithStats(WithStatistics):
|
||||
def get_statistics(self, *args, **kwargs):
|
||||
return (
|
||||
('foo', 42),
|
||||
('bar', 69),
|
||||
)
|
||||
return (('foo', 42), ('bar', 69))
|
||||
|
||||
|
||||
def test_with_statistics():
|
||||
|
||||
Reference in New Issue
Block a user