1   
 2   
 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 
 7   
 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) 
15          return outputts 
 16   
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] 
 21   
23          """checks that a simple po entry definition converts properly to a ts entry""" 
24          minipo = r'''#: term.cpp 
25  msgid "Term" 
26  msgstr "asdf"''' 
27          tsfile = self.po2ts(minipo) 
28          print tsfile 
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 
 33   
35          """check that an entry with various settings is converted correctly""" 
36          posource = '''# Translator comment 
37  #. Automatic comment 
38  #: location.cpp:100 
39  msgid "Source" 
40  msgstr "Target" 
41  ''' 
42          tsfile = self.po2ts(posource) 
43          print tsfile 
44           
45           
46          assert "<comment>Translator comment</comment>" in tsfile 
 47   
49          """check that we handle fuzzy units correctly""" 
50          posource = '''#: term.cpp 
51  #, fuzzy 
52  msgid "Source" 
53  msgstr "Target"''' 
54          tsfile = self.po2ts(posource) 
55          print tsfile 
56          assert '''<translation type="unfinished">Target</translation>''' in tsfile 
 57   
59          """test that we can take back obsolete messages""" 
60          posource = '''#. (obsolete) 
61  #: term.cpp 
62  msgid "Source" 
63  msgstr "Target"''' 
64          tsfile = self.po2ts(posource) 
65          print tsfile 
66          assert '''<translation type="obsolete">Target</translation>''' in tsfile 
 67           
69          """test that we can handle duplicates in the same context block""" 
70          posource = '''#: @@@#1 
71  msgid "English" 
72  msgstr "a" 
73   
74  #: @@@#3 
75  msgid "English" 
76  msgstr "b" 
77  ''' 
78          tsfile = self.po2ts(posource) 
79          print tsfile 
80          assert tsfile.find("English") != tsfile.rfind("English") 
 84      """Tests running actual po2ts commands on files""" 
85      convertmodule = po2ts 
86   
 91