Debian Codegraph @

petl/test/test_interactive.py

raw
1 from __future__ import absolute_import, print_function, division
2
3
4 import petl as etl
5 from petl.test.helpers import eq_
6
7
8 def test_repr():
9 table = (('foo', 'bar'),
10 ('a', 1),
11 ('b', 2),
12 ('c', 2))
13 expect = str(etl.look(table))
14 actual = repr(etl.wrap(table))
15 eq_(expect, actual)
16
17
18 def test_str():
19 table = (('foo', 'bar'),
20 ('a', 1),
21 ('b', 2),
22 ('c', 2))
23 expect = str(etl.look(table, vrepr=str))
24 actual = str(etl.wrap(table))
25 eq_(expect, actual)
26
27
28 def test_repr_html():
29 table = (('foo', 'bar'),
30 ('a', 1),
31 ('b', 2),
32 ('c', 2))
33 expect = """<table class='petl'>
34 <thead>
35 <tr>
36 <th>foo</th>
37 <th>bar</th>
38 </tr>
39 </thead>
40 <tbody>
41 <tr>
42 <td>a</td>
43 <td style='text-align: right'>1</td>
44 </tr>
45 <tr>
46 <td>b</td>
47 <td style='text-align: right'>2</td>
48 </tr>
49 <tr>
50 <td>c</td>
51 <td style='text-align: right'>2</td>
52 </tr>
53 </tbody>
54 </table>
55 """
56 actual = etl.wrap(table)._repr_html_()
57 for l1, l2 in zip(expect.split('\n'), actual.split('\n')):
58 eq_(l1, l2)
59
60
61 def test_repr_html_limit():
62 table = (('foo', 'bar'),
63 ('a', 1),
64 ('b', 2),
65 ('c', 2))
66
67 # lower limit
68 etl.config.display_limit = 2
69
70 expect = """<table class='petl'>
71 <thead>
72 <tr>
73 <th>foo</th>
74 <th>bar</th>
75 </tr>
76 </thead>
77 <tbody>
78 <tr>
79 <td>a</td>
80 <td style='text-align: right'>1</td>
81 </tr>
82 <tr>
83 <td>b</td>
84 <td style='text-align: right'>2</td>
85 </tr>
86 </tbody>
87 </table>
88 <p><strong>...</strong></p>
89 """
90 actual = etl.wrap(table)._repr_html_()
91 print(actual)
92 for l1, l2 in zip(expect.split('\n'), actual.split('\n')):
93 eq_(l1, l2)