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
)
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
38 print "*%s*" % txtfile
.units
[0]
39 assert str(txtfile
) == txtsource
40 assert self
.txtregen(txtsource
) == txtsource