File: test_json_unicode.py

package info (click to toggle)
python-petl 1.7.17-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,224 kB
  • sloc: python: 22,617; makefile: 109; xml: 9
file content (31 lines) | stat: -rw-r--r-- 744 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, division


import json
from tempfile import NamedTemporaryFile


from petl.test.helpers import ieq
from petl.io.json import tojson, fromjson


def test_json_unicode():

    tbl = ((u'id', u'name'),
           (1, u'Արամ Խաչատրյան'),
           (2, u'Johann Strauß'),
           (3, u'Вагиф Сәмәдоғлу'),
           (4, u'章子怡'),
           )
    fn = NamedTemporaryFile().name
    tojson(tbl, fn)

    result = json.load(open(fn))
    assert len(result) == 4
    for a, b in zip(tbl[1:], result):
        assert a[0] == b['id']
        assert a[1] == b['name']

    actual = fromjson(fn, header=['id', 'name'])
    ieq(tbl, actual)