fix git support for v1.5.3 (or higher) by setting "--work-tree"
[translate_toolkit.git] / storage / test_mo.py
blob4a20232a26b9352b8bf365027795db197d5c5cbe
1 #!/usr/bin/env python
3 import subprocess
4 import os.path
6 from translate.storage import test_base
7 from translate.storage import mo
9 class TestMOUnit(test_base.TestTranslationUnit):
10 UnitClass = mo.mounit
12 posources = [
13 r'''
14 msgid ""
15 msgstr ""
16 "PO-Revision-Date: 2006-02-09 23:33+0200\n"
17 "MIME-Version: 1.0\n"
18 "Content-Type: text/plain; charset=UTF-8\n"
19 "Content-Transfer-Encoding: 8-bit\n"
20 ''',
21 r'''
22 msgid ""
23 msgstr ""
24 "PO-Revision-Date: 2006-02-09 23:33+0200\n"
25 "MIME-Version: 1.0\n"
26 "Content-Type: text/plain; charset=UTF-8\n"
27 "Content-Transfer-Encoding: 8-bit\n"
29 msgid "plant"
30 msgstr ""
31 ''',
32 r'''
33 msgid ""
34 msgstr ""
35 "PO-Revision-Date: 2006-02-09 23:33+0200\n"
36 "MIME-Version: 1.0\n"
37 "Content-Type: text/plain; charset=UTF-8\n"
38 "Content-Transfer-Encoding: 8-bit\n"
40 msgid "plant"
41 msgstr ""
43 msgid ""
44 "_: Noun\n"
45 "convert"
46 msgstr "bekeerling"
47 ''',
48 r'''
49 msgid ""
50 msgstr ""
51 "PO-Revision-Date: 2006-02-09 23:33+0200\n"
52 "MIME-Version: 1.0\n"
53 "Content-Type: text/plain; charset=UTF-8\n"
54 "Content-Transfer-Encoding: 8-bit\n"
56 msgid "plant"
57 msgstr ""
59 msgid ""
60 "_: Noun\n"
61 "convert"
62 msgstr "bekeerling"
64 msgctxt "verb"
65 msgid ""
66 "convert"
67 msgstr "omskakel"
68 ''',
69 r'''
70 msgid ""
71 msgstr ""
72 "PO-Revision-Date: 2006-02-09 23:33+0200\n"
73 "MIME-Version: 1.0\n"
74 "Content-Type: text/plain; charset=UTF-8\n"
75 "Content-Transfer-Encoding: 8-bit\n"
77 msgid "plant"
78 msgstr ""
80 msgid ""
81 "_: Noun\n"
82 "convert"
83 msgstr "bekeerling"
85 msgctxt "verb"
86 msgid ""
87 "convert"
88 msgstr "omskakel"
90 msgid "tree"
91 msgid_plural "trees"
92 msgstr[0] ""
93 ''']
95 class TestMOFile(test_base.TestTranslationStore):
96 StoreClass = mo.mofile
98 def get_mo_and_po(self):
99 return (os.path.abspath(self.filename + '.po'),
100 os.path.abspath(self.filename + '.msgfmt.mo'),
101 os.path.abspath(self.filename + '.pocompile.mo'))
103 def remove_po_and_mo(self):
104 for file in self.get_mo_and_po():
105 if os.path.exists(file):
106 os.remove(file)
108 def setup_method(self, method):
109 test_base.TestTranslationStore.setup_method(self, method)
110 self.remove_po_and_mo()
112 def teardown_method(self, method):
113 test_base.TestTranslationStore.teardown_method(self, method)
114 self.remove_po_and_mo()
116 def test_output(self):
117 for posource in posources:
118 PO_FILE, MO_MSGFMT, MO_POCOMPILE = self.get_mo_and_po()
120 out_file = open(PO_FILE, 'w')
121 out_file.write(posource)
122 out_file.close()
124 subprocess.call(['msgfmt', PO_FILE, '-o', MO_MSGFMT])
125 subprocess.call(['pocompile', PO_FILE, MO_POCOMPILE])
127 mo_msgfmt_f = open(MO_MSGFMT)
128 mo_pocompile_f = open(MO_POCOMPILE)
130 try:
131 assert mo_msgfmt_f.read() == mo_pocompile_f.read()
132 finally:
133 mo_msgfmt_f.close()
134 mo_pocompile_f.close()