Пример #1
0
def _display_html(table, limit=0, vrepr=None, index_header=None, caption=None,
                  tr_style=None, td_styles=None, encoding=None,
                  truncate=None, epilogue=None):

    # determine defaults
    if limit == 0:
        limit = config.display_limit
    if vrepr is None:
        vrepr = config.display_vrepr
    if index_header is None:
        index_header = config.display_index_header
    if encoding is None:
        encoding = locale.getpreferredencoding()

    table, overflow = _vis_overflow(table, limit)
    buf = MemorySource()
    tohtml(table, buf, encoding=encoding, index_header=index_header,
           vrepr=vrepr, caption=caption, tr_style=tr_style,
           td_styles=td_styles, truncate=truncate)
    output = text_type(buf.getvalue(), encoding)

    if epilogue:
        output += '<p>%s</p>' % epilogue
    elif overflow:
        output += '<p><strong>...</strong></p>'

    return output
Пример #2
0
def test_tohtml_caption():

    # exercise function
    table = (('foo', 'bar'),
             ('a', 1),
             ('b', (1, 2)))
    f = NamedTemporaryFile(delete=False)
    tohtml(table, f.name, caption='my table', lineterminator='\n')

    # check what it did
    with open(f.name, 'rb') as o:
        actual = o.read()
        expect = """<table class='petl'>
<caption>my table</caption>
<thead>
<tr>
<th>foo</th>
<th>bar</th>
</tr>
</thead>
<tbody>
<tr>
<td>a</td>
<td style='text-align: right'>1</td>
</tr>
<tr>
<td>b</td>
<td>(1, 2)</td>
</tr>
</tbody>
</table>
"""
        eq_(expect, actual)
Пример #3
0
def test_tohtml_caption():

    # exercise function
    table = (('foo', 'bar'),
             ('a', 1),
             ('b', (1, 2)))
    f = NamedTemporaryFile(delete=False)
    tohtml(table, f.name, encoding='ascii', caption='my table',
           lineterminator='\n')

    # check what it did
    with io.open(f.name, mode='rt', encoding='ascii', newline='') as o:
        actual = o.read()
        expect = (
            u"<table class='petl'>\n"
            u"<caption>my table</caption>\n"
            u"<thead>\n"
            u"<tr>\n"
            u"<th>foo</th>\n"
            u"<th>bar</th>\n"
            u"</tr>\n"
            u"</thead>\n"
            u"<tbody>\n"
            u"<tr>\n"
            u"<td>a</td>\n"
            u"<td style='text-align: right'>1</td>\n"
            u"</tr>\n"
            u"<tr>\n"
            u"<td>b</td>\n"
            u"<td>(1, 2)</td>\n"
            u"</tr>\n"
            u"</tbody>\n"
            u"</table>\n"
        )
        eq_(expect, actual)
Пример #4
0
def test_tohtml_caption():

    # exercise function
    table = (('foo', 'bar'), ('a', 1), ('b', (1, 2)))
    f = NamedTemporaryFile(delete=False)
    tohtml(table, f.name, caption='my table', lineterminator='\n')

    # check what it did
    with open(f.name, 'rb') as o:
        actual = o.read()
        expect = """<table class='petl'>
<caption>my table</caption>
<thead>
<tr>
<th>foo</th>
<th>bar</th>
</tr>
</thead>
<tbody>
<tr>
<td>a</td>
<td style='text-align: right'>1</td>
</tr>
<tr>
<td>b</td>
<td>(1, 2)</td>
</tr>
</tbody>
</table>
"""
        eq_(expect, actual)
Пример #5
0
def test_tohtml():

    # exercise function
    tbl = ((u'name', u'id'),
           (u'Արամ Խաչատրյան', 1),
           (u'Johann Strauß', 2),
           (u'Вагиф Сәмәдоғлу', 3),
           (u'章子怡', 4))
    fn = NamedTemporaryFile().name
    tohtml(tbl, fn, encoding='utf-8', lineterminator='\n')

    # check what it did
    f = io.open(fn, mode='rt', encoding='utf-8', newline='')
    actual = f.read()
    expect = (
        u"<table class='petl'>\n"
        u"<thead>\n"
        u"<tr>\n"
        u"<th>name</th>\n"
        u"<th>id</th>\n"
        u"</tr>\n"
        u"</thead>\n"
        u"<tbody>\n"
        u"<tr>\n"
        u"<td>Արամ Խաչատրյան</td>\n"
        u"<td style='text-align: right'>1</td>\n"
        u"</tr>\n"
        u"<tr>\n"
        u"<td>Johann Strauß</td>\n"
        u"<td style='text-align: right'>2</td>\n"
        u"</tr>\n"
        u"<tr>\n"
        u"<td>Вагиф Сәмәдоғлу</td>\n"
        u"<td style='text-align: right'>3</td>\n"
        u"</tr>\n"
        u"<tr>\n"
        u"<td>章子怡</td>\n"
        u"<td style='text-align: right'>4</td>\n"
        u"</tr>\n"
        u"</tbody>\n"
        u"</table>\n"
    )
    eq_(expect, actual)
Пример #6
0
def test_tohtml():

    # exercise function
    tbl = ((u'name', u'id'), (u'Արամ Խաչատրյան', 1), (u'Johann Strauß', 2),
           (u'Вагиф Сәмәдоғлу', 3), (u'章子怡', 4))
    fn = NamedTemporaryFile().name
    tohtml(tbl, fn, encoding='utf-8', lineterminator='\n')

    # check what it did
    f = io.open(fn, mode='rt', encoding='utf-8', newline='')
    actual = f.read()
    expect = (u"<table class='petl'>\n"
              u"<thead>\n"
              u"<tr>\n"
              u"<th>name</th>\n"
              u"<th>id</th>\n"
              u"</tr>\n"
              u"</thead>\n"
              u"<tbody>\n"
              u"<tr>\n"
              u"<td>Արամ Խաչատրյան</td>\n"
              u"<td style='text-align: right'>1</td>\n"
              u"</tr>\n"
              u"<tr>\n"
              u"<td>Johann Strauß</td>\n"
              u"<td style='text-align: right'>2</td>\n"
              u"</tr>\n"
              u"<tr>\n"
              u"<td>Вагиф Сәмәдоғлу</td>\n"
              u"<td style='text-align: right'>3</td>\n"
              u"</tr>\n"
              u"<tr>\n"
              u"<td>章子怡</td>\n"
              u"<td style='text-align: right'>4</td>\n"
              u"</tr>\n"
              u"</tbody>\n"
              u"</table>\n")
    eq_(expect, actual)