#!/usr/bin/env python from translate.convert import po2html from translate.convert import test_convert from translate.misc import wStringIO from translate.storage import po from translate.storage import html class TestPO2Html: def converthtml(self, posource, htmltemplate): """helper to exercise the command line function""" inputfile = wStringIO.StringIO(posource) print inputfile.getvalue() outputfile = wStringIO.StringIO() templatefile = wStringIO.StringIO(htmltemplate) assert po2html.converthtml(inputfile, outputfile, templatefile) print outputfile.getvalue() return outputfile.getvalue() def test_simple(self): """simple po to html test""" htmlsource = '
A sentence.
' posource = '''#: html:3\nmsgid "A sentence."\nmsgstr "'n Sin."\n''' htmlexpected = ''''n Sin.
''' assert htmlexpected in self.converthtml(posource, htmlsource) def test_linebreaks(self): """Test that a po file can be merged into a template with linebreaks in it.""" htmlsource = '''5 less than 6
' posource = '#:html:3\nmsgid "5 less than 6"\nmsgstr "5 < 6"\n' htmlexpected = '5 < 6
' assert htmlexpected in self.converthtml(posource, htmlsource) htmlsource = 'Fish & chips
' posource = '#: html:3\nmsgid "Fish & chips"\nmsgstr "Vis & skyfies"\n' htmlexpected = 'Vis & skyfies
' assert htmlexpected in self.converthtml(posource, htmlsource) def test_escapes(self): """Tests that PO escapes are correctly handled""" htmlsource = '"leverage"
' posource = '#: html3\nmsgid "\\"leverage\\""\nmsgstr "\\"ek is dom\\""\n' htmlexpected = '"ek is dom"
' assert htmlexpected in self.converthtml(posource, htmlsource) class TestPO2HtmlCommand(test_convert.TestConvertCommand, TestPO2Html): """Tests running actual po2oo commands on files""" convertmodule = po2html def test_help(self): """tests getting help""" options = test_convert.TestConvertCommand.test_help(self) options = self.help_check(options, "-tTEMPLATE, --template=TEMPLATE") options = self.help_check(options, "-wWRAP, --wrap=WRAP") options = self.help_check(options, "--fuzzy") options = self.help_check(options, "--nofuzzy", last=True)