]> git.evergreen-ils.org Git - Evergreen.git/blob - build/i18n/tests/testbase.py
Unit test for generating and loading PO files.
[Evergreen.git] / build / i18n / tests / testbase.py
1 #!/usr/bin/env python
2 # vim: set fileencoding=utf-8 :
3 """
4 Test the BaseL10N class to ensure that we have a solid foundation.
5 """
6
7 import os
8 import polib
9 import sys
10 import unittest
11
12 class TestBaseL10N(unittest.TestCase):
13
14     tmpdirs = ('tmp')
15     poentries = [{
16         'msgid': 'Using Library', 
17         'msgstr': 'Utiliser la bibliothèque',
18         'occurences': [
19             {'line': 240, 'name': 'field.aihu.org_unit.label'},
20             {'line': 257, 'name': 'field.ancihu.org_unit.label'},
21         ]},
22         {
23         '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', 
24         'msgstr': 'ôèàéç',
25         'occurences': [
26             {'line': 2475, 'name': 'field.rxbt.voided.label'},
27         ]},
28         {
29         'msgid': 'Record Source', 
30         'occurences': [
31             {'line': 524, 'name': 'field.bre.source.label'},
32         ]},
33     ]
34
35     def setUp(self):
36         sys.path.append('../scripts/')
37         self.tearDown()
38         for dir in self.tmpdirs:
39             os.mkdir(dir)
40
41     def tearDown(self):
42         for dir in self.tmpdirs:
43             if os.access(dir, os.F_OK):
44                 for file in os.listdir(dir):
45                     os.remove(os.path.join(dir, file))
46                 os.rmdir(dir)
47
48     def testload(self):
49         """
50         Load a translated PO file and compare to a generated one
51         """
52         import basel10n
53         poload = basel10n.BaseL10N()
54         poload.loadpo('data/complex.po')
55         pogen = basel10n.BaseL10N()
56         pogen.pothead('Evergreen 1.4', '1999-12-31 23:59:59 -0400')
57         pogen.pot.metadata['PO-Revision-Date'] = '2007-12-08 23:14:20 -0400'
58         pogen.pot.metadata['Last-Translator'] = ' Dan Scott <dscott@laurentian.ca>'
59         pogen.pot.metadata['Language-Team'] = 'fr-CA <LL@li.org>'
60         for msg in self.poentries:
61             poe = polib.POEntry()
62             for x in msg['occurences']:
63                 poe.occurences.append((x['line'], x['name']))
64             poe.msgid = msg['msgid']
65             if msg.has_key('msgstr'):
66                 poe.msgstr = msg['msgstr']
67             pogen.pot.append(poe)
68
69         self.assertEqual(str(poload), str(pogen))
70
71 if __name__ == '__main__':
72     unittest.main()