l.a.b.t.test_stringformatter : module documentation

Part of lp.app.browser.tests

Unit tests for the string TALES formatter.
Function test_split_paragraphs The split_paragraphs() method is used to split a block of text
Function test_re_substitute When formatting text, we want to replace portions with links.
Function test_add_word_breaks Long words can cause page layout problems, so we insert manual
Function test_break_long_words If we have a long HTML string, break_long_words() can be used to
Class TestLinkifyingBugs Undocumented
Class TestLinkifyingProtocols Undocumented
Class TestLastParagraphClass Undocumented
Class TestParseDiff Test the parser for fmt:diff and fmt:ssdiff.
Class TestParseDiffErrors Undocumented
Class TestDiffFormatter Test the string formatter fmt:diff.
Class TestSideBySideDiffFormatter Test the string formatter fmt:ssdiff.
Class TestOOPSFormatter A test case for the oops_id() string formatter.
Class MarksDownAs Undocumented
Class TestMarkdownDisabled Feature flag can turn Markdown stuff off.
Class TestMarkdown Test for Markdown integration within Launchpad.
Function test_suite Undocumented
def test_split_paragraphs():

The split_paragraphs() method is used to split a block of text into paragraphs, which are separated by one or more blank lines. Paragraphs are yielded as a list of lines in the paragraph.

>>> from lp.app.browser.stringformatter import split_paragraphs
>>> for paragraph in split_paragraphs('\na\nb\n\nc\nd\n\n\n'):
...     print paragraph
['a', 'b']
['c', 'd']
def test_re_substitute():

When formatting text, we want to replace portions with links. re.sub() works fairly well for this, but doesn't give us much control over the non-matched text. The re_substitute() function lets us do that.

>>> import re
>>> from lp.app.browser.stringformatter import re_substitute
>>> def match_func(match):
...     return '[%s]' % match.group()
>>> def nomatch_func(text):
...     return '{%s}' % text
>>> pat = re.compile('a{2,6}')
>>> print re_substitute(pat, match_func, nomatch_func,
...                     'bbaaaabbbbaaaaaaa aaaaaaaab')
{bb}[aaaa]{bbbb}[aaaaaa]{a }[aaaaaa][aa]{b}
def test_add_word_breaks():

Long words can cause page layout problems, so we insert manual word breaks into long words. Breaks are added at least once every 15 characters, but will break on as little as 7 characters if there is a suitable non-alphanumeric character to break after.

>>> from lp.app.browser.stringformatter import add_word_breaks
>>> print add_word_breaks('abcdefghijklmnop')
abcdefghijklmno<wbr />p
>>> print add_word_breaks('abcdef/ghijklmnop')
abcdef/<wbr />ghijklmnop
>>> print add_word_breaks('ab/cdefghijklmnop')
ab/cdefghijklmn<wbr />op

The string can contain HTML entities, which do not get split:

>>> print add_word_breaks('abcdef&anentity;hijklmnop')
abcdef&anentity;<wbr />hijklmnop
def test_break_long_words():

If we have a long HTML string, break_long_words() can be used to add word breaks to the long words. It will not add breaks inside HTML tags. Only words longer than 20 characters will have breaks added.

>>> from lp.app.browser.stringformatter import break_long_words
>>> print break_long_words('1234567890123456')
1234567890123456
>>> print break_long_words('12345678901234567890')
123456789012345<wbr />67890
>>> print break_long_words('<tag a12345678901234567890="foo"></tag>')
<tag a12345678901234567890="foo"></tag>
>>> print break_long_words('12345678901234567890 1234567890.1234567890')
123456789012345<wbr />67890 1234567890.<wbr />1234567890
>>> print break_long_words('1234567890&abcdefghi;123')
1234567890&abcdefghi;123
>>> print break_long_words('<tag>1234567890123456</tag>')
<tag>1234567890123456</tag>
def test_suite():
Undocumented
API Documentation for Launchpad, generated by pydoctor at 2022-06-16 00:00:12.