Package translate :: Package convert :: Module test_po2prop

[hide private]
[frames] | no frames]

# Source Code for Module translate.convert.test_po2prop

      1  #!/usr/bin/env python
      2  # -*- coding: utf-8 -*-
      3
      4  from translate.convert import po2prop
      5  from translate.convert import test_convert
      6  from translate.misc import wStringIO
      7  from translate.storage import po
      8
      9 -class TestPO2Prop:
     10 -    def po2prop(self, posource):
     11          """helper that converts po source to .properties source without requiring files"""
     12          inputfile = wStringIO.StringIO(posource)
     13          inputpo = po.pofile(inputfile)
     14          convertor = po2prop.po2prop()
     15          outputprop = convertor.convertstore(inputpo)
     16          return outputprop
     17
     18 -    def merge2prop(self, propsource, posource, personality="java"):
     19          """helper that merges po translations to .properties source without requiring files"""
     20          inputfile = wStringIO.StringIO(posource)
     21          inputpo = po.pofile(inputfile)
     22          templatefile = wStringIO.StringIO(propsource)
     23          #templateprop = properties.propfile(templatefile)
     24          convertor = po2prop.reprop(templatefile)
     25          outputprop = convertor.convertstore(inputpo, personality=personality)
     26          print outputprop
     27          return outputprop
     28
     29 -    def test_merging_simple(self):
     30          """check the simplest case of merging a translation"""
     31          posource = '''#: prop\nmsgid "value"\nmsgstr "waarde"\n'''
     32          proptemplate = '''prop=value\n'''
     33          propexpected = '''prop=waarde\n'''
     34          propfile = self.merge2prop(proptemplate, posource)
     35          print propfile
     36          assert propfile == [propexpected]
     37
     38 -    def test_hard_newlines_preserved(self):
     39          """check that we preserver hard coded newlines at the start and end of sentence"""
     40          posource = '''#: prop\nmsgid "\\nvalue\\n\\n"\nmsgstr "\\nwaarde\\n\\n"\n'''
     41          proptemplate = '''prop=\\nvalue\\n\\n\n'''
     42          propexpected = '''prop=\\nwaarde\\n\\n\n'''
     43          propfile = self.merge2prop(proptemplate, posource)
     44          print propfile
     45          assert propfile == [propexpected]
     46
     47 -    def test_space_preservation(self):
     48          """check that we preserve any spacing in properties files when merging"""
     49          posource = '''#: prop\nmsgid "value"\nmsgstr "waarde"\n'''
     50          proptemplate = '''prop  =  value\n'''
     51          propexpected = '''prop  =  waarde\n'''
     52          propfile = self.merge2prop(proptemplate, posource)
     53          print propfile
     54          assert propfile == [propexpected]
     55
     56 -    def test_merging_blank_entries(self):
     57          """check that we can correctly merge entries that are blank in the template"""
     58          posource = '''#: accesskey-accept
     59  msgid ""
     60  "_: accesskey-accept\n"
     61  ""
     62  msgstr ""'''
     63          proptemplate = 'accesskey-accept=\n'
     64          propexpected = 'accesskey-accept=\n'
     65          propfile = self.merge2prop(proptemplate, posource)
     66          print propfile
     67          assert propfile == [propexpected]
     68
     69 -    def test_merging_fuzzy(self):
     70          """check merging a fuzzy translation"""
     71          posource = '''#: prop\n#, fuzzy\nmsgid "value"\nmsgstr "waarde"\n'''
     72          proptemplate = '''prop=value\n'''
     73          propexpected = '''prop=value\n'''
     74          propfile = self.merge2prop(proptemplate, posource)
     75          print propfile
     76          assert propfile == [propexpected]
     77
     78 -    def test_merging_propertyless_template(self):
     79          """check that when merging with a template with no property values that we copy the template"""
     80          posource = ""
     81          proptemplate = "# A comment\n"
     82          propexpected = proptemplate
     83          propfile = self.merge2prop(proptemplate, posource)
     84          print propfile
     85          assert propfile == [propexpected]
     86
     87 -    def test_personalities(self):
     88          """test that we output correctly for Java and Mozilla style property files.  Mozilla uses Unicode, while Java uses escaped Unicode"""
     89          posource = '''#: prop\nmsgid "value"\nmsgstr "ṽḁḽṻḝ"\n'''
     90          proptemplate = '''prop  =  value\n'''
     91          propexpectedjava = '''prop  =  \\u1E7D\\u1E01\\u1E3D\\u1E7B\\u1E1D\n'''
     92          propfile = self.merge2prop(proptemplate, posource)
     93          print propfile
     94          assert propfile == [propexpectedjava]
     95          propexpectedmozilla = '''prop  =  ṽḁḽṻḝ\n'''
     96          propfile = self.merge2prop(proptemplate, posource, personality="mozilla")
     97          print propfile
     98          assert propfile == [propexpectedmozilla]
     99
    100 -class TestPO2PropCommand(test_convert.TestConvertCommand, TestPO2Prop):
    101      """Tests running actual po2prop commands on files"""
    102      convertmodule = po2prop
    103      defaultoptions = {"progress": "none"}
    104
    105 -    def test_help(self):
    106          """tests getting help"""
    107          options = test_convert.TestConvertCommand.test_help(self)
    108          options = self.help_check(options, "-t TEMPLATE, --template=TEMPLATE")
    109          options = self.help_check(options, "--fuzzy")
    110          options = self.help_check(options, "--personality=TYPE")
    111          options = self.help_check(options, "--nofuzzy", last=True)
    112