Package translate :: Package convert :: Module test_po2html
[hide private]
[frames] | no frames]

Source Code for Module translate.convert.test_po2html

 1  #!/usr/bin/env python 
 2   
 3  from translate.convert import po2html 
 4  from translate.convert import test_convert 
 5  from translate.misc import wStringIO 
 6   
7 -class TestPO2Html:
8 - def converthtml(self, posource, htmltemplate):
9 """helper to exercise the command line function""" 10 inputfile = wStringIO.StringIO(posource) 11 print inputfile.getvalue() 12 outputfile = wStringIO.StringIO() 13 templatefile = wStringIO.StringIO(htmltemplate) 14 assert po2html.converthtml(inputfile, outputfile, templatefile) 15 print outputfile.getvalue() 16 return outputfile.getvalue()
17
18 - def test_simple(self):
19 """simple po to html test""" 20 htmlsource = '<p>A sentence.</p>' 21 posource = '''#: html:3\nmsgid "A sentence."\nmsgstr "'n Sin."\n''' 22 htmlexpected = '''<p>'n Sin.</p>''' 23 assert htmlexpected in self.converthtml(posource, htmlsource)
24
25 - def test_linebreaks(self):
26 """Test that a po file can be merged into a template with linebreaks in it.""" 27 htmlsource = '''<html> 28 <head> 29 </head> 30 <body> 31 <div> 32 A paragraph is a section in a piece of writing, usually highlighting a 33 particular point or topic. It always begins on a new line and usually 34 with indentation, and it consists of at least one sentence. 35 </div> 36 </body> 37 </html> 38 ''' 39 posource = '''#: None:1 40 msgid "" 41 "A paragraph is a section in a piece of writing, usually highlighting a " 42 "particular point or topic. It always begins on a new line and usually with " 43 "indentation, and it consists of at least one sentence." 44 msgstr "" 45 "'n Paragraaf is 'n afdeling in 'n geskrewe stuk wat gewoonlik 'n spesifieke " 46 "punt uitlig. Dit begin altyd op 'n nuwe lyn (gewoonlik met indentasie) en " 47 "dit bestaan uit ten minste een sin." 48 ''' 49 htmlexpected = '''<body> 50 <div>'n Paragraaf is 'n afdeling in 'n geskrewe stuk wat gewoonlik 51 'n spesifieke punt uitlig. Dit begin altyd op 'n nuwe lyn 52 (gewoonlik met indentasie) en dit bestaan uit ten minste een 53 sin.</div> 54 </body>''' 55 assert htmlexpected.replace("\n", " ") in self.converthtml(posource, htmlsource).replace("\n", " ")
56
57 - def test_entities(self):
58 """Tests that entities are handled correctly""" 59 htmlsource = '<p>5 less than 6</p>' 60 posource = '#:html:3\nmsgid "5 less than 6"\nmsgstr "5 < 6"\n' 61 htmlexpected = '<p>5 &lt; 6</p>' 62 assert htmlexpected in self.converthtml(posource, htmlsource) 63 64 htmlsource = '<p>Fish &amp; chips</p>' 65 posource = '#: html:3\nmsgid "Fish & chips"\nmsgstr "Vis & skyfies"\n' 66 htmlexpected = '<p>Vis &amp; skyfies</p>' 67 assert htmlexpected in self.converthtml(posource, htmlsource)
68
69 - def test_escapes(self):
70 """Tests that PO escapes are correctly handled""" 71 htmlsource = '<div>Row 1<br />Row 2</div>' 72 posource = '#: html:3\nmsgid "Row 1\\n"\n"Row 2"\nmsgstr "Ry 1\\n"\n"Ry 2"\n' 73 htmlexpected = '<div>Ry 1<br />Ry 2</div>' 74 assert htmlexpected in self.converthtml(posource, htmlsource) 75 76 htmlsource = '<p>"leverage"</p>' 77 posource = '#: html3\nmsgid "\\"leverage\\""\nmsgstr "\\"ek is dom\\""\n' 78 htmlexpected = '<p>"ek is dom"</p>' 79 assert htmlexpected in self.converthtml(posource, htmlsource)
80 81
82 -class TestPO2HtmlCommand(test_convert.TestConvertCommand, TestPO2Html):
83 """Tests running actual po2oo commands on files""" 84 convertmodule = po2html 85
86 - def test_help(self):
87 """tests getting help""" 88 options = test_convert.TestConvertCommand.test_help(self) 89 options = self.help_check(options, "-t TEMPLATE, --template=TEMPLATE") 90 options = self.help_check(options, "-w WRAP, --wrap=WRAP") 91 options = self.help_check(options, "--fuzzy") 92 options = self.help_check(options, "--nofuzzy", last=True)
93