fix git support for v1.5.3 (or higher) by setting "--work-tree"
[translate_toolkit.git] / storage / test_txt.py
blob57ddac75a6e2d81ed0d3e341f8c5ef49379e1e57
1 #!/usr/bin/env python
3 from translate.storage import txt
4 from translate.storage import test_monolingual
5 from translate.misc import wStringIO
7 class TestTxtUnit(test_monolingual.TestMonolingualUnit):
8 UnitClass = txt.TxtUnit
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
19 def txtregen(self, txtsource):
20 """helper that converts txt source to txtfile object and back"""
21 return str(self.txtparse(txtsource))
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
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