Exemple #1
0
    def test_csv01(self):
        mydata = [[11,12],[21,22]]
        myheaders = [ "Column 1", "Column 2" ]
        mystubs = [ "Row 1", "Row 2" ]
        tbl = SimpleTable(mydata, myheaders, mystubs, title="Title")
        actual = '%s' % tbl.as_csv().strip()
        desired = """
         Title         
     ,Column 1,Column 2
Row 1,11      ,12      
Row 2,21      ,22      
""".strip()
        self.assertEqual(actual, desired)
Exemple #2
0
    def test_csv01(self):
        mydata = [[11, 12], [21, 22]]
        myheaders = ["Column 1", "Column 2"]
        mystubs = ["Row 1", "Row 2"]
        tbl = SimpleTable(mydata, myheaders, mystubs, title="Title")
        actual = '%s' % tbl.as_csv().strip()
        desired = """
         Title         
     ,Column 1,Column 2
Row 1,11      ,12      
Row 2,21      ,22      
""".strip()
        self.assertEqual(actual, desired)
Exemple #3
0
    def test_customlabel(self):
        """Limited test of custom custom labeling"""
        if has_numpy:
            tbl = SimpleTable(table1data, test1header, test1stubs, txt_fmt=txt_fmt1)
            tbl[1][1].data = np.nan
            tbl.label_cells(custom_labeller)
            print([[c.datatype for c in row] for row in tbl])
            desired = """
*****************************
*       * header1 * header2 *
*****************************
* stub1 *    --   *       1 *
* stub2 *    2.00 *       3 *
*****************************
"""
            actual = '\n%s\n' % tbl.as_text(missing='--')
            print(actual)
            print(desired)
            self.assertEqual(actual, desired)
Exemple #4
0
    def test_customlabel(self):
        """Limited test of custom custom labeling"""
        if has_numpy:
            tbl = SimpleTable(table1data,
                              test1header,
                              test1stubs,
                              txt_fmt=txt_fmt1)
            tbl[1][1].data = np.nan
            tbl.label_cells(custom_labeller)
            print([[c.datatype for c in row] for row in tbl])
            desired = """
*****************************
*       * header1 * header2 *
*****************************
* stub1 *    --   *       1 *
* stub2 *    2.00 *       3 *
*****************************
"""
            actual = '\n%s\n' % tbl.as_text(missing='--')
            print(actual)
            print(desired)
            self.assertEqual(actual, desired)
Exemple #5
0
                title_align='r',
                header_align='r',
                data_aligns="r",
                stubs_align="l",
                fmt='txt')
cell0data = 0.0000
cell1data = 1
row0data = [cell0data, cell1data]
row1data = [2, 3.333]
table1data = [row0data, row1data]
test1stubs = ('stub1', 'stub2')
test1header = ('header1', 'header2')
#test1header = ('header1\nheader1a', 'header2\nheader2a')
tbl = SimpleTable(table1data,
                  test1header,
                  test1stubs,
                  txt_fmt=txt_fmt1,
                  ltx_fmt=ltx_fmt1,
                  html_fmt=html_fmt1)


def custom_labeller(cell):
    if cell.data is np.nan:
        return 'missing'


class test_Cell(unittest.TestCase):
    def test_celldata(self):
        celldata = cell0data, cell1data, row1data[0], row1data[1]
        cells = [
            Cell(datum, datatype=i % 2) for i, datum in enumerate(celldata)
        ]
Exemple #6
0
        if k['value'] > .5:
            res.append([
                coinNames[j.upper()] + ' (' + j.upper() + ')',
                round(k['amount'], 4),
                str(round(k['price'], 3)) + ' €',
                str(round(k['value'], 2)) + ' €'
            ])
    res.sort(key=lambda x: x[0])
    res.append([
        dt.datetime.fromtimestamp(round(i['timestamp'], 0)), '', '',
        str(round(i['value'], 2)) + ' €'
    ])
    totalValue += i['value']
    page.add_table(
        SimpleTable([['Coinname', 'Amount', 'Market Price', 'Value']] + res,
                    header_row=[name],
                    css_class='mytable',
                    header_colspan=4))
page.add_table(
    SimpleTable(
        [['Combined Value: ', '<b>' + str(round(totalValue, 2)) + ' €</b>']],
        css_class='mytable2'))
css = """
table.mytable {
    font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
    border-collapse: collapse;
    width=100%;
	margin=0;
    border: 1px solid #ddd;
}
table.mytable th, td {
    padding: 9px;