comparison test/test_templating.py @ 6097:90a1470edbea

added markdown rendering support using either markdown2 or markdown
author Christof Meerwald <cmeerw@cmeerw.org>
date Thu, 20 Feb 2020 19:30:26 +0000
parents c914b3d8362f
children 72a281a55a17
comparison
equal deleted inserted replaced
6096:c914b3d8362f 6097:90a1470edbea
26 skip_stext = lambda func, *args, **kwargs: func 26 skip_stext = lambda func, *args, **kwargs: func
27 except ImportError: 27 except ImportError:
28 StructuredText = None 28 StructuredText = None
29 skip_stext = mark_class(pytest.mark.skip( 29 skip_stext = mark_class(pytest.mark.skip(
30 reason='StructuredText not available')) 30 reason='StructuredText not available'))
31
32 try:
33 skip_markdown = lambda func, *args, **kwargs: func
34 from markdown2 import markdown
35 except ImportError:
36 try:
37 from markdown import markdown
38 except ImportError:
39 markdown = None
40 skip_markdown = mark_class(pytest.mark.skip(
41 reason='markdown not available'))
31 42
32 from roundup.anypy.strings import u2s, s2u 43 from roundup.anypy.strings import u2s, s2u
33 44
34 class MockDatabase(MockNull): 45 class MockDatabase(MockNull):
35 def getclass(self, name): 46 def getclass(self, name):
234 self.assertEqual(p.plain(hyperlink=1), 'A string &lt;b&gt; with <a href="mailto:rouilj@example.com">rouilj@example.com</a> embedded &amp;lt; html&lt;/b&gt;') 245 self.assertEqual(p.plain(hyperlink=1), 'A string &lt;b&gt; with <a href="mailto:rouilj@example.com">rouilj@example.com</a> embedded &amp;lt; html&lt;/b&gt;')
235 self.assertEqual(p.plain(escape=1, hyperlink=1), 'A string &lt;b&gt; with <a href="mailto:rouilj@example.com">rouilj@example.com</a> embedded &amp;lt; html&lt;/b&gt;') 246 self.assertEqual(p.plain(escape=1, hyperlink=1), 'A string &lt;b&gt; with <a href="mailto:rouilj@example.com">rouilj@example.com</a> embedded &amp;lt; html&lt;/b&gt;')
236 247
237 self.assertEqual(p.hyperlinked(), 'A string &lt;b&gt; with <a href="mailto:rouilj@example.com">rouilj@example.com</a> embedded &amp;lt; html&lt;/b&gt;') 248 self.assertEqual(p.hyperlinked(), 'A string &lt;b&gt; with <a href="mailto:rouilj@example.com">rouilj@example.com</a> embedded &amp;lt; html&lt;/b&gt;')
238 249
250 @skip_markdown
251 def test_string_markdown_installed(self):
252 pass # just so we have a record of a skipped test
253
254 def test_string_markdown(self):
255 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'A string http://localhost with cmeerw@example.com *embedded* \u00df'))
256 if markdown:
257 self.assertEqual(p.markdown().strip(), u2s(u'<p>A string <a href="http://localhost">http://localhost</a> with <a href="mailto:cmeerw@example.com">cmeerw@example.com</a> <em>embedded</em> \u00df</p>'))
258 else:
259 self.assertEqual(p.markdown(), u2s(u'A string <a href="http://localhost" rel="nofollow noopener">http://localhost</a> with <a href="mailto:cmeerw@example.com">cmeerw@example.com</a> *embedded* \u00df'))
260
239 @skip_rst 261 @skip_rst
262 def test_string_rst_installed(self):
263 pass # just so we have a record of a skipped test
264
240 def test_string_rst(self): 265 def test_string_rst(self):
241 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'A string with cmeerw@example.com *embedded* \u00df')) 266 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'A string with cmeerw@example.com *embedded* \u00df'))
242 if ReStructuredText: 267 if ReStructuredText:
243 self.assertEqual(p.rst(), u2s(u'<div class="document">\n<p>A string with <a class="reference external" href="mailto:cmeerw&#64;example.com">cmeerw&#64;example.com</a> <em>embedded</em> \u00df</p>\n</div>\n')) 268 self.assertEqual(p.rst(), u2s(u'<div class="document">\n<p>A string with <a class="reference external" href="mailto:cmeerw&#64;example.com">cmeerw&#64;example.com</a> <em>embedded</em> \u00df</p>\n</div>\n'))
244 else: 269 else:
245 self.assertEqual(p.rst(), u2s(u'A string with <a href="mailto:cmeerw@example.com">cmeerw@example.com</a> *embedded* \u00df')) 270 self.assertEqual(p.rst(), u2s(u'A string with <a href="mailto:cmeerw@example.com">cmeerw@example.com</a> *embedded* \u00df'))
246 271
247 @skip_stext 272 @skip_stext
273 def test_string_stext_installed(self):
274 pass # just so we have a record of a skipped test
275
248 def test_string_stext(self): 276 def test_string_stext(self):
249 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'A string with cmeerw@example.com *embedded* \u00df')) 277 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'A string with cmeerw@example.com *embedded* \u00df'))
250 if StructuredText: 278 if StructuredText:
251 self.assertEqual(p.stext(), u2s(u'<p>A string with <a href="mailto:cmeerw@example.com">cmeerw@example.com</a> <em>embedded</em> \u00df</p>\n')) 279 self.assertEqual(p.stext(), u2s(u'<p>A string with <a href="mailto:cmeerw@example.com">cmeerw@example.com</a> <em>embedded</em> \u00df</p>\n'))
252 else: 280 else:

Roundup Issue Tracker: http://roundup-tracker.org/