Beispiel #1
0
 def test_create(self):
     page = TempyPage()
     self.assertIsInstance(page, Html)
     self.assertEqual(len(page), 2)
     self.assertIsInstance(page.head, Head)
     self.assertIsInstance(page.body, Body)
     self.assertEqual(len(page.head.title), 0)
     self.assertEqual(page.head.charset.attrs['charset'], 'UTF-8')
Beispiel #2
0
 def test_title(self):
     page = TempyPage()
     page.set_title('test title')
     self.assertEqual(page.head.title.attrs['content'], 'test title')
Beispiel #3
0
 def test_doctype(self):
     page = TempyPage()
     page.set_doctype('html_strict')
     charset_string = 'HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"'
     self.assertTrue(charset_string in page.render())
Beispiel #4
0
 def test_keywords(self):
     page = TempyPage()
     kw = ['test', 'foo', 'bar']
     page.set_keywords(kw)
     self.assertEqual(page.head.keywords.attrs['content'], ', '.join(kw))
Beispiel #5
0
 def test_description(self):
     page = TempyPage()
     page.set_description('test page')
     self.assertEqual(page.head.description.attrs['content'], 'test page')
Beispiel #6
0
 def test_charset(self):
     page = TempyPage()
     self.assertEqual(page.head.charset.attrs['charset'], 'UTF-8')
     page.set_charset('text/html;charset=ISO-8859-1')
     self.assertEqual(page.head.charset.attrs['charset'],
                      'text/html;charset=ISO-8859-1')
Beispiel #7
0
 def test_title(self):
     page = TempyPage()
     page.set_title('test title')
     self.assertEqual(page.head.title.childs[-1], 'test title')
Beispiel #8
0
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()