11 class TestPOFramework(unittest.TestCase):
13 po_sources = ('../../Open-ILS/web/opac/locale/en-US/*.dtd', \
14 '../../Open-ILS/xul/staff_client/chrome/locale/en-US/*.properties')
17 devnull = open('/dev/null', 'w')
18 proc = subprocess.Popen(('make', 'LOCALE=ll-LL', 'newpo'), 0, None, None, devnull, devnull).wait()
19 proc = subprocess.Popen(('make', 'LOCALE=ll-LL', 'newproject'), 0, None, None, devnull, devnull).wait()
22 for file in os.listdir('po/ll-LL/'):
23 os.remove(os.path.join('po/ll-LL', file))
25 for file in os.listdir('locale/ll-LL/'):
26 os.remove(os.path.join('locale/ll-LL/', file))
27 os.rmdir('locale/ll-LL/')
29 def testnewpofiles(self):
30 # Create a brand new set of PO files from our en-US project files.
31 # Compare the files generated in the po/ll-LL directory with
32 # the number expected by a manual count of our known sources.
34 for po_dir in self.po_sources:
35 for path in glob.glob(po_dir):
36 po_files.append(os.path.basename(path) + '.po')
38 new_pofiles = os.listdir('po/ll-LL/')
40 self.assertEqual(po_files, new_pofiles)
42 def testnewprojectfiles(self):
43 # Create a brand new set of project files from PO files.
44 # Compare the files created with a manual count of our known sources.
46 for po_dir in self.po_sources:
47 for path in glob.glob(po_dir):
48 moz_files.append(os.path.basename(path))
50 new_mozfiles = os.listdir('locale/ll-LL/')
52 self.assertEqual(moz_files, new_mozfiles)
54 def testtranslatedfile(self):
55 # "Translate" strings in a PO file, then generate the project
56 # files to ensure that the translated string appears in the output.
58 # Create the "translated" PO file
59 commonpo = 'po/ll-LL/common.properties.po'
60 testpo = 'po/ll-LL/test.properties.po'
61 commonfile = open(commonpo)
62 testfile = open(testpo, 'w')
63 for line in commonfile:
64 line = re.sub(r'^msgstr ""', r'msgstr "abcdefg"', line)
69 os.rename(testpo, commonpo)
71 # Create the "translated" properties file
72 commonprops = 'locale/ll-LL/common.properties'
73 testprops = 'locale/ll-LL/test.properties'
74 commonfile = open(commonprops)
75 testfile = open(testprops, 'w')
76 for line in commonfile:
77 line = re.sub(r'^(.*?)=.*?$', r'\1=abcdefg', line)
82 # Regenerate the project files to get the translated strings in place
83 devnull = open('/dev/null', 'w')
84 proc = subprocess.Popen(('make', 'LOCALE=ll-LL', 'newproject'), 0, None, None, devnull, devnull).wait()
86 self.assertEqual(filecmp.cmp(commonprops, testprops), 1)
88 if __name__ == '__main__':