def VerifyChunkingDescriptions(self, fold_whitespace): p = tr_html.HtmlChunks() # Check capitals and explicit descriptions chunks = p.Parse( '<!-- desc=bingo! --><B>Hello!</B> how are you?<P>' '<I>I am fine.</I>', fold_whitespace) self.failUnlessEqual(chunks, [(True, '<B>Hello!</B> how are you?', 'bingo!'), (False, '<P>', ''), (True, '<I>I am fine.</I>', '')]) chunks = p.Parse( '<B><!-- desc=bingo! -->Hello!</B> how are you?<P>' '<I>I am fine.</I>', fold_whitespace) self.failUnlessEqual(chunks, [(True, '<B>Hello!</B> how are you?', 'bingo!'), (False, '<P>', ''), (True, '<I>I am fine.</I>', '')]) # Linebreaks get handled by the tclib message. chunks = p.Parse( '<B>Hello!</B> <!-- desc=bi\nngo\n! -->how are you?<P>' '<I>I am fine.</I>', fold_whitespace) self.failUnlessEqual( chunks, [(True, '<B>Hello!</B> how are you?', 'bi\nngo\n!'), (False, '<P>', ''), (True, '<I>I am fine.</I>', '')]) # In this case, because the explicit description appears after the first # translateable, it will actually apply to the second translateable. chunks = p.Parse( '<B>Hello!</B> how are you?<!-- desc=bingo! --><P>' '<I>I am fine.</I>', fold_whitespace) self.failUnlessEqual(chunks, [(True, '<B>Hello!</B> how are you?', ''), (False, '<P>', ''), (True, '<I>I am fine.</I>', 'bingo!')])
def VerifyChunkingBasic(self, fold_whitespace): p = tr_html.HtmlChunks() chunks = p.Parse('<p>Hello <b>dear</b> how <i>are</i>you?<p>Fine!', fold_whitespace) self.failUnlessEqual(chunks, [ (False, '<p>', ''), (True, 'Hello <b>dear</b> how <i>are</i>you?', ''), (False, '<p>', ''), (True, 'Fine!', '')]) chunks = p.Parse('<p> Hello <b>dear</b> how <i>are</i>you? <p>Fine!', fold_whitespace) self.failUnlessEqual(chunks, [ (False, '<p> ', ''), (True, 'Hello <b>dear</b> how <i>are</i>you?', ''), (False, ' <p>', ''), (True, 'Fine!', '')]) chunks = p.Parse('<p> Hello <b>dear how <i>are you? <p> Fine!', fold_whitespace) self.failUnlessEqual(chunks, [ (False, '<p> ', ''), (True, 'Hello <b>dear how <i>are you?', ''), (False, ' <p> ', ''), (True, 'Fine!', '')]) # Ensure translateable sections that start with inline tags contain # the starting inline tag. chunks = p.Parse('<b>Hello!</b> how are you?<p><i>I am fine.</i>', fold_whitespace) self.failUnlessEqual(chunks, [ (True, '<b>Hello!</b> how are you?', ''), (False, '<p>', ''), (True, '<i>I am fine.</i>', '')]) # Ensure translateable sections that end with inline tags contain # the ending inline tag. chunks = p.Parse("Hello! How are <b>you?</b><p><i>I'm fine!</i>", fold_whitespace) self.failUnlessEqual(chunks, [ (True, 'Hello! How are <b>you?</b>', ''), (False, '<p>', ''), (True, "<i>I'm fine!</i>", '')])
def VerifyChunkingReplaceables(self, fold_whitespace): # Check that replaceables within block tags (where attributes would go) are # handled correctly. p = tr_html.HtmlChunks() chunks = p.Parse( '<b>Hello!</b> how are you?<p [BINGO] [$~BONGO~$]>' '<i>I am fine.</i>', fold_whitespace) self.failUnlessEqual(chunks, [(True, '<b>Hello!</b> how are you?', ''), (False, '<p [BINGO] [$~BONGO~$]>', ''), (True, '<i>I am fine.</i>', '')])
def VerifyChunkingLineBreaks(self, fold_whitespace): # Check that the contents of preformatted tags preserve line breaks. p = tr_html.HtmlChunks() chunks = p.Parse('<textarea>Hello\nthere\nhow\nare\nyou?</textarea>', fold_whitespace) self.failUnlessEqual(chunks, [(False, '<textarea>', ''), (True, 'Hello\nthere\nhow\nare\nyou?', ''), (False, '</textarea>', '')]) # ...and that other tags' line breaks are converted to spaces chunks = p.Parse('<p>Hello\nthere\nhow\nare\nyou?</p>', fold_whitespace) self.failUnlessEqual(chunks, [(False, '<p>', ''), (True, 'Hello there how are you?', ''), (False, '</p>', '')])
def VerifyChunkingMessageNoBreak(self, fold_whitespace): p = tr_html.HtmlChunks() # Make sure that message-no-break comments work properly. chunks = p.Parse('Please <!-- message-no-break --> <br />don\'t break', fold_whitespace) self.failUnlessEqual(chunks, [(True, 'Please <!-- message-no-break --> ' '<br />don\'t break', '')]) chunks = p.Parse('Please <br /> break. <!-- message-no-break --> <br /> ' 'But not this time.', fold_whitespace) self.failUnlessEqual(chunks, [(True, 'Please', ''), (False, ' <br /> ', ''), (True, 'break. <!-- message-no-break --> ' '<br /> But not this time.', '')])
def testTranslateableAttributes(self): p = tr_html.HtmlChunks() # Check that the translateable attributes in <img>, <submit>, <button> and # <text> elements buttons are handled correctly. chunks = p.Parse('<img src=bingo.jpg alt="hello there">' '<input type=submit value="hello">' '<input type="button" value="hello">' '<input type=\'text\' value=\'Howdie\'>') self.failUnless(chunks == [ (False, '<img src=bingo.jpg alt="', ''), (True, 'hello there', ''), (False, '"><input type=submit value="', ''), (True, 'hello', ''), (False, '"><input type="button" value="', ''), (True, 'hello', ''), (False, '"><input type=\'text\' value=\'', ''), (True, 'Howdie', ''), (False, '\'>', '')])
def VerifyChunkingMessageBreak(self, fold_whitespace): p = tr_html.HtmlChunks() # Make sure that message-break comments work properly. chunks = p.Parse( 'Break<!-- message-break --> apart ' '<!--message-break-->messages', fold_whitespace) self.failUnlessEqual(chunks, [(True, 'Break', ''), (False, ' ', ''), (True, 'apart', ''), (False, ' ', ''), (True, 'messages', '')]) # Make sure message-break comments work in an inline tag. chunks = p.Parse( '<a href=\'google.com\'><!-- message-break -->Google' '<!--message-break--></a>', fold_whitespace) self.failUnlessEqual(chunks, [(False, '<a href=\'google.com\'>', ''), (True, 'Google', ''), (False, '</a>', '')])
def testChunking(self): p = tr_html.HtmlChunks() chunks = p.Parse('<p>Hello <b>dear</b> how <i>are</i>you?<p>Fine!') self.failUnless(chunks == [ (False, '<p>', ''), (True, 'Hello <b>dear</b> how <i>are</i>you?', ''), (False, '<p>', ''), (True, 'Fine!', '')]) chunks = p.Parse('<p> Hello <b>dear</b> how <i>are</i>you? <p>Fine!') self.failUnless(chunks == [ (False, '<p> ', ''), (True, 'Hello <b>dear</b> how <i>are</i>you?', ''), (False, ' <p>', ''), (True, 'Fine!', '')]) chunks = p.Parse('<p> Hello <b>dear how <i>are you? <p> Fine!') self.failUnless(chunks == [ (False, '<p> ', ''), (True, 'Hello <b>dear how <i>are you?', ''), (False, ' <p> ', ''), (True, 'Fine!', '')]) # Ensure translateable sections that start with inline tags contain # the starting inline tag. chunks = p.Parse('<b>Hello!</b> how are you?<p><i>I am fine.</i>') self.failUnless(chunks == [ (True, '<b>Hello!</b> how are you?', ''), (False, '<p>', ''), (True, '<i>I am fine.</i>', '')]) # Ensure translateable sections that end with inline tags contain # the ending inline tag. chunks = p.Parse("Hello! How are <b>you?</b><p><i>I'm fine!</i>") self.failUnless(chunks == [ (True, 'Hello! How are <b>you?</b>', ''), (False, '<p>', ''), (True, "<i>I'm fine!</i>", '')]) # Check capitals and explicit descriptions chunks = p.Parse('<!-- desc=bingo! --><B>Hello!</B> how are you?<P><I>I am fine.</I>') self.failUnless(chunks == [ (True, '<B>Hello!</B> how are you?', 'bingo!'), (False, '<P>', ''), (True, '<I>I am fine.</I>', '')]) chunks = p.Parse('<B><!-- desc=bingo! -->Hello!</B> how are you?<P><I>I am fine.</I>') self.failUnless(chunks == [ (True, '<B>Hello!</B> how are you?', 'bingo!'), (False, '<P>', ''), (True, '<I>I am fine.</I>', '')]) # Linebreaks get changed to spaces just like any other HTML content chunks = p.Parse('<B>Hello!</B> <!-- desc=bi\nngo\n! -->how are you?<P><I>I am fine.</I>') self.failUnless(chunks == [ (True, '<B>Hello!</B> how are you?', 'bi ngo !'), (False, '<P>', ''), (True, '<I>I am fine.</I>', '')]) # In this case, because the explicit description appears after the first # translateable, it will actually apply to the second translateable. chunks = p.Parse('<B>Hello!</B> how are you?<!-- desc=bingo! --><P><I>I am fine.</I>') self.failUnless(chunks == [ (True, '<B>Hello!</B> how are you?', ''), (False, '<P>', ''), (True, '<I>I am fine.</I>', 'bingo!')]) # Check that replaceables within block tags (where attributes would go) are # handled correctly. chunks = p.Parse('<b>Hello!</b> how are you?<p [BINGO] [$~BONGO~$]>' '<i>I am fine.</i>') self.failUnless(chunks == [ (True, '<b>Hello!</b> how are you?', ''), (False, '<p [BINGO] [$~BONGO~$]>', ''), (True, '<i>I am fine.</i>', '')]) # Check that the contents of preformatted tags preserve line breaks. chunks = p.Parse('<textarea>Hello\nthere\nhow\nare\nyou?</textarea>') self.failUnless(chunks == [(False, '<textarea>', ''), (True, 'Hello\nthere\nhow\nare\nyou?', ''), (False, '</textarea>', '')]) # ...and that other tags' line breaks are converted to spaces chunks = p.Parse('<p>Hello\nthere\nhow\nare\nyou?</p>') self.failUnless(chunks == [(False, '<p>', ''), (True, 'Hello there how are you?', ''), (False, '</p>', '')])