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()
43 devnull = open('/dev/null', 'w')
44 subprocess.Popen(('cp', '-r', 'tests/tmp', 'done'), 0, None, None, devnull, devnull).wait()
45 for root, dirs, files in os.walk(os.path.join(self.newdir, 'tests/tmp'), topdown=False):
47 os.remove(os.path.join(root, name))
49 os.rmdir(os.path.join(root, name))
50 if os.access(os.path.join(self.newdir, 'tests/tmp'), os.F_OK):
51 os.rmdir(os.path.join(self.newdir, 'tests/tmp'))
53 def testnewpofiles(self):
54 # Create a brand new set of PO files from our en-US project files.
55 # Compare the files generated in the po/ll-LL directory with
56 # the number expected by a manual count of our known sources.
58 for po_dir in self.po_sources:
59 for path in glob.glob(po_dir):
60 po_files.append(os.path.basename(path) + '.po')
62 new_pofiles = os.listdir(self.locale_dir)
64 self.assertEqual(len(po_files), len(new_pofiles))
66 def testnewprojectfiles(self):
67 # Create a brand new set of project files from PO files.
68 # Compare the files created with a manual count of our known sources.
70 for po_dir in self.po_sources:
71 for path in glob.glob(po_dir):
72 moz_files.append(os.path.basename(path))
74 new_mozfiles = os.listdir(self.locale_dir)
76 self.assertEqual(len(moz_files), len(new_mozfiles))
78 def testtranslatedfile(self):
79 # "Translate" strings in a PO file, then generate the project
80 # files to ensure that the translated string appears in the output.
82 # Create the "translated" PO file
83 commonpo = os.path.join(self.locale_dir, 'common.properties.po')
84 testpo = os.path.join(self.locale_dir, 'test.properties.po')
85 commonfile = open(commonpo)
86 testfile = open(testpo, 'w')
87 for line in commonfile:
88 line = re.sub(r'^msgstr ""', r'msgstr "abcdefg"', line)
93 os.rename(testpo, commonpo)
95 # Create the "translated" properties file
96 commonprops = os.path.join(self.project_dir, self.locale, 'common.properties')
97 testprops = os.path.join(self.locale_dir, 'test.properties')
98 commonfile = open(commonprops)
99 testfile = open(testprops, 'w')
100 for line in commonfile:
101 line = re.sub(r'^(.*?)=.*?$', r'\1=abcdefg', line)
106 # Regenerate the project files to get the translated strings in place
107 devnull = open('/dev/null', 'w')
108 subprocess.Popen(('make', 'LOCALE=ll-LL', self.po_in_dir, self.po_out_dir, 'updateproject'), 0, None, None, devnull, devnull).wait()
110 self.assertEqual(filecmp.cmp(commonprops, testprops), 1)
112 def testupdatepo(self):
113 # Add strings to a POT file, then ensure that the updated PO files
114 # include the new strings
116 # Create the "template" PO file
117 commonpo = os.path.join(self.locale_dir, 'common.properties.po')
118 testpo = os.path.join(self.locale_dir, 'test.properties.po')
119 commonfile = open(commonpo)
120 testfile = open(testpo, 'w')
121 for line in commonfile:
122 line = re.sub(r'common.properties$', r'test.properties', line)
127 # Create the test POT file
128 commonpot = os.path.join(self.pot_dir, 'common.properties.pot')
129 testpot = os.path.join(self.pot_dir, 'test.properties.pot')
130 commonfile = open(commonpot)
131 testfile = open(testpot, 'w')
132 for line in commonfile:
133 line = re.sub(r'common.properties$', r'test.properties', line)
136 testfile.write("\n#: common.testupdatepo")
137 testfile.write('\nmsgid "TESTUPDATEPO"')
138 testfile.write('\nmsgstr ""')
141 # Update the PO files to get the translated strings in place
142 devnull = open('/dev/null', 'w')
143 subprocess.Popen(('make', 'LOCALE=ll-LL', self.po_in_dir, self.po_out_dir, 'updatepo'), 0, None, None, devnull, devnull).wait()
145 commonprops = os.path.join(self.locale_dir, 'common.properties.po')
146 tempprops = os.path.join(self.locale_dir, 'temp.properties.po')
147 testprops = os.path.join(self.locale_dir, 'test.properties.po')
149 # Munge the common file to make it what we expect it to be
150 commonfile = open(commonprops, 'a+')
151 commonfile.write("\n#: common.testupdatepo")
152 commonfile.write('\nmsgid "TESTUPDATEPO"')
153 commonfile.write('\nmsgstr ""')
156 shutil.copyfile(commonprops, tempprops)
157 commonfile = open(commonprops, 'w')
158 tempfile = open(testpot)
159 for line in tempfile:
160 line = re.sub(r'common.properties$', r'test.properties', line)
161 line = re.sub(r'^"Project-Id-Version: .*"$', r'"Project-Id-Version: PACKAGE VERSION\\n"', line)
162 commonfile.write(line)
163 commonfile.write("\n")
167 # Compare the updated PO files - they should be the same
168 self.assertEqual(filecmp.cmp(commonprops, testprops), 1)
170 if __name__ == '__main__':