Refactoring and fixes around ioformats.
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import pytest
|
||||
|
||||
from bonobo import Bag, CsvReader, CsvWriter, open_fs
|
||||
from bonobo import Bag, CsvReader, CsvWriter, open_fs, settings
|
||||
from bonobo.constants import BEGIN, END
|
||||
from bonobo.execution.node import NodeExecutionContext
|
||||
from bonobo.util.testing import CapturingNodeExecutionContext
|
||||
@ -9,7 +9,7 @@ from bonobo.util.testing import CapturingNodeExecutionContext
|
||||
def test_write_csv_to_file(tmpdir):
|
||||
fs, filename = open_fs(tmpdir), 'output.csv'
|
||||
|
||||
writer = CsvWriter(path=filename)
|
||||
writer = CsvWriter(path=filename, ioformat=settings.IOFORMAT_ARG0)
|
||||
context = NodeExecutionContext(writer, services={'fs': fs})
|
||||
|
||||
context.write(BEGIN, Bag({'foo': 'bar'}), Bag({'foo': 'baz', 'ignore': 'this'}), END)
|
||||
@ -19,7 +19,7 @@ def test_write_csv_to_file(tmpdir):
|
||||
context.step()
|
||||
context.stop()
|
||||
|
||||
with fs.open(filename)as fp:
|
||||
with fs.open(filename) as fp:
|
||||
assert fp.read() == 'foo\nbar\nbaz\n'
|
||||
|
||||
with pytest.raises(AttributeError):
|
||||
@ -31,7 +31,7 @@ def test_read_csv_from_file(tmpdir):
|
||||
with fs.open(filename, 'w') as fp:
|
||||
fp.write('a,b,c\na foo,b foo,c foo\na bar,b bar,c bar')
|
||||
|
||||
reader = CsvReader(path=filename, delimiter=',')
|
||||
reader = CsvReader(path=filename, delimiter=',', ioformat=settings.IOFORMAT_ARG0)
|
||||
|
||||
context = CapturingNodeExecutionContext(reader, services={'fs': fs})
|
||||
|
||||
@ -64,7 +64,7 @@ def test_read_csv_kwargs_output_formater(tmpdir):
|
||||
with fs.open(filename, 'w') as fp:
|
||||
fp.write('a,b,c\na foo,b foo,c foo\na bar,b bar,c bar')
|
||||
|
||||
reader = CsvReader(path=filename, delimiter=',', output_format='kwargs')
|
||||
reader = CsvReader(path=filename, delimiter=',')
|
||||
|
||||
context = CapturingNodeExecutionContext(reader, services={'fs': fs})
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import pytest
|
||||
|
||||
from bonobo import Bag, JsonReader, JsonWriter, open_fs
|
||||
from bonobo import Bag, JsonReader, JsonWriter, open_fs, settings
|
||||
from bonobo.constants import BEGIN, END
|
||||
from bonobo.execution.node import NodeExecutionContext
|
||||
from bonobo.util.testing import CapturingNodeExecutionContext
|
||||
@ -9,7 +9,7 @@ from bonobo.util.testing import CapturingNodeExecutionContext
|
||||
def test_write_json_to_file(tmpdir):
|
||||
fs, filename = open_fs(tmpdir), 'output.json'
|
||||
|
||||
writer = JsonWriter(path=filename)
|
||||
writer = JsonWriter(filename, ioformat=settings.IOFORMAT_ARG0)
|
||||
context = NodeExecutionContext(writer, services={'fs': fs})
|
||||
|
||||
context.start()
|
||||
@ -31,7 +31,7 @@ def test_read_json_from_file(tmpdir):
|
||||
fs, filename = open_fs(tmpdir), 'input.json'
|
||||
with fs.open(filename, 'w') as fp:
|
||||
fp.write('[{"x": "foo"},{"x": "bar"}]')
|
||||
reader = JsonReader(path=filename)
|
||||
reader = JsonReader(filename, ioformat=settings.IOFORMAT_ARG0)
|
||||
|
||||
context = CapturingNodeExecutionContext(reader, services={'fs': fs})
|
||||
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import pickle
|
||||
|
||||
import pytest
|
||||
|
||||
from bonobo import Bag, PickleReader, PickleWriter, open_fs
|
||||
from bonobo import Bag, PickleReader, PickleWriter, open_fs, settings
|
||||
from bonobo.constants import BEGIN, END
|
||||
from bonobo.execution.node import NodeExecutionContext
|
||||
from bonobo.util.testing import CapturingNodeExecutionContext
|
||||
@ -10,7 +11,7 @@ from bonobo.util.testing import CapturingNodeExecutionContext
|
||||
def test_write_pickled_dict_to_file(tmpdir):
|
||||
fs, filename = open_fs(tmpdir), 'output.pkl'
|
||||
|
||||
writer = PickleWriter(path=filename)
|
||||
writer = PickleWriter(filename, ioformat=settings.IOFORMAT_ARG0)
|
||||
context = NodeExecutionContext(writer, services={'fs': fs})
|
||||
|
||||
context.write(BEGIN, Bag({'foo': 'bar'}), Bag({'foo': 'baz', 'ignore': 'this'}), END)
|
||||
@ -32,7 +33,7 @@ def test_read_pickled_list_from_file(tmpdir):
|
||||
with fs.open(filename, 'wb') as fp:
|
||||
fp.write(pickle.dumps([['a', 'b', 'c'], ['a foo', 'b foo', 'c foo'], ['a bar', 'b bar', 'c bar']]))
|
||||
|
||||
reader = PickleReader(path=filename)
|
||||
reader = PickleReader(filename, ioformat=settings.IOFORMAT_ARG0)
|
||||
|
||||
context = CapturingNodeExecutionContext(reader, services={'fs': fs})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user