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/sql/Pg/950.data.seed-values.sql')
19 po_tmp_files = ('tests/tmp/po/test.properties.pot', 'tests/tmp/po/ll-LL/temp.properties.po')
20 pot_dir = 'tests/tmp/po'
22 locale_dir = 'tests/tmp/po/ll-LL'
23 project_dir = 'tests/tmp/locale'
24 po_tmp_dirs = (project_dir + '/' + locale, project_dir, locale_dir, pot_dir, project_dir, 'tests/tmp')
25 newdir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
31 devnull = open('/dev/null', 'w')
33 os.mkdir(self.project_dir)
34 subprocess.Popen(('cp', '-r', 'po', 'tests/tmp'), 0, None, None, devnull, devnull).wait()
35 subprocess.Popen(('make', 'LOCALE=ll-LL', 'POINDIR=tests/tmp/po', 'POOUTDIR=tests/tmp/po', 'newpot'), 0, None, None, devnull, devnull).wait()
36 subprocess.Popen(('make', 'LOCALE=ll-LL', 'POINDIR=tests/tmp/po', 'POOUTDIR=tests/tmp/po', 'newpo'), 0, None, None, devnull, devnull).wait()
37 subprocess.Popen(('make', 'LOCALE=ll-LL', 'PROJECT=tests/tmp/locale', 'POINDIR=tests/tmp/po', 'POOUTDIR=tests/tmp/po', 'newproject'), 0, None, None, devnull, devnull).wait()
41 for root, dirs, files in os.walk(os.path.join(self.newdir, 'tests/tmp'), topdown=False):
43 os.remove(os.path.join(root, name))
45 os.rmdir(os.path.join(root, name))
46 if os.access(os.path.join(self.newdir, 'tests/tmp'), os.F_OK):
47 os.rmdir(os.path.join(self.newdir, 'tests/tmp'))
49 def testnewpofiles(self):
50 # Create a brand new set of PO files from our en-US project files.
51 # Compare the files generated in the po/ll-LL directory with
52 # the number expected by a manual count of our known sources.
54 for po_dir in self.po_sources:
55 for path in glob.glob(po_dir):
56 po_files.append(os.path.basename(path) + '.po')
58 new_pofiles = os.listdir(self.locale_dir)
60 self.assertEqual(len(po_files), len(new_pofiles))
62 def testnewprojectfiles(self):
63 # Create a brand new set of project files from PO files.
64 # Compare the files created with a manual count of our known sources.
66 for po_dir in self.po_sources:
67 for path in glob.glob(po_dir):
68 moz_files.append(os.path.basename(path))
70 new_mozfiles = os.listdir(self.locale_dir)
72 self.assertEqual(len(moz_files), len(new_mozfiles))
74 def testtranslatedfile(self):
75 # "Translate" strings in a PO file, then generate the project
76 # files to ensure that the translated string appears in the output.
78 # Create the "translated" PO file
79 commonpo = os.path.join(self.locale_dir, 'common.properties.po')
80 testpo = os.path.join(self.locale_dir, 'test.properties.po')
81 commonfile = open(commonpo)
82 testfile = open(testpo, 'w')
83 for line in commonfile:
84 line = re.sub(r'^msgstr ""', r'msgstr "abcdefg"', line)
89 os.rename(testpo, commonpo)
91 # Create the "translated" properties file
92 commonprops = os.path.join(self.project_dir, self.locale, 'common.properties')
93 testprops = os.path.join(self.locale_dir, 'test.properties')
94 commonfile = open(commonprops)
95 testfile = open(testprops, 'w')
96 for line in commonfile:
97 line = re.sub(r'^(.*?)=.*?$', r'\1=abcdefg', line)
102 # Regenerate the project files to get the translated strings in place
103 devnull = open('/dev/null', 'w')
104 subprocess.Popen(('make', 'LOCALE=ll-LL', 'POINDIR=tests/tmp/po', 'POOUTDIR=tests/tmp/po', 'updateproject'), 0, None, None, devnull, devnull).wait()
106 self.assertEqual(filecmp.cmp(commonprops, testprops), 1)
108 def testupdatepo(self):
109 # Add strings to a POT file, then ensure that the updated PO files
110 # include the new strings
112 # Create the "template" PO file
113 commonpo = os.path.join(self.locale_dir, 'common.properties.po')
114 testpo = os.path.join(self.locale_dir, 'test.properties.po')
115 commonfile = open(commonpo)
116 testfile = open(testpo, 'w')
117 for line in commonfile:
118 line = re.sub(r'common.properties$', r'test.properties', line)
123 # Create the test POT file
124 commonpot = os.path.join(self.pot_dir, 'common.properties.pot')
125 testpot = os.path.join(self.pot_dir, 'test.properties.pot')
126 commonfile = open(commonpot)
127 testfile = open(testpot, 'w')
128 for line in commonfile:
129 line = re.sub(r'common.properties$', r'test.properties', line)
132 testfile.write("\n#: common.testupdatepo")
133 testfile.write('\nmsgid "TESTUPDATEPO"')
134 testfile.write('\nmsgstr ""')
137 # Update the PO files to get the translated strings in place
138 devnull = open('/dev/null', 'w')
139 subprocess.Popen(('make', 'LOCALE=ll-LL', 'POINDIR=tests/tmp/po', 'POOUTDIR=tests/tmp/po', 'updatepo'), 0, None, None, devnull, devnull).wait()
141 commonprops = os.path.join(self.locale_dir, 'common.properties.po')
142 tempprops = os.path.join(self.locale_dir, 'temp.properties.po')
143 testprops = os.path.join(self.locale_dir, 'test.properties.po')
145 # Munge the common file to make it what we expect it to be
146 commonfile = open(commonprops, 'a+')
147 commonfile.write("\n#: common.testupdatepo")
148 commonfile.write('\nmsgid "TESTUPDATEPO"')
149 commonfile.write('\nmsgstr ""')
152 shutil.copyfile(commonprops, tempprops)
153 commonfile = open(commonprops, 'w')
154 tempfile = open(testpot)
155 for line in tempfile:
156 line = re.sub(r'common.properties$', r'test.properties', line)
157 line = re.sub(r'^"Project-Id-Version: .*"$', r'"Project-Id-Version: PACKAGE VERSION\\n"', line)
158 commonfile.write(line)
159 commonfile.write("\n")
163 # Compare the updated PO files - they should be the same
164 self.assertEqual(filecmp.cmp(commonprops, testprops), 1)
166 if __name__ == '__main__':