style: switching from yapf to isort/black
This commit is contained in:
@ -9,17 +9,11 @@ def test_entrypoint():
|
||||
for command in pkg_resources.iter_entry_points('bonobo.commands'):
|
||||
commands[command.name] = command
|
||||
|
||||
assert not {
|
||||
'convert',
|
||||
'init',
|
||||
'inspect',
|
||||
'run',
|
||||
'version',
|
||||
}.difference(set(commands))
|
||||
assert not {'convert', 'init', 'inspect', 'run', 'version'}.difference(set(commands))
|
||||
|
||||
|
||||
@all_runners
|
||||
def test_no_command(runner):
|
||||
_, err, exc = runner(catch_errors=True)
|
||||
assert type(exc) == SystemExit
|
||||
assert 'error: the following arguments are required: command' in err
|
||||
assert 'error: the following arguments are required: command' in err
|
||||
|
||||
@ -27,8 +27,9 @@ def test_download_works_for_examples(runner):
|
||||
fout = io.BytesIO()
|
||||
fout.close = lambda: None
|
||||
|
||||
with patch('bonobo.commands.download._open_url') as mock_open_url, \
|
||||
patch('bonobo.commands.download.open') as mock_open:
|
||||
with patch('bonobo.commands.download._open_url') as mock_open_url, patch(
|
||||
'bonobo.commands.download.open'
|
||||
) as mock_open:
|
||||
mock_open_url.return_value = MockResponse()
|
||||
mock_open.return_value = fout
|
||||
runner('download', 'examples/datasets/coffeeshops.txt')
|
||||
@ -41,4 +42,4 @@ def test_download_works_for_examples(runner):
|
||||
@all_runners
|
||||
def test_download_fails_non_example(runner):
|
||||
with pytest.raises(ValueError):
|
||||
runner('download', 'something/entirely/different.txt')
|
||||
runner('download', 'something/entirely/different.txt')
|
||||
|
||||
@ -6,21 +6,14 @@ from bonobo.util.testing import EnvironmentTestCase
|
||||
@pytest.fixture
|
||||
def env1(tmpdir):
|
||||
env_file = tmpdir.join('.env_one')
|
||||
env_file.write('\n'.join((
|
||||
'SECRET=unknown',
|
||||
'PASSWORD=sweet',
|
||||
'PATH=first',
|
||||
)))
|
||||
env_file.write('\n'.join(('SECRET=unknown', 'PASSWORD=sweet', 'PATH=first')))
|
||||
return str(env_file)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def env2(tmpdir):
|
||||
env_file = tmpdir.join('.env_two')
|
||||
env_file.write('\n'.join((
|
||||
'PASSWORD=bitter',
|
||||
"PATH='second'",
|
||||
)))
|
||||
env_file.write('\n'.join(('PASSWORD=bitter', "PATH='second'")))
|
||||
return str(env_file)
|
||||
|
||||
|
||||
@ -71,7 +64,15 @@ class TestEnvFileCombinations(EnvironmentTestCase):
|
||||
|
||||
def test_run_with_both_env_files_then_overrides(self, runner, target, env1, env2):
|
||||
env = self.run_environ(
|
||||
runner, *target, '--default-env-file', env1, '--env-file', env2, '--env', 'PASSWORD=mine', '--env',
|
||||
runner,
|
||||
*target,
|
||||
'--default-env-file',
|
||||
env1,
|
||||
'--env-file',
|
||||
env2,
|
||||
'--env',
|
||||
'PASSWORD=mine',
|
||||
'--env',
|
||||
'SECRET=s3cr3t'
|
||||
)
|
||||
assert env.get('SECRET') == 's3cr3t'
|
||||
|
||||
@ -17,4 +17,4 @@ def test_version(runner):
|
||||
out, err = runner('version', '-qq')
|
||||
out = out.strip()
|
||||
assert not out.startswith('bonobo ')
|
||||
assert __version__ in out
|
||||
assert __version__ in out
|
||||
|
||||
@ -50,10 +50,7 @@ def test_define_with_decorator():
|
||||
calls = []
|
||||
|
||||
def my_handler(*args, **kwargs):
|
||||
calls.append((
|
||||
args,
|
||||
kwargs,
|
||||
))
|
||||
calls.append((args, kwargs))
|
||||
|
||||
Concrete = MethodBasedConfigurable(my_handler)
|
||||
|
||||
@ -77,10 +74,7 @@ def test_late_binding_method_decoration():
|
||||
|
||||
@MethodBasedConfigurable(foo='foo')
|
||||
def Concrete(*args, **kwargs):
|
||||
calls.append((
|
||||
args,
|
||||
kwargs,
|
||||
))
|
||||
calls.append((args, kwargs))
|
||||
|
||||
assert callable(Concrete.handler)
|
||||
t = Concrete(bar='baz')
|
||||
@ -95,10 +89,7 @@ def test_define_with_argument():
|
||||
calls = []
|
||||
|
||||
def concrete_handler(*args, **kwargs):
|
||||
calls.append((
|
||||
args,
|
||||
kwargs,
|
||||
))
|
||||
calls.append((args, kwargs))
|
||||
|
||||
t = MethodBasedConfigurable(concrete_handler, 'foo', bar='baz')
|
||||
assert callable(t.handler)
|
||||
@ -112,10 +103,7 @@ def test_define_with_inheritance():
|
||||
|
||||
class Inheriting(MethodBasedConfigurable):
|
||||
def handler(self, *args, **kwargs):
|
||||
calls.append((
|
||||
args,
|
||||
kwargs,
|
||||
))
|
||||
calls.append((args, kwargs))
|
||||
|
||||
t = Inheriting('foo', bar='baz')
|
||||
assert callable(t.handler)
|
||||
@ -132,10 +120,7 @@ def test_inheritance_then_decorate():
|
||||
|
||||
@Inheriting
|
||||
def Concrete(*args, **kwargs):
|
||||
calls.append((
|
||||
args,
|
||||
kwargs,
|
||||
))
|
||||
calls.append((args, kwargs))
|
||||
|
||||
assert callable(Concrete.handler)
|
||||
t = Concrete('foo', bar='baz')
|
||||
|
||||
@ -40,7 +40,7 @@ def test_partial():
|
||||
assert len(ci.options) == 4
|
||||
assert len(ci.processors) == 1
|
||||
assert ci.partial
|
||||
assert ci.partial[0] == (f1, )
|
||||
assert ci.partial[0] == (f1,)
|
||||
assert not len(ci.partial[1])
|
||||
|
||||
# instanciate a more complete partial instance ...
|
||||
@ -53,10 +53,7 @@ def test_partial():
|
||||
assert len(ci.options) == 4
|
||||
assert len(ci.processors) == 1
|
||||
assert ci.partial
|
||||
assert ci.partial[0] == (
|
||||
f1,
|
||||
f2,
|
||||
)
|
||||
assert ci.partial[0] == (f1, f2)
|
||||
assert not len(ci.partial[1])
|
||||
|
||||
c = C('foo')
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
from operator import attrgetter
|
||||
|
||||
from bonobo.config import Configurable
|
||||
from bonobo.config.processors import ContextProcessor, resolve_processors, ContextCurrifier, use_context_processor
|
||||
from bonobo.config.processors import ContextCurrifier, ContextProcessor, resolve_processors, use_context_processor
|
||||
|
||||
|
||||
class CP1(Configurable):
|
||||
|
||||
@ -4,11 +4,11 @@ import time
|
||||
import pytest
|
||||
|
||||
from bonobo.config import Configurable, Container, Exclusive, Service, use
|
||||
from bonobo.config.services import validate_service_name, create_container
|
||||
from bonobo.config.services import create_container, validate_service_name
|
||||
from bonobo.util import get_name
|
||||
|
||||
|
||||
class PrinterInterface():
|
||||
class PrinterInterface:
|
||||
def print(self, *args):
|
||||
raise NotImplementedError()
|
||||
|
||||
@ -21,14 +21,11 @@ class ConcretePrinter(PrinterInterface):
|
||||
return ';'.join((self.prefix, *args))
|
||||
|
||||
|
||||
SERVICES = Container(
|
||||
printer0=ConcretePrinter(prefix='0'),
|
||||
printer1=ConcretePrinter(prefix='1'),
|
||||
)
|
||||
SERVICES = Container(printer0=ConcretePrinter(prefix='0'), printer1=ConcretePrinter(prefix='1'))
|
||||
|
||||
|
||||
class MyServiceDependantConfigurable(Configurable):
|
||||
printer = Service(PrinterInterface, )
|
||||
printer = Service(PrinterInterface)
|
||||
|
||||
def __call__(self, *args, printer: PrinterInterface):
|
||||
return printer.print(*args)
|
||||
@ -80,7 +77,7 @@ def test_exclusive():
|
||||
vcr.append(' '.join((prefix, str(i))))
|
||||
time.sleep(0.05)
|
||||
|
||||
threads = [threading.Thread(target=record, args=(str(i), )) for i in range(5)]
|
||||
threads = [threading.Thread(target=record, args=(str(i),)) for i in range(5)]
|
||||
|
||||
for thread in threads:
|
||||
thread.start()
|
||||
@ -90,8 +87,32 @@ def test_exclusive():
|
||||
thread.join()
|
||||
|
||||
assert vcr.tape == [
|
||||
'hello', '0 0', '0 1', '0 2', '0 3', '0 4', '1 0', '1 1', '1 2', '1 3', '1 4', '2 0', '2 1', '2 2', '2 3',
|
||||
'2 4', '3 0', '3 1', '3 2', '3 3', '3 4', '4 0', '4 1', '4 2', '4 3', '4 4'
|
||||
'hello',
|
||||
'0 0',
|
||||
'0 1',
|
||||
'0 2',
|
||||
'0 3',
|
||||
'0 4',
|
||||
'1 0',
|
||||
'1 1',
|
||||
'1 2',
|
||||
'1 3',
|
||||
'1 4',
|
||||
'2 0',
|
||||
'2 1',
|
||||
'2 2',
|
||||
'2 3',
|
||||
'2 4',
|
||||
'3 0',
|
||||
'3 1',
|
||||
'3 2',
|
||||
'3 3',
|
||||
'3 4',
|
||||
'4 0',
|
||||
'4 1',
|
||||
'4 2',
|
||||
'4 3',
|
||||
'4 4',
|
||||
]
|
||||
|
||||
|
||||
@ -118,10 +139,7 @@ def test_create_container_empty_values(services):
|
||||
|
||||
|
||||
def test_create_container_override():
|
||||
c = create_container({
|
||||
'http': 'http',
|
||||
'fs': 'fs',
|
||||
})
|
||||
c = create_container({'http': 'http', 'fs': 'fs'})
|
||||
assert len(c) == 2
|
||||
assert 'fs' in c and c['fs'] == 'fs'
|
||||
assert 'http' in c and c['http'] == 'http'
|
||||
|
||||
@ -3,10 +3,10 @@ from unittest.mock import MagicMock
|
||||
import pytest
|
||||
|
||||
from bonobo import Graph
|
||||
from bonobo.constants import EMPTY, NOT_MODIFIED, INHERIT
|
||||
from bonobo.constants import EMPTY, INHERIT, NOT_MODIFIED
|
||||
from bonobo.execution.contexts.node import NodeExecutionContext, split_token
|
||||
from bonobo.execution.strategies import NaiveStrategy
|
||||
from bonobo.util.testing import BufferingNodeExecutionContext, BufferingGraphExecutionContext
|
||||
from bonobo.util.testing import BufferingGraphExecutionContext, BufferingNodeExecutionContext
|
||||
|
||||
|
||||
def test_node_string():
|
||||
@ -18,7 +18,7 @@ def test_node_string():
|
||||
output = context.get_buffer()
|
||||
|
||||
assert len(output) == 1
|
||||
assert output[0] == ('foo', )
|
||||
assert output[0] == ('foo',)
|
||||
|
||||
def g():
|
||||
yield 'foo'
|
||||
@ -29,8 +29,8 @@ def test_node_string():
|
||||
output = context.get_buffer()
|
||||
|
||||
assert len(output) == 2
|
||||
assert output[0] == ('foo', )
|
||||
assert output[1] == ('bar', )
|
||||
assert output[0] == ('foo',)
|
||||
assert output[1] == ('bar',)
|
||||
|
||||
|
||||
def test_node_bytes():
|
||||
@ -42,7 +42,7 @@ def test_node_bytes():
|
||||
|
||||
output = context.get_buffer()
|
||||
assert len(output) == 1
|
||||
assert output[0] == (b'foo', )
|
||||
assert output[0] == (b'foo',)
|
||||
|
||||
def g():
|
||||
yield b'foo'
|
||||
@ -53,8 +53,8 @@ def test_node_bytes():
|
||||
output = context.get_buffer()
|
||||
|
||||
assert len(output) == 2
|
||||
assert output[0] == (b'foo', )
|
||||
assert output[1] == (b'bar', )
|
||||
assert output[0] == (b'foo',)
|
||||
assert output[1] == (b'bar',)
|
||||
|
||||
|
||||
def test_node_dict():
|
||||
@ -65,7 +65,7 @@ def test_node_dict():
|
||||
context.write_sync(EMPTY)
|
||||
output = context.get_buffer()
|
||||
assert len(output) == 1
|
||||
assert output[0] == ({'id': 1, 'name': 'foo'}, )
|
||||
assert output[0] == ({'id': 1, 'name': 'foo'},)
|
||||
|
||||
def g():
|
||||
yield {'id': 1, 'name': 'foo'}
|
||||
@ -75,8 +75,8 @@ def test_node_dict():
|
||||
context.write_sync(EMPTY)
|
||||
output = context.get_buffer()
|
||||
assert len(output) == 2
|
||||
assert output[0] == ({'id': 1, 'name': 'foo'}, )
|
||||
assert output[1] == ({'id': 2, 'name': 'bar'}, )
|
||||
assert output[0] == ({'id': 1, 'name': 'foo'},)
|
||||
assert output[1] == ({'id': 2, 'name': 'bar'},)
|
||||
|
||||
|
||||
def test_node_dict_chained():
|
||||
@ -93,7 +93,7 @@ def test_node_dict_chained():
|
||||
output = context.get_buffer()
|
||||
|
||||
assert len(output) == 1
|
||||
assert output[0] == ({'id': 1, 'name': 'FOO'}, )
|
||||
assert output[0] == ({'id': 1, 'name': 'FOO'},)
|
||||
|
||||
def g():
|
||||
yield {'id': 1, 'name': 'foo'}
|
||||
@ -104,8 +104,8 @@ def test_node_dict_chained():
|
||||
output = context.get_buffer()
|
||||
|
||||
assert len(output) == 2
|
||||
assert output[0] == ({'id': 1, 'name': 'FOO'}, )
|
||||
assert output[1] == ({'id': 2, 'name': 'BAR'}, )
|
||||
assert output[0] == ({'id': 1, 'name': 'FOO'},)
|
||||
assert output[1] == ({'id': 2, 'name': 'BAR'},)
|
||||
|
||||
|
||||
def test_node_tuple():
|
||||
@ -229,7 +229,7 @@ def test_node_lifecycle_with_kill():
|
||||
def test_split_token():
|
||||
assert split_token(('foo', 'bar')) == (set(), ('foo', 'bar'))
|
||||
assert split_token(()) == (set(), ())
|
||||
assert split_token('') == (set(), ('', ))
|
||||
assert split_token('') == (set(), ('',))
|
||||
|
||||
|
||||
def test_split_token_duplicate():
|
||||
@ -249,10 +249,10 @@ def test_split_token_not_modified():
|
||||
with pytest.raises(ValueError):
|
||||
split_token((INHERIT, NOT_MODIFIED))
|
||||
assert split_token(NOT_MODIFIED) == ({NOT_MODIFIED}, ())
|
||||
assert split_token((NOT_MODIFIED, )) == ({NOT_MODIFIED}, ())
|
||||
assert split_token((NOT_MODIFIED,)) == ({NOT_MODIFIED}, ())
|
||||
|
||||
|
||||
def test_split_token_inherit():
|
||||
assert split_token(INHERIT) == ({INHERIT}, ())
|
||||
assert split_token((INHERIT, )) == ({INHERIT}, ())
|
||||
assert split_token((INHERIT,)) == ({INHERIT}, ())
|
||||
assert split_token((INHERIT, 'foo', 'bar')) == ({INHERIT}, ('foo', 'bar'))
|
||||
|
||||
@ -14,16 +14,11 @@ class ResponseMock:
|
||||
return {}
|
||||
else:
|
||||
self.count += 1
|
||||
return {
|
||||
'records': self.json_value,
|
||||
}
|
||||
return {'records': self.json_value}
|
||||
|
||||
|
||||
def test_read_from_opendatasoft_api():
|
||||
extract = OpenDataSoftAPI(dataset='test-a-set')
|
||||
with patch('requests.get', return_value=ResponseMock([
|
||||
{'fields': {'foo': 'bar'}},
|
||||
{'fields': {'foo': 'zab'}},
|
||||
])):
|
||||
with patch('requests.get', return_value=ResponseMock([{'fields': {'foo': 'bar'}}, {'fields': {'foo': 'zab'}}])):
|
||||
for line in extract('http://example.com/', ValueHolder(0)):
|
||||
assert 'foo' in line
|
||||
|
||||
@ -1,10 +1,7 @@
|
||||
from bonobo.constants import INHERIT
|
||||
from bonobo.util.testing import BufferingNodeExecutionContext
|
||||
|
||||
messages = [
|
||||
('Hello', ),
|
||||
('Goodbye', ),
|
||||
]
|
||||
messages = [('Hello',), ('Goodbye',)]
|
||||
|
||||
|
||||
def append(*args):
|
||||
@ -15,7 +12,7 @@ def test_inherit():
|
||||
with BufferingNodeExecutionContext(append) as context:
|
||||
context.write_sync(*messages)
|
||||
|
||||
assert context.get_buffer() == list(map(lambda x: x + ('!', ), messages))
|
||||
assert context.get_buffer() == list(map(lambda x: x + ('!',), messages))
|
||||
|
||||
|
||||
def test_inherit_bag_tuple():
|
||||
@ -24,4 +21,4 @@ def test_inherit_bag_tuple():
|
||||
context.write_sync(*messages)
|
||||
|
||||
assert context.get_output_fields() == ('message', '0')
|
||||
assert context.get_buffer() == list(map(lambda x: x + ('!', ), messages))
|
||||
assert context.get_buffer() == list(map(lambda x: x + ('!',), messages))
|
||||
|
||||
@ -7,10 +7,7 @@ def useless(*args, **kwargs):
|
||||
|
||||
|
||||
def test_not_modified():
|
||||
input_messages = [
|
||||
('foo', 'bar'),
|
||||
('foo', 'baz'),
|
||||
]
|
||||
input_messages = [('foo', 'bar'), ('foo', 'baz')]
|
||||
|
||||
with BufferingNodeExecutionContext(useless) as context:
|
||||
context.write_sync(*input_messages)
|
||||
|
||||
@ -6,8 +6,9 @@ import pytest
|
||||
|
||||
from bonobo import CsvReader, CsvWriter
|
||||
from bonobo.constants import EMPTY
|
||||
from bonobo.util.testing import FilesystemTester, BufferingNodeExecutionContext, WriterTest, ConfigurableNodeTest, \
|
||||
ReaderTest
|
||||
from bonobo.util.testing import (
|
||||
BufferingNodeExecutionContext, ConfigurableNodeTest, FilesystemTester, ReaderTest, WriterTest
|
||||
)
|
||||
|
||||
csv_tester = FilesystemTester('csv')
|
||||
csv_tester.input_data = 'a,b,c\na foo,b foo,c foo\na bar,b bar,c bar'
|
||||
@ -23,15 +24,10 @@ def test_read_csv_from_file_kwargs(tmpdir):
|
||||
with BufferingNodeExecutionContext(CsvReader(filename, **defaults), services=services) as context:
|
||||
context.write_sync(EMPTY)
|
||||
|
||||
assert context.get_buffer_args_as_dicts() == [{
|
||||
'a': 'a foo',
|
||||
'b': 'b foo',
|
||||
'c': 'c foo',
|
||||
}, {
|
||||
'a': 'a bar',
|
||||
'b': 'b bar',
|
||||
'c': 'c bar',
|
||||
}]
|
||||
assert context.get_buffer_args_as_dicts() == [
|
||||
{'a': 'a foo', 'b': 'b foo', 'c': 'c foo'},
|
||||
{'a': 'a bar', 'b': 'b bar', 'c': 'c bar'},
|
||||
]
|
||||
|
||||
|
||||
###
|
||||
@ -50,22 +46,11 @@ LL = ('i', 'have', 'more', 'values')
|
||||
|
||||
|
||||
class CsvReaderTest(Csv, ReaderTest, TestCase):
|
||||
input_data = '\n'.join((
|
||||
'id,name',
|
||||
'1,John Doe',
|
||||
'2,Jane Doe',
|
||||
',DPR',
|
||||
'42,Elon Musk',
|
||||
))
|
||||
input_data = '\n'.join(('id,name', '1,John Doe', '2,Jane Doe', ',DPR', '42,Elon Musk'))
|
||||
|
||||
def check_output(self, context, *, prepend=None):
|
||||
out = context.get_buffer()
|
||||
assert out == (prepend or list()) + [
|
||||
('1', 'John Doe'),
|
||||
('2', 'Jane Doe'),
|
||||
('', 'DPR'),
|
||||
('42', 'Elon Musk'),
|
||||
]
|
||||
assert out == (prepend or list()) + [('1', 'John Doe'), ('2', 'Jane Doe'), ('', 'DPR'), ('42', 'Elon Musk')]
|
||||
|
||||
@incontext()
|
||||
def test_nofields(self, context):
|
||||
@ -80,12 +65,7 @@ class CsvReaderTest(Csv, ReaderTest, TestCase):
|
||||
context.stop()
|
||||
self.check_output(context, prepend=[('id', 'name')])
|
||||
|
||||
@incontext(
|
||||
output_fields=(
|
||||
'x',
|
||||
'y',
|
||||
), skip=1
|
||||
)
|
||||
@incontext(output_fields=('x', 'y'), skip=1)
|
||||
def test_output_fields(self, context):
|
||||
context.write_sync(EMPTY)
|
||||
context.stop()
|
||||
@ -107,11 +87,7 @@ class CsvWriterTest(Csv, WriterTest, TestCase):
|
||||
context.write_sync(('a', 'b'), ('c', 'd'))
|
||||
context.stop()
|
||||
|
||||
assert self.readlines() == (
|
||||
'foo,bar',
|
||||
'a,b',
|
||||
'c,d',
|
||||
)
|
||||
assert self.readlines() == ('foo,bar', 'a,b', 'c,d')
|
||||
|
||||
@incontext()
|
||||
def test_fields_from_type(self, context):
|
||||
@ -127,30 +103,21 @@ class CsvWriterTest(Csv, WriterTest, TestCase):
|
||||
context.write_sync((L1, L2), (L3, L4))
|
||||
context.stop()
|
||||
|
||||
assert self.readlines() == (
|
||||
'a,hey',
|
||||
'b,bee',
|
||||
'c,see',
|
||||
'd,dee',
|
||||
)
|
||||
assert self.readlines() == ('a,hey', 'b,bee', 'c,see', 'd,dee')
|
||||
|
||||
@incontext()
|
||||
def test_nofields_multiple_args_length_mismatch(self, context):
|
||||
# if length of input vary, then we get a TypeError (unrecoverable)
|
||||
with pytest.raises(TypeError):
|
||||
context.write_sync((L1, L2), (L3, ))
|
||||
context.write_sync((L1, L2), (L3,))
|
||||
|
||||
@incontext()
|
||||
def test_nofields_single_arg(self, context):
|
||||
# single args are just dumped, shapes can vary.
|
||||
context.write_sync((L1, ), (LL, ), (L3, ))
|
||||
context.write_sync((L1,), (LL,), (L3,))
|
||||
context.stop()
|
||||
|
||||
assert self.readlines() == (
|
||||
'a,hey',
|
||||
'i,have,more,values',
|
||||
'c,see',
|
||||
)
|
||||
assert self.readlines() == ('a,hey', 'i,have,more,values', 'c,see')
|
||||
|
||||
@incontext()
|
||||
def test_nofields_empty_args(self, context):
|
||||
|
||||
@ -21,10 +21,7 @@ def test_file_writer_contextless(tmpdir):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'lines,output',
|
||||
[
|
||||
(('ACME', ), 'ACME'), # one line...
|
||||
(('Foo', 'Bar', 'Baz'), 'Foo\nBar\nBaz'), # more than one line...
|
||||
]
|
||||
[(('ACME',), 'ACME'), (('Foo', 'Bar', 'Baz'), 'Foo\nBar\nBaz')], # one line... # more than one line...
|
||||
)
|
||||
def test_file_writer_in_context(tmpdir, lines, output):
|
||||
fs, filename, services = txt_tester.get_services_for_writer(tmpdir)
|
||||
@ -44,5 +41,5 @@ def test_file_reader(tmpdir):
|
||||
|
||||
output = context.get_buffer()
|
||||
assert len(output) == 2
|
||||
assert output[0] == ('Hello', )
|
||||
assert output[1] == ('World', )
|
||||
assert output[0] == ('Hello',)
|
||||
assert output[1] == ('World',)
|
||||
|
||||
@ -4,10 +4,9 @@ from unittest import TestCase
|
||||
|
||||
import pytest
|
||||
|
||||
from bonobo import JsonReader, JsonWriter
|
||||
from bonobo import LdjsonReader, LdjsonWriter
|
||||
from bonobo import JsonReader, JsonWriter, LdjsonReader, LdjsonWriter
|
||||
from bonobo.constants import EMPTY
|
||||
from bonobo.util.testing import WriterTest, ReaderTest, ConfigurableNodeTest
|
||||
from bonobo.util.testing import ConfigurableNodeTest, ReaderTest, WriterTest
|
||||
|
||||
FOOBAR = {'foo': 'bar'}
|
||||
OD_ABC = OrderedDict((('a', 'A'), ('b', 'B'), ('c', 'C')))
|
||||
@ -34,14 +33,7 @@ class JsonReaderDictsTest(Json, ReaderTest, TestCase):
|
||||
context.write_sync(EMPTY)
|
||||
context.stop()
|
||||
|
||||
assert context.get_buffer() == [
|
||||
({
|
||||
"foo": "bar"
|
||||
}, ),
|
||||
({
|
||||
"baz": "boz"
|
||||
}, ),
|
||||
]
|
||||
assert context.get_buffer() == [({"foo": "bar"},), ({"baz": "boz"},)]
|
||||
|
||||
|
||||
class JsonReaderListsTest(Json, ReaderTest, TestCase):
|
||||
@ -52,20 +44,14 @@ class JsonReaderListsTest(Json, ReaderTest, TestCase):
|
||||
context.write_sync(EMPTY)
|
||||
context.stop()
|
||||
|
||||
assert context.get_buffer() == [
|
||||
([1, 2, 3], ),
|
||||
([4, 5, 6], ),
|
||||
]
|
||||
assert context.get_buffer() == [([1, 2, 3],), ([4, 5, 6],)]
|
||||
|
||||
@incontext(output_type=tuple)
|
||||
def test_output_type(self, context):
|
||||
context.write_sync(EMPTY)
|
||||
context.stop()
|
||||
|
||||
assert context.get_buffer() == [
|
||||
([1, 2, 3], ),
|
||||
([4, 5, 6], ),
|
||||
]
|
||||
assert context.get_buffer() == [([1, 2, 3],), ([4, 5, 6],)]
|
||||
|
||||
|
||||
class JsonReaderStringsTest(Json, ReaderTest, TestCase):
|
||||
@ -76,22 +62,14 @@ class JsonReaderStringsTest(Json, ReaderTest, TestCase):
|
||||
context.write_sync(EMPTY)
|
||||
context.stop()
|
||||
|
||||
assert context.get_buffer() == [
|
||||
('foo', ),
|
||||
('bar', ),
|
||||
('baz', ),
|
||||
]
|
||||
assert context.get_buffer() == [('foo',), ('bar',), ('baz',)]
|
||||
|
||||
@incontext(output_type=tuple)
|
||||
def test_output_type(self, context):
|
||||
context.write_sync(EMPTY)
|
||||
context.stop()
|
||||
|
||||
assert context.get_buffer() == [
|
||||
('foo', ),
|
||||
('bar', ),
|
||||
('baz', ),
|
||||
]
|
||||
assert context.get_buffer() == [('foo',), ('bar',), ('baz',)]
|
||||
|
||||
|
||||
class JsonWriterTest(Json, WriterTest, TestCase):
|
||||
@ -101,10 +79,7 @@ class JsonWriterTest(Json, WriterTest, TestCase):
|
||||
context.write_sync(('a', 'b'), ('c', 'd'))
|
||||
context.stop()
|
||||
|
||||
assert self.readlines() == (
|
||||
'[{"foo": "a", "bar": "b"},',
|
||||
'{"foo": "c", "bar": "d"}]',
|
||||
)
|
||||
assert self.readlines() == ('[{"foo": "a", "bar": "b"},', '{"foo": "c", "bar": "d"}]')
|
||||
|
||||
@incontext()
|
||||
def test_fields_from_type(self, context):
|
||||
@ -112,10 +87,7 @@ class JsonWriterTest(Json, WriterTest, TestCase):
|
||||
context.write_sync((1, 2), (3, 4))
|
||||
context.stop()
|
||||
|
||||
assert self.readlines() == (
|
||||
'[{"x": 1, "y": 2},',
|
||||
'{"x": 3, "y": 4}]',
|
||||
)
|
||||
assert self.readlines() == ('[{"x": 1, "y": 2},', '{"x": 3, "y": 4}]')
|
||||
|
||||
@incontext()
|
||||
def test_nofields_multiple_args(self, context):
|
||||
@ -144,11 +116,7 @@ class JsonWriterTest(Json, WriterTest, TestCase):
|
||||
context.write_sync(FOOBAR, OD_ABC, FOOBAZ)
|
||||
context.stop()
|
||||
|
||||
assert self.readlines() == (
|
||||
'[{"foo": "bar"},',
|
||||
'{"a": "A", "b": "B", "c": "C"},',
|
||||
'{"foo": "baz"}]',
|
||||
)
|
||||
assert self.readlines() == ('[{"foo": "bar"},', '{"a": "A", "b": "B", "c": "C"},', '{"foo": "baz"}]')
|
||||
|
||||
@incontext()
|
||||
def test_nofields_empty_args(self, context):
|
||||
@ -156,7 +124,7 @@ class JsonWriterTest(Json, WriterTest, TestCase):
|
||||
context.write_sync(EMPTY, EMPTY, EMPTY)
|
||||
context.stop()
|
||||
|
||||
assert self.readlines() == ('[]', )
|
||||
assert self.readlines() == ('[]',)
|
||||
|
||||
|
||||
###
|
||||
@ -178,14 +146,7 @@ class LdjsonReaderDictsTest(Ldjson, ReaderTest, TestCase):
|
||||
context.write_sync(EMPTY)
|
||||
context.stop()
|
||||
|
||||
assert context.get_buffer() == [
|
||||
({
|
||||
"foo": "bar"
|
||||
}, ),
|
||||
({
|
||||
"baz": "boz"
|
||||
}, ),
|
||||
]
|
||||
assert context.get_buffer() == [({"foo": "bar"},), ({"baz": "boz"},)]
|
||||
|
||||
|
||||
class LdjsonReaderListsTest(Ldjson, ReaderTest, TestCase):
|
||||
@ -196,20 +157,14 @@ class LdjsonReaderListsTest(Ldjson, ReaderTest, TestCase):
|
||||
context.write_sync(EMPTY)
|
||||
context.stop()
|
||||
|
||||
assert context.get_buffer() == [
|
||||
([1, 2, 3], ),
|
||||
([4, 5, 6], ),
|
||||
]
|
||||
assert context.get_buffer() == [([1, 2, 3],), ([4, 5, 6],)]
|
||||
|
||||
@incontext(output_type=tuple)
|
||||
def test_output_type(self, context):
|
||||
context.write_sync(EMPTY)
|
||||
context.stop()
|
||||
|
||||
assert context.get_buffer() == [
|
||||
([1, 2, 3], ),
|
||||
([4, 5, 6], ),
|
||||
]
|
||||
assert context.get_buffer() == [([1, 2, 3],), ([4, 5, 6],)]
|
||||
|
||||
|
||||
class LdjsonReaderStringsTest(Ldjson, ReaderTest, TestCase):
|
||||
@ -220,22 +175,14 @@ class LdjsonReaderStringsTest(Ldjson, ReaderTest, TestCase):
|
||||
context.write_sync(EMPTY)
|
||||
context.stop()
|
||||
|
||||
assert context.get_buffer() == [
|
||||
('foo', ),
|
||||
('bar', ),
|
||||
('baz', ),
|
||||
]
|
||||
assert context.get_buffer() == [('foo',), ('bar',), ('baz',)]
|
||||
|
||||
@incontext(output_type=tuple)
|
||||
def test_output_type(self, context):
|
||||
context.write_sync(EMPTY)
|
||||
context.stop()
|
||||
|
||||
assert context.get_buffer() == [
|
||||
('foo', ),
|
||||
('bar', ),
|
||||
('baz', ),
|
||||
]
|
||||
assert context.get_buffer() == [('foo',), ('bar',), ('baz',)]
|
||||
|
||||
|
||||
class LdjsonWriterTest(Ldjson, WriterTest, TestCase):
|
||||
@ -253,10 +200,7 @@ class LdjsonWriterTest(Ldjson, WriterTest, TestCase):
|
||||
context.write_sync((1, 2), (3, 4))
|
||||
context.stop()
|
||||
|
||||
assert self.readlines() == (
|
||||
'{"x": 1, "y": 2}',
|
||||
'{"x": 3, "y": 4}',
|
||||
)
|
||||
assert self.readlines() == ('{"x": 1, "y": 2}', '{"x": 3, "y": 4}')
|
||||
|
||||
@incontext()
|
||||
def test_nofields_multiple_args(self, context):
|
||||
@ -285,11 +229,7 @@ class LdjsonWriterTest(Ldjson, WriterTest, TestCase):
|
||||
context.write_sync(FOOBAR, OD_ABC, FOOBAZ)
|
||||
context.stop()
|
||||
|
||||
assert self.readlines() == (
|
||||
'{"foo": "bar"}',
|
||||
'{"a": "A", "b": "B", "c": "C"}',
|
||||
'{"foo": "baz"}',
|
||||
)
|
||||
assert self.readlines() == ('{"foo": "bar"}', '{"a": "A", "b": "B", "c": "C"}', '{"foo": "baz"}')
|
||||
|
||||
@incontext()
|
||||
def test_nofields_empty_args(self, context):
|
||||
|
||||
@ -32,7 +32,4 @@ def test_read_pickled_list_from_file(tmpdir):
|
||||
|
||||
output = context.get_buffer()
|
||||
assert context.get_output_fields() == ('a', 'b', 'c')
|
||||
assert output == [
|
||||
('a foo', 'b foo', 'c foo'),
|
||||
('a bar', 'b bar', 'c bar'),
|
||||
]
|
||||
assert output == [('a foo', 'b foo', 'c foo'), ('a bar', 'b bar', 'c bar')]
|
||||
|
||||
@ -5,9 +5,9 @@ from unittest.mock import MagicMock
|
||||
import pytest
|
||||
|
||||
import bonobo
|
||||
from bonobo.constants import NOT_MODIFIED, EMPTY
|
||||
from bonobo.util import ensure_tuple, ValueHolder
|
||||
from bonobo.util.testing import BufferingNodeExecutionContext, StaticNodeTest, ConfigurableNodeTest
|
||||
from bonobo.constants import EMPTY, NOT_MODIFIED
|
||||
from bonobo.util import ValueHolder, ensure_tuple
|
||||
from bonobo.util.testing import BufferingNodeExecutionContext, ConfigurableNodeTest, StaticNodeTest
|
||||
|
||||
|
||||
class CountTest(StaticNodeTest, TestCase):
|
||||
@ -26,7 +26,7 @@ class CountTest(StaticNodeTest, TestCase):
|
||||
def test_execution(self):
|
||||
with self.execute() as context:
|
||||
context.write_sync(*([EMPTY] * 42))
|
||||
assert context.get_buffer() == [(42, )]
|
||||
assert context.get_buffer() == [(42,)]
|
||||
|
||||
|
||||
class IdentityTest(StaticNodeTest, TestCase):
|
||||
@ -98,14 +98,11 @@ def test_fixedwindow():
|
||||
|
||||
with BufferingNodeExecutionContext(bonobo.FixedWindow(2)) as context:
|
||||
context.write_sync(*range(9))
|
||||
assert context.get_buffer() == [(0, 1), (2, 3), (4, 5), (6, 7), (
|
||||
8,
|
||||
None,
|
||||
)]
|
||||
assert context.get_buffer() == [(0, 1), (2, 3), (4, 5), (6, 7), (8, None)]
|
||||
|
||||
with BufferingNodeExecutionContext(bonobo.FixedWindow(1)) as context:
|
||||
context.write_sync(*range(3))
|
||||
assert context.get_buffer() == [(0, ), (1, ), (2, )]
|
||||
assert context.get_buffer() == [(0,), (1,), (2,)]
|
||||
|
||||
|
||||
def test_methodcaller():
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from whistle import EventDispatcher
|
||||
|
||||
import bonobo
|
||||
from bonobo.execution import events
|
||||
from bonobo.execution.contexts.graph import GraphExecutionContext
|
||||
from bonobo.plugins.console import ConsoleOutputPlugin
|
||||
from whistle import EventDispatcher
|
||||
|
||||
|
||||
def test_register_unregister():
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
|
||||
from unittest.mock import sentinel
|
||||
|
||||
import pytest
|
||||
|
||||
from bonobo.constants import BEGIN
|
||||
from bonobo.structs import Graph
|
||||
|
||||
@ -48,24 +48,14 @@ def test_graph_add_chain():
|
||||
def test_graph_topological_sort():
|
||||
g = Graph()
|
||||
|
||||
g.add_chain(
|
||||
sentinel.a1,
|
||||
sentinel.a2,
|
||||
sentinel.a3,
|
||||
_input=None,
|
||||
_output=None,
|
||||
)
|
||||
g.add_chain(sentinel.a1, sentinel.a2, sentinel.a3, _input=None, _output=None)
|
||||
|
||||
assert g.topologically_sorted_indexes == (0, 1, 2)
|
||||
assert g[0] == sentinel.a1
|
||||
assert g[1] == sentinel.a2
|
||||
assert g[2] == sentinel.a3
|
||||
|
||||
g.add_chain(
|
||||
sentinel.b1,
|
||||
sentinel.b2,
|
||||
_output=sentinel.a2,
|
||||
)
|
||||
g.add_chain(sentinel.b1, sentinel.b2, _output=sentinel.a2)
|
||||
|
||||
assert g.topologically_sorted_indexes[-2:] == (1, 2)
|
||||
assert g.topologically_sorted_indexes.index(3) < g.topologically_sorted_indexes.index(4)
|
||||
|
||||
@ -19,7 +19,7 @@ from queue import Empty
|
||||
import pytest
|
||||
|
||||
from bonobo.constants import BEGIN, END
|
||||
from bonobo.errors import InactiveWritableError, InactiveReadableError
|
||||
from bonobo.errors import InactiveReadableError, InactiveWritableError
|
||||
from bonobo.structs.inputs import Input
|
||||
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ def generate_integers():
|
||||
|
||||
|
||||
def square(i):
|
||||
return i**2
|
||||
return i ** 2
|
||||
|
||||
|
||||
def results(f, context):
|
||||
|
||||
@ -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