Exemple #1
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)
Exemple #2
0
def test_tohtml():

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

    # check what it did
    with open(f.name, 'rb') as o:
        actual = o.read()
        expect = """<table>
<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)
Exemple #3
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>
<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)
Exemple #4
0
def test_tohtml():
    
    # exercise function
    table = (('foo', 'bar'),
             ('a', 1),
             ('b', 2))
    f = NamedTemporaryFile(delete=False)
    tohtml(table, f.name)
    
    # check what it did
    with open(f.name, 'rb') as o:
        actual = o.read()
        expect = """<table>
<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 style='text-align: right'>2</td>
</tr>
</tbody>
</table>
"""
        eq_(expect, actual)
Exemple #5
0
def get_load_result(nameFile):

    table1 = etl.fromjson('./static/data/tabalaElegidaCalculadora.json')
    tocsv(table1, './exelFiles/' + str(nameFile) + '.csv')
    etl.tohtml(table1,
               './exelFiles/' + str(nameFile) + '.html',
               caption=str(nameFile))
    return jsonify(True)
Exemple #6
0
def test_stdoutsource_unicode():

    tbl = [('foo', 'bar'),
           (u'Արամ Խաչատրյան', 1),
           (u'Johann Strauß', 2)]
    etl.tocsv(tbl, StdoutSource(), encoding='utf-8')
    etl.tohtml(tbl, StdoutSource(), encoding='utf-8')
    etl.topickle(tbl, StdoutSource())
Exemple #7
0
    def to_html(self,
                local_path=None,
                encoding=None,
                errors='strict',
                index_header=False,
                caption=None,
                tr_style=None,
                td_styles=None,
                truncate=None):
        """
        Outputs table to html.

        .. warning::
                If a file already exists at the given location, it will be
                overwritten.

        `Args:`
            local_path: str
                The path to write the html locally. If not specified, a temporary file will be
                created and returned, and that file will be removed automatically when the script
                is done running.
            encoding: str
                The encoding type for `csv.writer()
                <https://docs.python.org/2/library/csv.html#csv.writer/>`_
            errors: str
                Raise an Error if encountered
            index_header: boolean
                Prepend index to column names; Defaults to False.
            caption: str
                A caption to include with the html table.
            tr_style: str or callable
                Style to be applied to the table row.
            td_styles: str, dict or callable
                Styles to be applied to the table cells.
            truncate: int
                Length of cell data.
        `Returns:`
            str
                The path of the new file
        """

        if not local_path:
            local_path = files.create_temp_file(suffix=".html")

        petl.tohtml(self.table,
                    source=local_path,
                    encoding=encoding,
                    errors=errors,
                    caption=caption,
                    index_header=index_header,
                    tr_style=tr_style,
                    td_styles=td_styles,
                    truncate=truncate)

        return local_path
Exemple #8
0
from __future__ import division, print_function, absolute_import


# tohtml()
##########


import petl as etl
table1 = [['foo', 'bar'],
          ['a', 1],
          ['b', 2],
          ['c', 2]]
etl.tohtml(table1, 'example.html', caption='example table')
print(open('example.html').read())
Exemple #9
0
from __future__ import division, print_function, absolute_import

# tohtml()
##########

import petl as etl
table1 = [['foo', 'bar'], ['a', 1], ['b', 2], ['c', 2]]
etl.tohtml(table1, 'example.html', caption='example table')
print(open('example.html').read())
Exemple #10
0
def test_stdoutsource_unicode():

    tbl = [('foo', 'bar'), (u'Արամ Խաչատրյան', 1), (u'Johann Strauß', 2)]
    etl.tocsv(tbl, StdoutSource(), encoding='utf-8')
    etl.tohtml(tbl, StdoutSource(), encoding='utf-8')
    etl.topickle(tbl, StdoutSource())
Exemple #11
0
def test_stdoutsource():

    tbl = [('foo', 'bar'), ('a', 1), ('b', 2)]
    etl.tocsv(tbl, StdoutSource(), encoding='ascii')
    etl.tohtml(tbl, StdoutSource(), encoding='ascii')
    etl.topickle(tbl, StdoutSource())
Exemple #12
0
def test_stdoutsource():

    tbl = [('foo', 'bar'), ('a', 1), ('b', 2)]
    etl.tocsv(tbl, StdoutSource(), encoding='ascii')
    etl.tohtml(tbl, StdoutSource(), encoding='ascii')
    etl.topickle(tbl, StdoutSource())
Exemple #13
0
def get_html_data(csv_data):
    petl.tohtml(csv_data, HTML_TABLE_FILE)
    with open(HTML_TABLE_FILE, 'r') as f:
        html_data = f.read()
    return html_data