2 # -*- coding: utf=8 -*-
3 # vim: set fileencoding=utf-8 :
5 Test the BaseL10N class to ensure that we have a solid foundation.
14 class TestBaseL10N(unittest.TestCase):
16 basedir = os.path.dirname(__file__)
17 tmpdirs = [(os.path.join(basedir, 'tmp/'))]
18 savefile = os.path.join(basedir, 'tmp/testsave.pot')
19 canonpot = os.path.join(basedir, 'data/complex.pot')
20 canonpo = os.path.join(basedir, 'data/complex.po')
22 'msgid': 'Using Library',
23 'msgstr': u'Utiliser la bibliothèque',
25 {'line': 240, 'name': 'field.aihu.org_unit.label'},
26 {'line': 257, 'name': 'field.ancihu.org_unit.label'},
29 'msgid': '\nSuper crazy long and repetitive message ID from hell\nSuper crazy long and repetitive message ID from hell\nSuper crazy long and repetitive message ID from hell\nSuper crazy long and repetitive message ID from hell\nSuper crazy long and repetitive message ID from hell',
32 {'line': 2475, 'name': 'field.rxbt.voided.label'},
35 'msgid': 'Record Source',
37 {'line': 524, 'name': 'field.bre.source.label'},
42 sys.path.append(os.path.join(self.basedir, '../scripts/'))
44 for tmpdir in self.tmpdirs:
48 for tmpdir in self.tmpdirs:
49 if os.access(tmpdir, os.F_OK):
50 for tmpfile in os.listdir(tmpdir):
51 os.remove(os.path.join(tmpdir, tmpfile))
56 Load a translated PO file and compare to a generated one
59 poload = basel10n.BaseL10N()
60 poload.loadpo(self.canonpo)
61 pogen = basel10n.BaseL10N()
62 pogen.pothead('Evergreen 1.4', '1999-12-31 23:59:59 -0400')
63 pogen.pot.metadata['PO-Revision-Date'] = '2007-12-08 23:14:20 -0400'
64 pogen.pot.metadata['Last-Translator'] = ' Dan Scott <dscott@laurentian.ca>'
65 pogen.pot.metadata['Language-Team'] = 'fr-CA <LL@li.org>'
66 for msg in self.poentries:
68 for x in msg['occurrences']:
69 poe.occurrences.append((x['name'], x['line']))
70 poe.msgid = msg['msgid']
71 if msg.has_key('msgstr'):
72 poe.msgstr = msg['msgstr']
75 self.assertEqual(unicode(poload), unicode(pogen))
77 def testsavepot(self):
79 Save a generated POT file and compare to a known good one
82 pogen = basel10n.BaseL10N()
83 pogen.pothead('Evergreen 1.4', '1999-12-31 23:59:59 -0400')
84 for msg in self.poentries:
86 for x in msg['occurrences']:
87 poe.occurrences.append((x['line'], x['name']))
88 poe.msgid = msg['msgid']
90 pogen.savepot(self.savefile)
92 self.assertEqual(filecmp.cmp(self.savefile, self.canonpot), 1)
94 if __name__ == '__main__':