Package translate :: Package storage :: Module test_txt

[hide private]
[frames] | no frames]

# Source Code for Module translate.storage.test_txt

     1  #!/usr/bin/env python
     2
     3  from translate.storage import txt
     4  from translate.storage import test_monolingual
     5  from translate.misc import wStringIO
     6
     7 -class TestTxtUnit(test_monolingual.TestMonolingualUnit):
     8      UnitClass = txt.TxtUnit
     9
    10
    11 -class TestTxtFile(test_monolingual.TestMonolingualStore):
    12      StoreClass = txt.TxtFile
    13 -    def txtparse(self, txtsource):
    14          """helper that parses txt source without requiring files"""
    15          dummyfile = wStringIO.StringIO(txtsource)
    16          txtfile = self.StoreClass(dummyfile)
    17          return txtfile
    18
    19 -    def txtregen(self, txtsource):
    20          """helper that converts txt source to txtfile object and back"""
    21          return str(self.txtparse(txtsource))
    22
    23 -    def test_simpleblock(self):
    24          """checks that a simple txt block is parsed correctly"""
    25          txtsource = 'bananas for sale'
    26          txtfile = self.txtparse(txtsource)
    27          assert len(txtfile.units) == 1
    28          assert txtfile.units[0].source == txtsource
    29          assert self.txtregen(txtsource) == txtsource
    30
    31 -    def test_multipleblocks(self):
    32          """ check that multiple blocks are parsed correctly"""
    33          txtsource = '''One\nOne\n\nTwo\n---\n\nThree'''
    34          txtfile = self.txtparse(txtsource)
    35          assert len(txtfile.units) == 3
    36          print txtsource
    37          print str(txtfile)
    38          print "*%s*" % txtfile.units[0]
    39          assert str(txtfile) == txtsource
    40          assert self.txtregen(txtsource) == txtsource
    41