def test_make_json_writer_with_unicode(): fp = StringIO() writer = make_json_writer(lambda: {u'ùñï©ôð€': u'εvεrywhεrε'}) writer(fp) expected = u'{\n "ùñï©ôð€": "εvεrywhεrε"\n}' if PY2: expected = expected.encode('utf-8') assert fp.getvalue() == expected
def test_make_json_writer_with_args(): fp = StringIO() writer = make_json_writer(lambda x: {'foo': x}, 23) writer(fp) assert fp.getvalue() == '{\n "foo": 23\n}'
def test_make_json_writer_with_kwargs(): fp = StringIO() writer = make_json_writer(lambda foo=None: {'foo': foo}, foo='bar') writer(fp) assert fp.getvalue() == '{\n "foo": "bar"\n}'
def test_make_json_writer(): fp = StringIO() writer = make_json_writer(lambda: {'foo': 42}) writer(fp) assert fp.getvalue() == '{\n "foo": 42\n}'
def test_make_json_writer_with_unicode(): fp = StringIO() writer = make_json_writer(lambda: {'ùñï©ôð€': 'εvεrywhεrε'}) writer(fp) expected = '{\n "ùñï©ôð€": "εvεrywhεrε"\n}' assert fp.getvalue() == expected