style: switching from yapf to isort/black
This commit is contained in:
@ -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):
|
||||
|
||||
Reference in New Issue
Block a user