1
2
3 from translate.convert import txt2po
4 from translate.convert import test_convert
5 from translate.misc import wStringIO
6 from translate.storage import txt
7
9 - def txt2po(self, txtsource, template=None):
10 """helper that converts txt source to po source without requiring files"""
11 inputfile = wStringIO.StringIO(txtsource)
12 inputtxt = txt.TxtFile(inputfile)
13 convertor = txt2po.txt2po()
14 outputpo = convertor.convertstore(inputtxt)
15 return outputpo
16
18 """checks that the pofile contains a single non-header element, and returns it"""
19 print str(storage)
20 assert len(storage.units) == 1
21 return storage.units[0]
22
24 """test the most basic txt conversion"""
25 txtsource = "A simple string"
26 poexpected = '''#: :1
27 msgid "A simple string"
28 msgstr ""
29 '''
30 poresult = self.txt2po(txtsource)
31 assert str(poresult.units[1]) == poexpected
32
34 """test that we can handle txt with multiple units"""
35 txtsource = """First unit
36 Still part of first unit
37
38 Second unit is a heading
39 ------------------------
40
41 Third unit with blank after but no more units.
42
43 """
44 poresult = self.txt2po(txtsource)
45 assert poresult.units[0].isheader()
46 assert len(poresult.units) == 4
47
49 """Remove carriage returns from files in dos format."""
50 txtsource = '''The rapid expansion of telecommunications infrastructure in recent years has\r
51 helped to bridge the digital divide to a limited extent.\r
52 '''
53
54 txtexpected = '''The rapid expansion of telecommunications infrastructure in recent years has
55 helped to bridge the digital divide to a limited extent.'''
56
57 poresult = self.txt2po(txtsource)
58 pounit = poresult.units[1]
59 assert str(pounit.getsource()) == txtexpected
60
62 - def doku2po(self, txtsource, template=None):
63 """helper that converts dokuwiki source to po source without requiring files."""
64 inputfile = wStringIO.StringIO(txtsource)
65 inputtxt = txt.TxtFile(inputfile, flavour="dokuwiki")
66 convertor = txt2po.txt2po()
67 outputpo = convertor.convertstore(inputtxt)
68 return outputpo
69
71 """checks that the pofile contains a single non-header element, and returns it"""
72 print str(storage)
73 assert len(storage.units) == 1
74 return storage.units[0]
75
77 """Tests that we can convert some basic things."""
78 dokusource = """=====Heading=====
79
80 This is a wiki page.
81 """
82 poresult = self.doku2po(dokusource)
83 assert poresult.units[0].isheader()
84 assert len(poresult.units) == 3
85 assert poresult.units[1].source == "Heading"
86 assert poresult.units[2].source == "This is a wiki page."
87
89 """Tests that we can convert some basic things."""
90 dokusource = """ * This is a fact.
91 * This is a fact.
92 """
93 poresult = self.doku2po(dokusource)
94 assert poresult.units[0].isheader()
95 assert len(poresult.units) == 3
96 assert poresult.units[1].source == "This is a fact."
97 assert poresult.units[2].source == "This is a fact."
98
100 """Tests that we can convert some basic things."""
101 dokusource = """ - This is an item.
102 - This is an item.
103 """
104 poresult = self.doku2po(dokusource)
105 assert poresult.units[0].isheader()
106 assert len(poresult.units) == 3
107 assert poresult.units[1].source == "This is an item."
108 assert poresult.units[2].source == "This is an item."
109
111 """Tests that we can convert some basic things."""
112 dokusource = """ ===== Heading =====
113 * This is an item.
114 * This is a subitem.
115 * This is a tabbed item.
116 """
117 poresult = self.doku2po(dokusource)
118 assert poresult.units[0].isheader()
119 assert len(poresult.units) == 5
120 assert poresult.units[1].source == "Heading"
121 assert poresult.units[2].source == "This is an item."
122 assert poresult.units[3].source == "This is a subitem."
123 assert poresult.units[4].source == "This is a tabbed item."
124
126 """Tests running actual txt2po commands on files"""
127 convertmodule = txt2po
128 defaultoptions = {"progress": "none"}
129
137