Mercurial > p > roundup > code
comparison test/test_templating.py @ 7864:b080cdb8b199
fix: document/fix wrapped HtmlProperty method.
The wrapped method was not documented in reference.txt.
It is now documented in reference.txt. The docstring documented that
it would not break up long words. Fixed by adding
break_long_words=False to prevent breaking string longer than the wrap
length. Wrapping was breaking the hyperlinking of long urls.
Added columns argument to set the wrap length (default 80 columns).
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sun, 07 Apr 2024 15:27:18 -0400 |
| parents | 978285986b2c |
| children | 9bbc1d951677 |
comparison
equal
deleted
inserted
replaced
| 7863:bd126f890279 | 7864:b080cdb8b199 |
|---|---|
| 448 test_string = ('A long string that needs to be wrapped to' | 448 test_string = ('A long string that needs to be wrapped to' |
| 449 ' 80 characters and no more. Put in a link issue1.' | 449 ' 80 characters and no more. Put in a link issue1.' |
| 450 ' Put in <html> to be escaped. Put in a' | 450 ' Put in <html> to be escaped. Put in a' |
| 451 ' https://example.com/link as well. Let us see if' | 451 ' https://example.com/link as well. Let us see if' |
| 452 ' it will wrap properly.' ) | 452 ' it will wrap properly.' ) |
| 453 test_result = ('A long string that needs to be wrapped to 80' | 453 |
| 454 test_result_wrap = {} | |
| 455 test_result_wrap[80] = ('A long string that needs to be wrapped to 80' | |
| 454 ' characters and no more. Put in a\n' | 456 ' characters and no more. Put in a\n' |
| 455 'link <a href="issue1">issue1</a>. Put in' | 457 'link <a href="issue1">issue1</a>. Put in' |
| 456 ' <html> to be escaped. Put in a <a' | 458 ' <html> to be escaped. Put in a <a' |
| 457 ' href="https://example.com/link"' | 459 ' href="https://example.com/link"' |
| 458 ' rel="nofollow noopener">' | 460 ' rel="nofollow noopener">' |
| 459 'https://example.com/link</a> as\n' | 461 'https://example.com/link</a> as\n' |
| 460 'well. Let us see if it will wrap properly.') | 462 'well. Let us see if it will wrap properly.') |
| 463 test_result_wrap[20] = ( | |
| 464 'A long string that\n' | |
| 465 'needs to be wrapped\n' | |
| 466 'to 80 characters and\n' | |
| 467 'no more. Put in a\nlink <a href="issue1">issue1</a>. Put in\n' | |
| 468 '<html> to be\n' | |
| 469 'escaped. Put in a\n' | |
| 470 '<a href="https://example.com/link" rel="nofollow ' | |
| 471 'noopener">https://example.com/link</a>\n' | |
| 472 'as well. Let us see\n' | |
| 473 'if it will wrap\n' | |
| 474 'properly.') | |
| 475 test_result_wrap[100] = ( | |
| 476 'A long string that needs to be wrapped to 80 characters and no more. Put in a link <a href="issue1">issue1</a>. Put in\n' | |
| 477 '<html> to be escaped. Put in a <a href="https://example.com/link" rel="nofollow noopener">https://example.com/link</a> as well. Let us see if it will wrap\n' | |
| 478 'properly.') | |
| 461 | 479 |
| 462 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', | 480 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', |
| 463 test_string) | 481 test_string) |
| 464 self.assertEqual(p.wrapped(), test_result) | 482 |
| 483 for i in [80, 20, 100]: | |
| 484 wrapped = p.wrapped(columns=i) | |
| 485 print(wrapped) | |
| 486 self.assertEqual(wrapped, test_result_wrap[i]) | |
| 465 | 487 |
| 466 def test_string_plain_or_hyperlinked(self): | 488 def test_string_plain_or_hyperlinked(self): |
| 467 ''' test that email obscures the email ''' | 489 ''' test that email obscures the email ''' |
| 468 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', 'A string <b> with rouilj@example.com embedded < html</b>') | 490 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', 'A string <b> with rouilj@example.com embedded < html</b>') |
| 469 self.assertEqual(p.plain(), 'A string <b> with rouilj@example.com embedded < html</b>') | 491 self.assertEqual(p.plain(), 'A string <b> with rouilj@example.com embedded < html</b>') |
