def test_pop_row(self): table = TempyTable(data=self.data) # test pop last r = table.pop_row() self.assertEqual(r, self.data[-1]) # test pop get tags r = table.pop_row(tags=True) test_row = Tr()(Td()(c) for c in self.data[-2]) for cell, t_cell in zip(r, test_row): self.assertEqual(cell, t_cell) # test pop by index r = table.pop_row(0) self.assertEqual(r, self.data[0])
def test_pop_cell(self): table = TempyTable(data=self.data) # test pop last r = table.pop_cell() self.assertEqual(r, self.data[-1][-1]) # test pop get tags r = table.pop_cell(tags=True) test_cell = Td()(self.data[-2][-1]) self.assertEqual(r, test_cell) # test pop by index row r = table.pop_cell(0) self.assertEqual(r, self.data[0][-1]) # test pop by index row andcol r = table.pop_cell(0, 0) self.assertEqual(r, self.data[0][0])
def repr(self): self( Td()(self.contact_type.title()), Td()(self.value) )
def repr(self): self(Tr()(Td()(row[0]), Td()(row[1])) for row in self.rows)
def test_map(self): tag = Td() list_ele = ['foo', 'Br', 'Div', 'Pre'] result = tag.map(list_ele) self.assertEqual(len(result), 4)
import cProfile import pstats from io import StringIO from tempy.tags import Table, Tr, Td, Div from tempy.widgets import TempyPage TABLE_DATA = [ dict(a='a', b='b', c='c', d='d', e='e', f='f', g='g', h='h', i='i', j='k') for x in range(100) ] page = TempyPage() pr = cProfile.Profile() pr.enable() for _ in range(100): page.body(Div()(table=Table()(Tr(id='%s' % i)( Td(klass='CIAO', id='%s-%s' % (i, td))(cont=td) for td in tr.values()) for i, tr in enumerate(TABLE_DATA)))) pr.disable() s = StringIO() sortby = 'tottime' ps = pstats.Stats(pr, stream=s).sort_stats(sortby) print('*' * 200) print('CREATION') ps.print_stats() print(s.getvalue()) pr = cProfile.Profile() pr.enable() _ = page.render() pr.disable() s = StringIO()