Debian Codegraph @

petl/test/io/test_html_unicode.py

raw
1 # -*- coding: utf-8 -*-
2 from __future__ import absolute_import, print_function, division
3
4
5 import io
6 from tempfile import NamedTemporaryFile
7 from petl.test.helpers import eq_
8
9
10 from petl.io.html import tohtml
11
12
13 def test_tohtml():
14
15 # exercise function
16 tbl = ((u'name', u'id'),
17 (u'Արամ Խաչատրյան', 1),
18 (u'Johann Strauß', 2),
19 (u'Вагиф Сәмәдоғлу', 3),
20 (u'章子怡', 4))
21 fn = NamedTemporaryFile().name
22 tohtml(tbl, fn, encoding='utf-8', lineterminator='\n')
23
24 # check what it did
25 f = io.open(fn, mode='rt', encoding='utf-8', newline='')
26 actual = f.read()
27 expect = (
28 u"<table class='petl'>\n"
29 u"<thead>\n"
30 u"<tr>\n"
31 u"<th>name</th>\n"
32 u"<th>id</th>\n"
33 u"</tr>\n"
34 u"</thead>\n"
35 u"<tbody>\n"
36 u"<tr>\n"
37 u"<td>Արամ Խաչատրյան</td>\n"
38 u"<td style='text-align: right'>1</td>\n"
39 u"</tr>\n"
40 u"<tr>\n"
41 u"<td>Johann Strauß</td>\n"
42 u"<td style='text-align: right'>2</td>\n"
43 u"</tr>\n"
44 u"<tr>\n"
45 u"<td>Вагиф Сәмәдоғлу</td>\n"
46 u"<td style='text-align: right'>3</td>\n"
47 u"</tr>\n"
48 u"<tr>\n"
49 u"<td>章子怡</td>\n"
50 u"<td style='text-align: right'>4</td>\n"
51 u"</tr>\n"
52 u"</tbody>\n"
53 u"</table>\n"
54 )
55 eq_(expect, actual)