3 from translate
.convert
import po2ts
4 from translate
.convert
import test_convert
5 from translate
.misc
import wStringIO
6 from translate
.storage
import po
9 def po2ts(self
, posource
):
10 """helper that converts po source to ts source without requiring files"""
11 inputfile
= wStringIO
.StringIO(posource
)
12 inputpo
= po
.pofile(inputfile
)
13 convertor
= po2ts
.po2ts()
14 outputts
= convertor
.convertstore(inputpo
)
17 def singleelement(self
, storage
):
18 """checks that the pofile contains a single non-header element, and returns it"""
19 assert len(storage
.units
) == 1
20 return storage
.units
[0]
22 def test_simpleunit(self
):
23 """checks that a simple po entry definition converts properly to a ts entry"""
24 minipo
= r
'''#: term.cpp
27 tsfile
= self
.po2ts(minipo
)
29 assert "<name>term.cpp</name>" in tsfile
30 assert "<source>Term</source>" in tsfile
31 assert "<translation>asdf</translation>" in tsfile
32 assert "<comment>" not in tsfile
34 def test_fullunit(self
):
35 """check that an entry with various settings is converted correctly"""
36 posource
= '''# Translator comment
42 tsfile
= self
.po2ts(posource
)
44 # The other section are a duplicate of test_simplentry
45 # FIXME need to think about auto vs trans comments maybe in TS v1.1
46 assert "<comment>Translator comment</comment>" in tsfile
48 def test_fuzzyunit(self
):
49 """check that we handle fuzzy units correctly"""
50 posource
= '''#: term.cpp
54 tsfile
= self
.po2ts(posource
)
56 assert '''<translation type="unfinished">Target</translation>''' in tsfile
58 def test_obsolete(self
):
59 """test that we can take back obsolete messages"""
60 posource
= '''#. (obsolete)
64 tsfile
= self
.po2ts(posource
)
66 assert '''<translation type="obsolete">Target</translation>''' in tsfile
68 def test_duplicates(self
):
69 """test that we can handle duplicates in the same context block"""
70 posource
= '''#: @@@#1
78 tsfile
= self
.po2ts(posource
)
80 assert tsfile
.find("English") != tsfile
.rfind("English")
83 class TestPO2TSCommand(test_convert
.TestConvertCommand
, TestPO2TS
):
84 """Tests running actual po2ts commands on files"""
88 """tests getting help"""
89 options
= test_convert
.TestConvertCommand
.test_help(self
)
90 options
= self
.help_check(options
, "-c CONTEXT, --context=CONTEXT")
91 options
= self
.help_check(options
, "-t TEMPLATE, --template=TEMPLATE", last
=True)