|
9 | 9 | import pytest |
10 | 10 | from .pytest_patcher import mark_class |
11 | 11 |
|
12 | | -try: |
13 | | - from docutils.core import publish_parts as ReStructuredText |
| 12 | +if ReStructuredText: |
14 | 13 | skip_rst = lambda func, *args, **kwargs: func |
15 | | -except ImportError: |
16 | | - ReStructuredText = None |
| 14 | +else: |
17 | 15 | skip_rst = mark_class(pytest.mark.skip( |
18 | 16 | reason='ReStructuredText not available')) |
19 | 17 |
|
20 | | -try: |
21 | | - from StructuredText.StructuredText import HTML as StructuredText |
| 18 | +if StructuredText: |
22 | 19 | 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')) |
31 | | - |
32 | | -try: |
| 20 | +else: |
| 21 | + skip_stext = mark_class(pytest.mark.skip( |
| 22 | + reason='StructuredText not available')) |
| 23 | + |
| 24 | +import roundup.cgi.templating |
| 25 | +if roundup.cgi.templating._import_mistune(): |
| 26 | + skip_mistune = lambda func, *args, **kwargs: func |
| 27 | +else: |
| 28 | + skip_mistune = mark_class(pytest.mark.skip( |
| 29 | + reason='mistune not available')) |
| 30 | + |
| 31 | +if roundup.cgi.templating._import_markdown2(): |
| 32 | + skip_markdown2 = lambda func, *args, **kwargs: func |
| 33 | +else: |
| 34 | + skip_markdown2 = mark_class(pytest.mark.skip( |
| 35 | + reason='markdown2 not available')) |
| 36 | + |
| 37 | +if roundup.cgi.templating._import_markdown(): |
33 | 38 | 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')) |
| 39 | +else: |
| 40 | + skip_markdown = mark_class(pytest.mark.skip( |
| 41 | + reason='markdown not available')) |
42 | 42 |
|
43 | 43 | from roundup.anypy.strings import u2s, s2u |
44 | 44 |
|
@@ -247,21 +247,7 @@ def test_string_plain_or_hyperlinked(self): |
247 | 247 |
|
248 | 248 | self. assertEqual( p. hyperlinked(), 'A string <b> with <a href="mailto:[email protected]">[email protected]</a> embedded &lt; html</b>') |
249 | 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 [email protected] *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:[email protected]">[email protected]</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:[email protected]">[email protected]</a> *embedded* \u00df')) |
260 | | - |
261 | 250 | @skip_rst |
262 | | - def test_string_rst_installed(self): |
263 | | - pass # just so we have a record of a skipped test |
264 | | - |
265 | 251 | def test_string_rst(self): |
266 | 252 | p = StringHTMLProperty( self. client, 'test', '1', None, 'test', u2s( u'A string with [email protected] *embedded* \u00df')) |
267 | 253 |
|
@@ -295,23 +281,14 @@ def test_string_rst(self): |
295 | 281 | </div> |
296 | 282 | </div> |
297 | 283 | ''' |
298 | | - if ReStructuredText: |
299 | | - self.assertEqual(p.rst(), u2s(u'<div class="document">\n<p>A string with <a class="reference external" href="mailto:cmeerw@example.com">cmeerw@example.com</a> <em>embedded</em> \u00df</p>\n</div>\n')) |
300 | | - self.assertEqual(q.rst(), u2s(q_result)) |
301 | | - self.assertEqual(r.rst(), u2s(r_result)) |
302 | | - else: |
303 | | - self. assertEqual( p. rst(), u2s( u'A string with <a href="mailto:[email protected]">[email protected]</a> *embedded* \u00df')) |
| 284 | + self.assertEqual(p.rst(), u2s(u'<div class="document">\n<p>A string with <a class="reference external" href="mailto:cmeerw@example.com">cmeerw@example.com</a> <em>embedded</em> \u00df</p>\n</div>\n')) |
| 285 | + self.assertEqual(q.rst(), u2s(q_result)) |
| 286 | + self.assertEqual(r.rst(), u2s(r_result)) |
304 | 287 |
|
305 | 288 | @skip_stext |
306 | | - def test_string_stext_installed(self): |
307 | | - pass # just so we have a record of a skipped test |
308 | | - |
309 | 289 | def test_string_stext(self): |
310 | 290 | p = StringHTMLProperty( self. client, 'test', '1', None, 'test', u2s( u'A string with [email protected] *embedded* \u00df')) |
311 | | - if StructuredText: |
312 | | - self. assertEqual( p. stext(), u2s( u'<p>A string with <a href="mailto:[email protected]">[email protected]</a> <em>embedded</em> \u00df</p>\n')) |
313 | | - else: |
314 | | - self. assertEqual( p. stext(), u2s( u'A string with <a href="mailto:[email protected]">[email protected]</a> *embedded* \u00df')) |
| 291 | + self. assertEqual( p. stext(), u2s( u'<p>A string with <a href="mailto:[email protected]">[email protected]</a> <em>embedded</em> \u00df</p>\n')) |
315 | 292 |
|
316 | 293 | def test_string_field(self): |
317 | 294 | p = StringHTMLProperty( self. client, 'test', '1', None, 'test', 'A string <b> with [email protected] embedded < html</b>') |
@@ -436,6 +413,105 @@ def test_input_xhtml(self): |
436 | 413 | input=input_xhtml(**attrs) |
437 | 414 | self.assertEqual(input, '<input class="required" disabled="disabled" size="30" type="text"/>') |
438 | 415 |
|
| 416 | +# common markdown test cases |
| 417 | +class MarkdownTests: |
| 418 | + def test_string_markdown(self): |
| 419 | + p = StringHTMLProperty( self. client, 'test', '1', None, 'test', u2s( u'A string http://localhost with [email protected] <br> *embedded* \u00df')) |
| 420 | + self. assertEqual( p. markdown(). strip(), u2s( u'<p>A string <a href="http://localhost">http://localhost</a> with <a href="mailto:[email protected]">[email protected]</a> <br> <em>embedded</em> \u00df</p>')) |
| 421 | + |
| 422 | + def test_string_markdown_code_block(self): |
| 423 | + p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'embedded code block\n\n```\nline 1\nline 2\n```\n\nnew paragraph')) |
| 424 | + self.assertEqual(p.markdown().strip().replace('\n\n', '\n'), u2s(u'<p>embedded code block</p>\n<pre><code>line 1\nline 2\n</code></pre>\n<p>new paragraph</p>')) |
| 425 | + |
| 426 | +@skip_mistune |
| 427 | +class MistuneTestCase(TemplatingTestCase, MarkdownTests) : |
| 428 | + def setUp(self): |
| 429 | + TemplatingTestCase.setUp(self) |
| 430 | + |
| 431 | + from roundup.cgi import templating |
| 432 | + self.__markdown = templating.markdown |
| 433 | + templating.markdown = templating._import_mistune() |
| 434 | + |
| 435 | + def tearDown(self): |
| 436 | + from roundup.cgi import templating |
| 437 | + templating.markdown = self.__markdown |
| 438 | + |
| 439 | +@skip_markdown2 |
| 440 | +class Markdown2TestCase(TemplatingTestCase, MarkdownTests) : |
| 441 | + def setUp(self): |
| 442 | + TemplatingTestCase.setUp(self) |
| 443 | + |
| 444 | + from roundup.cgi import templating |
| 445 | + self.__markdown = templating.markdown |
| 446 | + templating.markdown = templating._import_markdown2() |
| 447 | + |
| 448 | + def tearDown(self): |
| 449 | + from roundup.cgi import templating |
| 450 | + templating.markdown = self.__markdown |
| 451 | + |
| 452 | +@skip_markdown |
| 453 | +class MarkdownTestCase(TemplatingTestCase, MarkdownTests) : |
| 454 | + def setUp(self): |
| 455 | + TemplatingTestCase.setUp(self) |
| 456 | + |
| 457 | + from roundup.cgi import templating |
| 458 | + self.__markdown = templating.markdown |
| 459 | + templating.markdown = templating._import_markdown() |
| 460 | + |
| 461 | + def tearDown(self): |
| 462 | + from roundup.cgi import templating |
| 463 | + templating.markdown = self.__markdown |
| 464 | + |
| 465 | + |
| 466 | +class NoMarkdownTestCase(TemplatingTestCase) : |
| 467 | + def setUp(self): |
| 468 | + TemplatingTestCase.setUp(self) |
| 469 | + |
| 470 | + from roundup.cgi import templating |
| 471 | + self.__markdown = templating.markdown |
| 472 | + templating.markdown = None |
| 473 | + |
| 474 | + def tearDown(self): |
| 475 | + from roundup.cgi import templating |
| 476 | + templating.markdown = self.__markdown |
| 477 | + |
| 478 | + def test_string_markdown(self): |
| 479 | + p = StringHTMLProperty( self. client, 'test', '1', None, 'test', u2s( u'A string http://localhost with [email protected] <br> *embedded* \u00df')) |
| 480 | + self. assertEqual( p. markdown(), u2s( u'A string <a href="http://localhost" rel="nofollow noopener">http://localhost</a> with <a href="mailto:[email protected]">[email protected]</a> <br> *embedded* \u00df')) |
| 481 | + |
| 482 | +class NoRstTestCase(TemplatingTestCase) : |
| 483 | + def setUp(self): |
| 484 | + TemplatingTestCase.setUp(self) |
| 485 | + |
| 486 | + from roundup.cgi import templating |
| 487 | + self.__ReStructuredText = templating.ReStructuredText |
| 488 | + templating.ReStructuredText = None |
| 489 | + |
| 490 | + def tearDown(self): |
| 491 | + from roundup.cgi import templating |
| 492 | + templating.ReStructuredText = self.__ReStructuredText |
| 493 | + |
| 494 | + def test_string_rst(self): |
| 495 | + p = StringHTMLProperty( self. client, 'test', '1', None, 'test', u2s( u'A string with [email protected] *embedded* \u00df')) |
| 496 | + self. assertEqual( p. rst(), u2s( u'A string with <a href="mailto:[email protected]">[email protected]</a> *embedded* \u00df')) |
| 497 | + |
| 498 | +class NoStextTestCase(TemplatingTestCase) : |
| 499 | + def setUp(self): |
| 500 | + TemplatingTestCase.setUp(self) |
| 501 | + |
| 502 | + from roundup.cgi import templating |
| 503 | + self.__StructuredText = templating.StructuredText |
| 504 | + templating.StructuredText = None |
| 505 | + |
| 506 | + def tearDown(self): |
| 507 | + from roundup.cgi import templating |
| 508 | + templating.StructuredText = self.__StructuredText |
| 509 | + |
| 510 | + def test_string_stext(self): |
| 511 | + p = StringHTMLProperty( self. client, 'test', '1', None, 'test', u2s( u'A string with [email protected] *embedded* \u00df')) |
| 512 | + self. assertEqual( p. stext(), u2s( u'A string with <a href="mailto:[email protected]">[email protected]</a> *embedded* \u00df')) |
| 513 | + |
| 514 | + |
439 | 515 | r''' |
440 | 516 | class HTMLPermissions: |
441 | 517 | def is_edit_ok(self): |
|
0 commit comments