still testing

This commit is contained in:
Romain Dorgueil
2016-12-26 08:57:39 +01:00
parent 1fbd43a94d
commit 8903e1d386
5 changed files with 85 additions and 2 deletions

37
tests/io/test_json.py Normal file
View File

@ -0,0 +1,37 @@
import pytest
from bonobo import to_json
from bonobo.util.lifecycle import get_initializer, get_finalizer
class ContextMock:
pass
def test_write_json_to_file(tmpdir):
file = tmpdir.join('output.json')
json_writer = to_json(file)
context = ContextMock()
get_initializer(json_writer)(context)
json_writer(context, {'foo': 'bar'})
get_finalizer(json_writer)(context)
assert file.read() == '''[
{"foo": "bar"}
]'''
with pytest.raises(AttributeError):
getattr(context, 'fp')
with pytest.raises(AttributeError):
getattr(context, 'first')
def test_write_json_without_initializer_should_not_work(tmpdir):
file = tmpdir.join('output.json')
json_writer = to_json(file)
context = ContextMock()
with pytest.raises(AttributeError):
json_writer(context, {'foo': 'bar'})