12 class TestPOFramework(unittest.TestCase):
14 po_sources = ('../../Open-ILS/web/opac/locale/en-US/*.dtd',
15 '../../Open-ILS/xul/staff_client/chrome/locale/en-US/*.properties',
16 '../../Open-ILS/examples/fm_IDL.xml',
17 '../../Open-ILS/src/extras/ils_events.xml',
18 '../../Open-ILS/src/sql/Pg/950.data.seed-values.sql')
20 po_tmp_files = ('tests/tmp/po/en-US/test.properties.pot', 'tests/tmp/po/ll-LL/temp.properties.po')
21 pot_dir = 'tests/tmp/po/en-US'
22 po_in_dir = 'POINDIR=tests/tmp/po'
23 po_out_dir = 'POOUTDIR=tests/tmp/po'
25 locale_dir = 'tests/tmp/po/ll-LL'
26 project_dir = 'tests/tmp/locale'
27 po_tmp_dirs = (project_dir + '/' + locale, project_dir, locale_dir, pot_dir, project_dir, 'tests/tmp')
28 newdir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
33 devnull = open('/dev/null', 'w')
35 os.mkdir(self.project_dir)
36 subprocess.Popen(('cp', '-r', 'po', 'tests/tmp'), 0, None, None, devnull, devnull).wait()
37 subprocess.Popen(('make', 'LOCALE=ll-LL', 'POTSRC=tests/tmp/po/en-US', self.po_in_dir, self.po_out_dir, 'newpot'), 0, None, None, devnull, devnull).wait()
38 subprocess.Popen(('make', 'LOCALE=ll-LL', 'POTSRC=tests/tmp/po/en-US', self.po_in_dir, self.po_out_dir, 'newpo'), 0, None, None, devnull, devnull).wait()
39 subprocess.Popen(('make', 'LOCALE=ll-LL', 'PROJECT=tests/tmp/locale', self.po_in_dir, 'newproject'), 0, None, None, devnull, devnull).wait()
44 # devnull = open('/dev/null', 'w')
45 # subprocess.Popen(('cp', '-r', 'tests/tmp', 'done'), 0, None, None, devnull, devnull).wait()
46 # for root, dirs, files in os.walk(os.path.join(self.newdir, 'tests/tmp'), topdown=False):
48 # os.remove(os.path.join(root, name))
50 # os.rmdir(os.path.join(root, name))
51 # if os.access(os.path.join(self.newdir, 'tests/tmp'), os.F_OK):
52 # os.rmdir(os.path.join(self.newdir, 'tests/tmp'))
54 def testnewpofiles(self):
55 # Create a brand new set of PO files from our en-US project files.
56 # Compare the files generated in the po/ll-LL directory with
57 # the number expected by a manual count of our known sources.
59 for po_dir in self.po_sources:
60 for path in glob.glob(po_dir):
61 po_files.append(os.path.basename(path) + '.po')
63 new_pofiles = os.listdir(self.locale_dir)
65 self.assertEqual(len(po_files), len(new_pofiles))
67 def testnewprojectfiles(self):
68 # Create a brand new set of project files from PO files.
69 # Compare the files created with a manual count of our known sources.
71 for po_dir in self.po_sources:
72 for path in glob.glob(po_dir):
73 moz_files.append(os.path.basename(path))
75 new_mozfiles = os.listdir(self.locale_dir)
77 self.assertEqual(len(moz_files), len(new_mozfiles))
79 def testtranslatedfile(self):
80 # "Translate" strings in a PO file, then generate the project
81 # files to ensure that the translated string appears in the output.
83 # Create the "translated" PO file
84 commonpo = os.path.join(self.locale_dir, 'common.properties.po')
85 testpo = os.path.join(self.locale_dir, 'test.properties.po')
86 commonfile = open(commonpo)
87 testfile = open(testpo, 'w')
88 for line in commonfile:
89 line = re.sub(r'^msgstr ""', r'msgstr "abcdefg"', line)
94 os.rename(testpo, commonpo)
96 # Create the "translated" properties file
97 commonprops = os.path.join(self.project_dir, self.locale, 'common.properties')
98 testprops = os.path.join(self.locale_dir, 'test.properties')
99 commonfile = open(commonprops)
100 testfile = open(testprops, 'w')
101 for line in commonfile:
102 line = re.sub(r'^(.*?)=.*?$', r'\1=abcdefg', line)
107 # Regenerate the project files to get the translated strings in place
108 devnull = open('/dev/null', 'w')
109 subprocess.Popen(('make', 'LOCALE=ll-LL', self.po_in_dir, self.po_out_dir, 'updateproject'), 0, None, None, devnull, devnull).wait()
111 self.assertEqual(filecmp.cmp(commonprops, testprops), 1)
113 def testupdatepo(self):
114 # Add strings to a POT file, then ensure that the updated PO files
115 # include the new strings
117 # Create the "template" PO file
118 commonpo = os.path.join(self.locale_dir, 'common.properties.po')
119 testpo = os.path.join(self.locale_dir, 'test.properties.po')
120 commonfile = open(commonpo)
121 testfile = open(testpo, 'w')
122 for line in commonfile:
123 line = re.sub(r'common.properties$', r'test.properties', line)
128 # Create the test POT file
129 commonpot = os.path.join(self.pot_dir, 'common.properties.pot')
130 testpot = os.path.join(self.pot_dir, 'test.properties.pot')
131 commonfile = open(commonpot)
132 testfile = open(testpot, 'w')
133 for line in commonfile:
134 line = re.sub(r'common.properties$', r'test.properties', line)
137 testfile.write("\n#: common.testupdatepo")
138 testfile.write('\nmsgid "TESTUPDATEPO"')
139 testfile.write('\nmsgstr ""')
142 # Update the PO files to get the translated strings in place
143 devnull = open('/dev/null', 'w')
144 subprocess.Popen(('make', 'LOCALE=ll-LL', self.po_in_dir, self.po_out_dir, 'updatepo'), 0, None, None, devnull, devnull).wait()
146 commonprops = os.path.join(self.locale_dir, 'common.properties.po')
147 tempprops = os.path.join(self.locale_dir, 'temp.properties.po')
148 testprops = os.path.join(self.locale_dir, 'test.properties.po')
150 # Munge the common file to make it what we expect it to be
151 commonfile = open(commonprops, 'a+')
152 commonfile.write("\n#: common.testupdatepo")
153 commonfile.write('\nmsgid "TESTUPDATEPO"')
154 commonfile.write('\nmsgstr ""')
157 shutil.copyfile(commonprops, tempprops)
158 commonfile = open(commonprops, 'w')
159 tempfile = open(testpot)
160 for line in tempfile:
161 line = re.sub(r'common.properties$', r'test.properties', line)
162 line = re.sub(r'^"Project-Id-Version: .*"$', r'"Project-Id-Version: PACKAGE VERSION\\n"', line)
163 commonfile.write(line)
164 commonfile.write("\n")
168 # Compare the updated PO files - they should be the same
169 self.assertEqual(filecmp.cmp(commonprops, testprops), 1)
171 if __name__ == '__main__':