def test_content_from_granpa(self): cont = Content(name='test1') p = P()(Div()(cont)) p.inject(self.test_contents) self.assertEqual(list(cont.content), [ 1, ])
def test_content_from_parent(self): cont = Content(name='test1') d = Div()(cont) d.inject(self.test_contents) self.assertEqual(list(cont.content), [ 1, ])
def test_render(self): d = Div()(Content(name='test1')).inject(self.test_contents) self.assertEqual(Counter(d.render()), Counter('<div>1</div>')) d = Div()(Content(name='test1'), Content(name='test2')).inject(self.test_contents) self.assertEqual(Counter(d.render()), Counter('<div>11 2 3 test_string</div>')) d = Div()(Content(name='test1')).inject({'test1': Div()}) self.assertEqual(Counter(d.render()), Counter('<div><div></div></div>')) t_repr = Div()(Content(name='test21')) d = Div()(Content(name='test2', t_repr=t_repr)).inject(self.test_contents) self.assertEqual(Counter(d.render()), Counter('<div><div>1 2 3</div></div>'))
# -*- coding: utf-8 -*- from tempy import Html, Head, Title, Body, Div, Content, Br from tempy_templates.sw_characters import character page = Html()( Head()( Title()( 'Flaskr - SW' ) ), body=Body()( Div(klass='page')( 'All the Star Wars characters!', Br(), Content('characters', template=character) ) ) )
def test_copy(self): cont = Content(name='test', content='test') cont2 = copy(cont) self.assertEqual(cont, cont2)
def test_eq(self): self.assertEqual(Content(name='test'), Content(name='test')) self.assertNotEqual(Content(name='test'), Div)
def test_init(self): with self.assertRaises(ContentError): Content() cont = Content(name='test') self.assertEqual(cont._name, 'test') cont = Content(content='test') self.assertEqual(list(cont.content), ['test', ]) cont = Content(content=['test']) self.assertEqual(list(cont.content), ['test', ]) cont = Content(content=('test')) self.assertEqual(list(cont.content), ['test', ]) c = (i for i in (1, 2, 3)) cont = Content(content=c) self.assertEqual(list(cont.content), [1, 2, 3]) cont = Content(content=('test', )) self.assertEqual(list(cont.content), ['test', ]) cont = Content(content=1) self.assertEqual(list(cont.content), [1, ]) self.assertEqual(cont.length, 1) cont = Content(content={'test': 'test'}) self.assertEqual(list(cont.content), [{'test': 'test'}, ]) cont = Content(name='test', t_repr=Div()) self.assertEqual(cont._t_repr, Div()) with self.assertRaises(ContentError): Content(name='test', t_repr='wrong')
def test_repr(self): c = Content(name='test') self.assertEqual(len(str(c)), len('<tempy.elements.Content 97fa6e42-bb6e-4d9b-8bad-872405209148. Named test>'))
def test_repr(self): c = Content(name='test') id_of_c = id(c) self.assertEqual(len(str(c)), len('<tempy.content.Content %s. Named test>' % id_of_c))
# -*- coding: utf-8 -*- from tempy import Html, Head, Title, Body, Div, Content, Br, B, P character = Div(klass='chr')( B()(Content('name')), P()('height:', Content('height')), P()('mass:', Content('mass')), P()('hair_color:', Content('hair_color')), P()('skin_color:', Content('skin_color')), P()('eye_color:', Content('eye_color')), P()('birth_year:', Content('birth_year')), P()('gender:', Content('gender')), P()('homeworld:', Content('homeworld')), P()('created:', Content('created')), P()('edited:', Content('edited')), P()('url:', Content('url')), ) page = Html()(Head()(Title()('Flaskr - SW')), body=Body()(Div(klass='page')('All the Star Wars characters!', Br(), Content('characters', template=character))))