comparison test/test_templating.py @ 6096:c914b3d8362f

If rst missing skip; initial attempt to test structuredtext. Try to set up structured text testing. I can't get StructuredText to run under python3, but this test passes under python2. Once I get StructuredText to pass under p3, I'll install StructuredText to ci and these tests won't be skipped. Also if import for reStructuredText fails, skip the test rather than silently passing.
author John Rouillard <rouilj@ieee.org>
date Wed, 19 Feb 2020 22:12:06 -0500
parents 3ada6a3f48e1
children 90a1470edbea
comparison
equal deleted inserted replaced
6095:3ada6a3f48e1 6096:c914b3d8362f
3 from cgi import FieldStorage, MiniFieldStorage 3 from cgi import FieldStorage, MiniFieldStorage
4 4
5 from roundup.cgi.templating import * 5 from roundup.cgi.templating import *
6 from .test_actions import MockNull, true 6 from .test_actions import MockNull, true
7 7
8
9 import pytest
10 from .pytest_patcher import mark_class
11
8 try: 12 try:
9 from docutils.core import publish_parts as ReStructuredText 13 from docutils.core import publish_parts as ReStructuredText
14 skip_rst = lambda func, *args, **kwargs: func
10 except ImportError: 15 except ImportError:
11 ReStructuredText = None 16 ReStructuredText = None
17 skip_rst = mark_class(pytest.mark.skip(
18 reason='ReStructuredText not available'))
19
20 try:
21 from StructuredText.StructuredText import HTML as StructuredText
22 skip_stext = lambda func, *args, **kwargs: func
23 except ImportError:
24 try: # older version
25 import StructuredText
26 skip_stext = lambda func, *args, **kwargs: func
27 except ImportError:
28 StructuredText = None
29 skip_stext = mark_class(pytest.mark.skip(
30 reason='StructuredText not available'))
12 31
13 from roundup.anypy.strings import u2s, s2u 32 from roundup.anypy.strings import u2s, s2u
14 33
15 class MockDatabase(MockNull): 34 class MockDatabase(MockNull):
16 def getclass(self, name): 35 def getclass(self, name):
215 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;') 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;')
216 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;') 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;')
217 236
218 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;') 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;')
219 238
239 @skip_rst
220 def test_string_rst(self): 240 def test_string_rst(self):
221 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'A string with cmeerw@example.com *embedded* \u00df')) 241 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'A string with cmeerw@example.com *embedded* \u00df'))
222 if ReStructuredText: 242 if ReStructuredText:
223 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')) 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'))
224 else: 244 else:
225 self.assertEqual(p.rst(), u2s(u'A string with <a href="mailto:cmeerw@example.com">cmeerw@example.com</a> *embedded* \u00df')) 245 self.assertEqual(p.rst(), u2s(u'A string with <a href="mailto:cmeerw@example.com">cmeerw@example.com</a> *embedded* \u00df'))
246
247 @skip_stext
248 def test_string_stext(self):
249 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'A string with cmeerw@example.com *embedded* \u00df'))
250 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'))
252 else:
253 self.assertEqual(p.stext(), u2s(u'A string with <a href="mailto:cmeerw@example.com">cmeerw@example.com</a> *embedded* \u00df'))
226 254
227 def test_string_field(self): 255 def test_string_field(self):
228 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', 'A string <b> with rouilj@example.com embedded &lt; html</b>') 256 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', 'A string <b> with rouilj@example.com embedded &lt; html</b>')
229 self.assertEqual(p.field(), '<input name="test1@test" size="30" type="text" value="A string &lt;b&gt; with rouilj@example.com embedded &amp;lt; html&lt;/b&gt;">') 257 self.assertEqual(p.field(), '<input name="test1@test" size="30" type="text" value="A string &lt;b&gt; with rouilj@example.com embedded &amp;lt; html&lt;/b&gt;">')
230 258

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