示例#1
0
文件: html.py 项目: hanotch/trac
 def test_tag(self):
     self.assertEqual(Markup('0<a>0</a> and <b>0</b> and <c></c>'
                             ' and <d class="a b" more_="[\'a\']"></d>'),
                      Markup(tag(0, tag.a(0, href=''), b' and ', tag.b(0.0),
                                 ' and ', tag.c(None), ' and ',
                                 tag.d('', class_=['a', '', 'b'],
                                       more__=[b'a']))))
示例#2
0
 def _test_add_message_escapes_markup(self, msgtype, add_fn):
     req = MockRequest(self.env)
     add_fn(req, 'Message with an "&"')
     add_fn(req, Exception("Exception message with an &"))
     add_fn(req, tag("Message with text ", tag.b("& markup")))
     add_fn(req, Markup("Markup <strong>message</strong>."))
     messages = req.chrome[msgtype]
     self.assertIn('Message with an "&amp;"', messages)
     self.assertIn("Exception message with an &amp;", messages)
     self.assertIn("Message with text <b>&amp; markup</b>", messages)
     self.assertIn("Markup <strong>message</strong>.", messages)
示例#3
0
 def render(context, field, event):
     if event[0] == 'test&1':
         if field == 'url':
             return 'http://example.org/path?foo=bar&baz=1'
         if field == 'summary':
             return 'summary 1: <b>&</b>'
         if field == 'description':
             return tag(tag.h1('Title 1st'), tag.p('body & < >'))
     if event[0] == 'test&2':
         if field == 'url':
             return 'http://example.org/path?baz=2&foo=bar'
         if field == 'summary':
             return tag('summary 2: ', tag.b('&'))
         if field == 'description':
             return tag(tag.h1('Title 2nd'), tag.p('body & < >'))
示例#4
0
 def test_fragment_with_unicode_as_argument(self):
     e = HTTPInternalServerError(tag.b(u'thé méssägé'))
     self.assertEqual(u'500 Internal Server Error (<b>thé méssägé</b>)',
                      unicode(e))
示例#5
0
 def test_exception_with_fragment_as_argument(self):
     e1 = Exception(tag(tag.b('the message')))
     e2 = HTTPInternalServerError(e1)
     self.assertEqual('500 Internal Server Error (<b>the message</b>)',
                      unicode(e2))
示例#6
0
 def test_tracerror_with_fragment_as_argument(self):
     e1 = TracError(tag(tag.b('the message')))
     e2 = HTTPInternalServerError(e1)
     self.assertEqual('500 Trac Error (<b>the message</b>)', unicode(e2))
示例#7
0
 def test_str(self):
     self.assertEqual(b'<b>M</b>ess\xc3\xa4ge',
                      str(tag(tag.b('M'), 'essäge')))
示例#8
0
 def test_unicode(self):
     self.assertEqual('<b>M</b>essäge', unicode(tag(tag.b('M'), 'essäge')))
示例#9
0
 def test_zeros(self):
     self.assertEqual(Markup('0<b>0</b> and <b>0</b>'),
                      Markup(tag(0, tag.b(0), ' and ', tag.b(0.0))))
示例#10
0
 def test_error_with_error_with_fragment(self):
     v1 = ValueError(tag('invalid literal for int(): ', tag.b('blah')))
     rv = to_fragment(ValueError(v1))
     self.assertEqual(Fragment, type(rv))
     self.assertEqual('invalid literal for int(): <b>blah</b>', unicode(rv))
示例#11
0
 def test_escape_fragment(self):
     self.assertEqual(Markup('<b class="em&#34;ph&#34;">"1 &lt; 2"</b>'),
                      escape(tag(tag.b('"1 < 2"', class_='em"ph"'))))
     self.assertEqual(
         Markup('<b class="em&#34;ph&#34;">"1 &lt; 2"</b>'),
         escape(tag(tag.b('"1 < 2"', class_='em"ph"')), quotes=False))
示例#12
0
 def test_str(self):
     self.assertEqual(b'<b>M<em>ess\xc3\xa4ge</em></b>',
                      str(tag.b('M', tag.em('essäge'))))
示例#13
0
 def test_unicode(self):
     self.assertEqual('<b>M<em>essäge</em></b>',
                      unicode(tag.b('M', tag.em('essäge'))))