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')
19 devnull = open('/dev/null', 'w')
20 proc = subprocess.Popen(('make', 'LOCALE=ll-LL', 'newpo'), 0, None, None, devnull, devnull).wait()
21 proc = subprocess.Popen(('make', 'LOCALE=ll-LL', 'newproject'), 0, None, None, devnull, devnull).wait()
25 tmpdirs = ('po/ll-LL', 'locale/ll-LL')
26 tmpfiles = ('po/test.properties.pot', 'locale/ll-LL/temp.properties.po')
28 if os.access(dir, os.F_OK):
29 for file in os.listdir(dir):
30 os.remove(os.path.join(dir, file))
34 if os.access(file, os.F_OK):
37 def testnewpofiles(self):
38 # Create a brand new set of PO files from our en-US project files.
39 # Compare the files generated in the po/ll-LL directory with
40 # the number expected by a manual count of our known sources.
42 for po_dir in self.po_sources:
43 for path in glob.glob(po_dir):
44 po_files.append(os.path.basename(path) + '.po')
46 new_pofiles = os.listdir('po/ll-LL/')
48 self.assertEqual(po_files, new_pofiles)
50 def testnewprojectfiles(self):
51 # Create a brand new set of project files from PO files.
52 # Compare the files created with a manual count of our known sources.
54 for po_dir in self.po_sources:
55 for path in glob.glob(po_dir):
56 moz_files.append(os.path.basename(path))
58 new_mozfiles = os.listdir('locale/ll-LL/')
60 self.assertEqual(moz_files, new_mozfiles)
62 def testtranslatedfile(self):
63 # "Translate" strings in a PO file, then generate the project
64 # files to ensure that the translated string appears in the output.
66 # Create the "translated" PO file
67 commonpo = 'po/ll-LL/common.properties.po'
68 testpo = 'po/ll-LL/test.properties.po'
69 commonfile = open(commonpo)
70 testfile = open(testpo, 'w')
71 for line in commonfile:
72 line = re.sub(r'^msgstr ""', r'msgstr "abcdefg"', line)
77 os.rename(testpo, commonpo)
79 # Create the "translated" properties file
80 commonprops = 'locale/ll-LL/common.properties'
81 testprops = 'locale/ll-LL/test.properties'
82 commonfile = open(commonprops)
83 testfile = open(testprops, 'w')
84 for line in commonfile:
85 line = re.sub(r'^(.*?)=.*?$', r'\1=abcdefg', line)
90 # Regenerate the project files to get the translated strings in place
91 devnull = open('/dev/null', 'w')
92 proc = subprocess.Popen(('make', 'LOCALE=ll-LL', 'updateproject'), 0, None, None, devnull, devnull).wait()
94 self.assertEqual(filecmp.cmp(commonprops, testprops), 1)
96 def testupdatepo(self):
97 # Add strings to a POT file, then ensure that the updated PO files
98 # include the new strings
100 # Create the "template" PO file
101 commonpo = 'po/ll-LL/common.properties.po'
102 testpo = 'po/ll-LL/test.properties.po'
103 commonfile = open(commonpo)
104 testfile = open(testpo, 'w')
105 for line in commonfile:
106 line = re.sub(r'common.properties$', r'test.properties', line)
111 # Create the test POT file
112 commonpot = 'po/common.properties.pot'
113 testpot = 'po/test.properties.pot'
114 commonfile = open(commonpot)
115 testfile = open(testpot, 'w')
116 for line in commonfile:
117 line = re.sub(r'common.properties$', r'test.properties', line)
120 testfile.write("\n#: common.testupdatepo")
121 testfile.write('\nmsgid "TESTUPDATEPO"')
122 testfile.write('\nmsgstr ""')
125 # Update the PO files to get the translated strings in place
126 devnull = open('/dev/null', 'w')
127 proc = subprocess.Popen(('make', 'LOCALE=ll-LL', 'updatepo'), 0, None, None, devnull, devnull).wait()
129 commonprops = 'po/ll-LL/common.properties.po'
130 tempprops = 'po/ll-LL/temp.properties.po'
131 testprops = 'po/ll-LL/test.properties.po'
133 # Munge the common file to make it what we expect it to be
134 commonfile = open(commonprops, 'a+')
135 commonfile.write("\n#: common.testupdatepo")
136 commonfile.write('\nmsgid "TESTUPDATEPO"')
137 commonfile.write('\nmsgstr ""')
140 shutil.copyfile(commonprops, tempprops)
141 commonfile = open(commonprops, 'w')
142 tempfile = open(testpot)
143 for line in tempfile:
144 line = re.sub(r'common.properties$', r'test.properties', line)
145 line = re.sub(r'^"Project-Id-Version: .*"$', r'"Project-Id-Version: PACKAGE VERSION\\n"', line)
146 commonfile.write(line)
147 commonfile.write("\n")
151 # Compare the updated PO files - they should be the same
152 self.assertEqual(filecmp.cmp(commonprops, testprops), 1)
154 if __name__ == '__main__':