Package translate :: Package convert :: Module test_txt2po

[hide private]
[frames] | no frames]

# Source Code for Module translate.convert.test_txt2po

      1  #!/usr/bin/env python
      2
      3  from translate.convert import txt2po
      4  from translate.convert import test_convert
      5  from translate.misc import wStringIO
      6  from translate.storage import txt
      7
      8 -class TestTxt2PO:
      9 -    def txt2po(self, txtsource, template=None):
     10          """helper that converts txt source to po source without requiring files"""
     11          inputfile = wStringIO.StringIO(txtsource)
     12          inputtxt = txt.TxtFile(inputfile)
     13          convertor = txt2po.txt2po()
     14          outputpo = convertor.convertstore(inputtxt)
     15          return outputpo
     16
     17 -    def singleelement(self, storage):
     18          """checks that the pofile contains a single non-header element, and returns it"""
     19          print str(storage)
     20          assert len(storage.units) == 1
     21          return storage.units[0]
     22
     23 -    def test_simple(self):
     24          """test the most basic txt conversion"""
     25          txtsource = "A simple string"
     26          poexpected = '''#: :1
     27  msgid "A simple string"
     28  msgstr ""
     29  '''
     30          poresult = self.txt2po(txtsource)
     31          assert str(poresult.units[1]) == poexpected
     32
     33 -    def test_miltiple_units(self):
     34          """test that we can handle txt with multiple units"""
     35          txtsource = """First unit
     36  Still part of first unit
     37
     38  Second unit is a heading
     39  ------------------------
     40
     41  Third unit with blank after but no more units.
     42
     43  """
     44          poresult = self.txt2po(txtsource)
     45          assert poresult.units[0].isheader()
     46          assert len(poresult.units) == 4
     47
     48 -    def test_carriage_return(self):
     49          """Remove carriage returns from files in dos format."""
     50          txtsource = '''The rapid expansion of telecommunications infrastructure in recent years has\r
     51  helped to bridge the digital divide to a limited extent.\r
     52  '''
     53
     54          txtexpected = '''The rapid expansion of telecommunications infrastructure in recent years has
     55  helped to bridge the digital divide to a limited extent.'''
     56
     57          poresult = self.txt2po(txtsource)
     58          pounit = poresult.units[1]
     59          assert str(pounit.getsource()) == txtexpected
     60
     61 -class TestDoku2po:
     62 -    def doku2po(self, txtsource, template=None):
     63          """helper that converts dokuwiki source to po source without requiring files."""
     64          inputfile = wStringIO.StringIO(txtsource)
     65          inputtxt = txt.TxtFile(inputfile, flavour="dokuwiki")
     66          convertor = txt2po.txt2po()
     67          outputpo = convertor.convertstore(inputtxt)
     68          return outputpo
     69
     70 -    def singleelement(self, storage):
     71          """checks that the pofile contains a single non-header element, and returns it"""
     72          print str(storage)
     73          assert len(storage.units) == 1
     74          return storage.units[0]
     75
     76 -    def test_basic(self):
     77          """Tests that we can convert some basic things."""
     78          dokusource = """=====Heading=====
     79
     80  This is a wiki page.
     81  """
     82          poresult = self.doku2po(dokusource)
     83          assert poresult.units[0].isheader()
     84          assert len(poresult.units) == 3
     85          assert poresult.units[1].source == "Heading"
     86          assert poresult.units[2].source == "This is a wiki page."
     87
     88 -    def test_bullets(self):
     89          """Tests that we can convert some basic things."""
     90          dokusource = """  * This is a fact.
     91    * This is a fact.
     92  """
     93          poresult = self.doku2po(dokusource)
     94          assert poresult.units[0].isheader()
     95          assert len(poresult.units) == 3
     96          assert poresult.units[1].source == "This is a fact."
     97          assert poresult.units[2].source == "This is a fact."
     98
     99 -    def test_numbers(self):
    100          """Tests that we can convert some basic things."""
    101          dokusource = """  - This is an item.
    102    - This is an item.
    103  """
    104          poresult = self.doku2po(dokusource)
    105          assert poresult.units[0].isheader()
    106          assert len(poresult.units) == 3
    107          assert poresult.units[1].source == "This is an item."
    108          assert poresult.units[2].source == "This is an item."
    109
    110 -    def test_spacing(self):
    111          """Tests that we can convert some basic things."""
    112          dokusource = """ =====         Heading  =====
    113    * This is an item.
    114      * This is a subitem.
    115          * This is a tabbed item.
    116  """
    117          poresult = self.doku2po(dokusource)
    118          assert poresult.units[0].isheader()
    119          assert len(poresult.units) == 5
    120          assert poresult.units[1].source == "Heading"
    121          assert poresult.units[2].source == "This is an item."
    122          assert poresult.units[3].source == "This is a subitem."
    123          assert poresult.units[4].source == "This is a tabbed item."
    124
    125 -class TestTxt2POCommand(test_convert.TestConvertCommand, TestTxt2PO):
    126      """Tests running actual txt2po commands on files"""
    127      convertmodule = txt2po
    128      defaultoptions = {"progress": "none"}
    129
    130 -    def test_help(self):
    131          """tests getting help"""
    132          options = test_convert.TestConvertCommand.test_help(self)
    133          options = self.help_check(options, "-P, --pot")
    134          options = self.help_check(options, "--duplicates")
    135          options = self.help_check(options, "--encoding")
    136          options = self.help_check(options, "--flavour", last=True)
    137