fix git support for v1.5.3 (or higher) by setting "--work-tree"
[translate_toolkit.git] / convert / test_ts2po.py
blobc5a11dd96137f699709709be35c0b1378377c397
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 from translate.convert import ts2po
5 from translate.convert import test_convert
6 from translate.misc import wStringIO
8 class TestTS2PO:
9 def ts2po(self, tssource):
10 converter = ts2po.ts2po()
11 tsfile = wStringIO.StringIO(tssource)
12 outputpo = converter.convertfile(tsfile)
13 print "The generated po:"
14 print str(outputpo)
15 return outputpo
17 def test_blank(self):
18 """tests blank conversion"""
19 tssource = '''<!DOCTYPE TS><TS>
20 <context>
21 <name>MainWindowBase</name>
22 <message>
23 <source>Project:</source>
24 <translation type="unfinished"></translation>
25 </message>
26 </context>
27 </TS>
28 '''
29 pofile = self.ts2po(tssource)
30 assert len(pofile.units) == 2
31 assert pofile.units[1].source == "Project:"
32 assert pofile.units[1].target == ""
33 assert pofile.units[1].getlocations()[0].startswith("MainWindowBase")
34 assert not pofile.units[1].isfuzzy()
36 def test_basic(self):
37 """tests basic conversion"""
38 tssource = '''<!DOCTYPE TS><TS>
39 <context>
40 <name>AboutDialog</name>
41 <message>
42 <source>&amp;About</source>
43 <translation>&amp;Giới thiệu</translation>
44 </message>
45 </context>
46 </TS>
47 '''
48 pofile = self.ts2po(tssource)
49 assert len(pofile.units) == 2
50 assert pofile.units[1].source == "&About"
51 assert pofile.units[1].target == u"&Giới thiệu"
52 assert pofile.units[1].getlocations()[0].startswith("AboutDialog")
54 def test_unfinished(self):
55 """tests unfinished conversion"""
56 tssource = '''<!DOCTYPE TS><TS>
57 <context>
58 <name>MainWindowBase</name>
59 <message>
60 <source>Project:</source>
61 <translation type="unfinished">Projek vergardering</translation>
62 </message>
63 </context>
64 </TS>
65 '''
66 pofile = self.ts2po(tssource)
67 assert len(pofile.units) == 2
68 assert pofile.units[1].source == "Project:"
69 assert pofile.units[1].target == "Projek vergardering"
70 assert pofile.units[1].getlocations()[0].startswith("MainWindowBase")
71 assert pofile.units[1].isfuzzy()
73 def test_multiline(self):
74 """tests multiline message conversion"""
75 tssource = '''<!DOCTYPE TS><TS>
76 <context>
77 <name>@default</name>
78 <message>
79 <source>Source with
80 new line</source>
81 <translation>Test with
82 new line</translation>
83 </message>
84 </context>
85 </TS>
86 '''
87 pofile = self.ts2po(tssource)
88 assert len(pofile.units) == 2
89 assert pofile.units[1].source == "Source with\nnew line"
90 assert pofile.units[1].target == "Test with\nnew line"
91 assert pofile.units[1].getlocations()[0].startswith("@default")
93 def test_obsolete(self):
94 """test the handling of obsolete TS entries"""
95 tssource = '''<!DOCTYPE TS><TS>
96 <context>
97 <name>Obsoleted</name>
98 <message>
99 <source>Failed</source>
100 <translation type="obsolete">Mislukt</translation>
101 </message>
102 </context>
103 </TS>
105 pofile = self.ts2po(tssource)
106 assert pofile.units[1].getnotes("developer") == "(obsolete)"
107 # Test that we aren't following the old style
108 assert "_ OBSOLETE" not in pofile.units[1].getnotes()
110 class TestTS2POCommand(test_convert.TestConvertCommand, TestTS2PO):
111 """Tests running actual ts2po commands on files"""
112 convertmodule = ts2po
114 def test_help(self):
115 """tests getting help"""
116 options = test_convert.TestConvertCommand.test_help(self)
117 options = self.help_check(options, "--duplicates=DUPLICATESTYLE")
118 options = self.help_check(options, "-P, --pot", last=True)