Package translate :: Package storage :: Module test_poxliff

[hide private]
[frames] | no frames]

# Source Code for Module translate.storage.test_poxliff

     1  #!/usr/bin/env python
     2
     3  from translate.storage import poxliff
     4  from translate.storage import test_xliff
     5  from translate.misc.multistring import multistring
     6
     7 -class TestPOXLIFFUnit(test_xliff.TestXLIFFUnit):
     8      UnitClass = poxliff.PoXliffUnit
     9
    10 -    def test_plurals(self):
    11          """Tests that plurals are handled correctly."""
    12          unit = self.UnitClass(multistring(["Cow", "Cows"]))
    13          print type(unit.source)
    14          print repr(unit.source)
    15          assert isinstance(unit.source, multistring)
    16          assert unit.source.strings == ["Cow", "Cows"]
    17          assert unit.source == "Cow"
    18
    19          unit.target = ["Koei", "Koeie"]
    20          assert isinstance(unit.target, multistring)
    21          assert unit.target.strings == ["Koei", "Koeie"]
    22          assert unit.target == "Koei"
    23
    24          unit.target = [u"Sk\u00ear", u"Sk\u00eare"]
    25          assert isinstance(unit.target, multistring)
    26          assert unit.target.strings == [u"Sk\u00ear", u"Sk\u00eare"]
    27          assert unit.target.strings == [u"Sk\u00ear", u"Sk\u00eare"]
    28          assert unit.target == u"Sk\u00ear"
    29
    30 -    def test_ids(self):
    31          """Tests that ids are assigned correctly, especially for plurals"""
    32          unit = self.UnitClass("gras")
    33          assert not unit.getid()
    34          unit.setid("4")
    35          assert unit.getid() == "4"
    36
    37          unit = self.UnitClass(multistring(["shoe", "shoes"]))
    38          assert not unit.getid()
    39          unit.setid("20")
    40          assert unit.getid() == "20"
    41          assert unit.units[1].getid() == "20[1]"
    42
    43          unit.target = ["utshani", "uutshani", "uuutshani"]
    44          assert unit.getid() == "20"
    45          assert unit.units[1].getid() == "20[1]"
    46
    47 -class TestPOXLIFFfile(test_xliff.TestXLIFFfile):
    48      StoreClass = poxliff.PoXliffFile
    49      xliffskeleton = '''<?xml version="1.0" ?>
    50  <xliff version="1.1" xmlns="urn:oasis:names:tc:xliff:document:1.1">
    51    <file original="filename.po" source-language="en-US" datatype="po">
    52      <body>
    53          %s
    54      </body>
    55    </file>
    56  </xliff>'''
    57
    58 -    def test_parse(self):
    59          minixlf = self.xliffskeleton % '''<group restype="x-gettext-plurals">
    60          <trans-unit id="1[0]" xml:space="preserve">
    61              <source>cow</source>
    62              <target>inkomo</target>
    63          </trans-unit>
    64          <trans-unit id="1[1]" xml:space="preserve">
    65              <source>cows</source>
    66              <target>iinkomo</target>
    67          </trans-unit>
    68  </group>'''
    69          xlifffile = self.StoreClass.parsestring(minixlf)
    70          assert len(xlifffile.units) == 1
    71          assert xlifffile.translate("cow") == "inkomo"
    72          assert xlifffile.units[0].source == "cow"
    73          assert xlifffile.units[0].source == multistring(["cow", "cows"])
    74
    75 -    def test_notes(self):
    76          minixlf = self.xliffskeleton % '''<group restype="x-gettext-plurals">
    77          <trans-unit id="1[0]" xml:space="preserve">
    78              <source>cow</source>
    79              <target>inkomo</target>
    80  <note from="po-translator">Zulu translation of program ABC</note>
    81  <note from="developer">azoozoo come back!</note>
    82          </trans-unit>
    83          <trans-unit id="1[1]" xml:space="preserve">
    84              <source>cows</source>
    85              <target>iinkomo</target>
    86  <note from="po-translator">Zulu translation of program ABC</note>
    87  <note from="developer">azoozoo come back!</note>
    88          </trans-unit>
    89  </group>'''
    90          xlifffile = self.StoreClass.parsestring(minixlf)
    91          assert xlifffile.units[0].getnotes() == "Zulu translation of program ABC\nazoozoo come back!"
    92          assert xlifffile.units[0].getnotes("developer") == "azoozoo come back!"
    93          assert xlifffile.units[0].getnotes("po-translator") == "Zulu translation of program ABC"
    94