Package translate :: Package convert :: Module test_po2php

[hide private]
[frames] | no frames]

# Source Code for Module translate.convert.test_po2php

     1  #!/usr/bin/env python
     2  # -*- coding: utf-8 -*-
     3
     4  from translate.convert import po2php
     5  from translate.convert import test_convert
     6  from translate.misc import wStringIO
     7  from translate.storage import po
     8
     9 -class TestPO2Php:
    10 -    def po2php(self, posource):
    11          """helper that converts po source to .php source without requiring files"""
    12          inputfile = wStringIO.StringIO(posource)
    13          inputpo = po.pofile(inputfile)
    14          convertor = po2php.po2php()
    15          outputphp = convertor.convertstore(inputpo)
    16          return outputphp
    17
    18 -    def merge2php(self, phpsource, posource):
    19          """helper that merges po translations to .php source without requiring files"""
    20          inputfile = wStringIO.StringIO(posource)
    21          inputpo = po.pofile(inputfile)
    22          templatefile = wStringIO.StringIO(phpsource)
    23          #templatephp = php.phpfile(templatefile)
    24          convertor = po2php.rephp(templatefile)
    25          outputphp = convertor.convertstore(inputpo)
    26          print outputphp
    27          return outputphp
    28
    29 -    def test_merging_simple(self):
    30          """check the simplest case of merging a translation"""
    31          posource = '''#: $lang['name']\nmsgid "value"\nmsgstr "waarde"\n'''
    32          phptemplate = '''$lang['name'] = 'value';\n'''
    33          phpexpected = '''$lang['name'] = 'waarde';\n'''
    34          phpfile = self.merge2php(phptemplate, posource)
    35          print phpfile
    36          assert phpfile == [phpexpected]
    37
    38 -    def test_space_preservation(self):
    39          """check that we preserve any spacing in php files when merging"""
    40          posource = '''#: $lang['name']\nmsgid "value"\nmsgstr "waarde"\n'''
    41          phptemplate = '''$lang['name']  =  'value';\n'''
    42          phpexpected = '''$lang['name']  =  'waarde';\n'''
    43          phpfile = self.merge2php(phptemplate, posource)
    44          print phpfile
    45          assert phpfile == [phpexpected]
    46
    47 -    def test_merging_blank_entries(self):
    48          """check that we can correctly merge entries that are blank in the template"""
    49          posource = '''#: accesskey-accept
    50  msgid ""
    51  "_: accesskey-accept\n"
    52  ""
    53  msgstr ""'''
    54          phptemplate = '''$lang['accesskey-accept'] = '';\n'''
    55          phpexpected = '''$lang['accesskey-accept'] = '';\n'''
    56          phpfile = self.merge2php(phptemplate, posource)
    57          print phpfile
    58          assert phpfile == [phpexpected]
    59
    60 -    def test_merging_fuzzy(self):
    61          """check merging a fuzzy translation"""
    62          posource = '''#: $lang['name']\n#, fuzzy\nmsgid "value"\nmsgstr "waarde"\n'''
    63          phptemplate = '''$lang['name']  =  'value';\n'''
    64          phpexpected = '''$lang['name']  =  'value';\n'''
    65          phpfile = self.merge2php(phptemplate, posource)
    66          print phpfile
    67          assert phpfile == [phpexpected]
    68
    69 -    def test_locations_with_spaces(self):
    70          """check that a location with spaces in php but spaces removed in PO is used correctly"""
    71          posource = '''#: $lang['name']\nmsgid "value"\nmsgstr "waarde"\n'''
    72          phptemplate = '''$lang[ 'name' ]  =  'value';\n'''
    73          phpexpected = '''$lang[ 'name' ]  =  'waarde';\n'''
    74          phpfile = self.merge2php(phptemplate, posource)
    75          print phpfile
    76          assert phpfile == [phpexpected]
    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 -class TestPO2PhpCommand(test_convert.TestConvertCommand, TestPO2Php):
    88      """Tests running actual po2php commands on files"""
    89      convertmodule = po2php
    90      defaultoptions = {"progress": "none"}
    91
    92 -    def test_help(self):
    93          """tests getting help"""
    94          options = test_convert.TestConvertCommand.test_help(self)
    95          options = self.help_check(options, "-t TEMPLATE, --template=TEMPLATE")
    96          options = self.help_check(options, "--fuzzy")
    97          options = self.help_check(options, "--nofuzzy", last=True)
    98