]> git.evergreen-ils.org Git - Evergreen.git/blob - build/i18n/tests/testbase.py
better protection for non-existent hold expire interval setting
[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 filecmp
8 import os
9 import polib
10 import sys
11 import unittest
12
13 class TestBaseL10N(unittest.TestCase):
14
15     basedir = os.path.dirname(__file__)
16     tmpdirs = [(os.path.join(basedir, 'tmp/'))]
17     savefile = os.path.join(basedir, 'tmp/testsave.pot')
18     canonpot = os.path.join(basedir, 'data/complex.pot')
19     canonpo = os.path.join(basedir, 'data/complex.po')
20     poentries = [{
21         'msgid': 'Using Library', 
22         'msgstr': 'Utiliser la bibliothèque',
23         'occurrences': [
24             {'line': 240, 'name': 'field.aihu.org_unit.label'},
25             {'line': 257, 'name': 'field.ancihu.org_unit.label'},
26         ]},
27         {
28         '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', 
29         'msgstr': 'ôèàéç',
30         'occurrences': [
31             {'line': 2475, 'name': 'field.rxbt.voided.label'},
32         ]},
33         {
34         'msgid': 'Record Source', 
35         'occurrences': [
36             {'line': 524, 'name': 'field.bre.source.label'},
37         ]},
38     ]
39
40     def setUp(self):
41         sys.path.append(os.path.join(self.basedir, '../scripts/'))
42         self.tearDown()
43         for tmpdir in self.tmpdirs:
44             os.mkdir(tmpdir)
45
46     def tearDown(self):
47         for tmpdir in self.tmpdirs:
48             if os.access(tmpdir, os.F_OK):
49                 for tmpfile in os.listdir(tmpdir):
50                     os.remove(os.path.join(tmpdir, tmpfile))
51                 os.rmdir(tmpdir)
52
53     def testload(self):
54         """
55         Load a translated PO file and compare to a generated one
56         """
57         import basel10n
58         poload = basel10n.BaseL10N()
59         poload.loadpo(self.canonpo)
60         pogen = basel10n.BaseL10N()
61         pogen.pothead('Evergreen 1.4', '1999-12-31 23:59:59 -0400')
62         pogen.pot.metadata['PO-Revision-Date'] = '2007-12-08 23:14:20 -0400'
63         pogen.pot.metadata['Last-Translator'] = ' Dan Scott <dscott@laurentian.ca>'
64         pogen.pot.metadata['Language-Team'] = 'fr-CA <LL@li.org>'
65         for msg in self.poentries:
66             poe = polib.POEntry()
67             for x in msg['occurrences']:
68                 poe.occurrences.append((x['line'], x['name']))
69             poe.msgid = msg['msgid']
70             if msg.has_key('msgstr'):
71                 poe.msgstr = msg['msgstr']
72             pogen.pot.append(poe)
73
74         self.assertEqual(str(poload), str(pogen))
75
76     def testsavepot(self):
77         """
78         Save a generated POT file and compare to a known good one
79         """
80         import basel10n
81         pogen = basel10n.BaseL10N()
82         pogen.pothead('Evergreen 1.4', '1999-12-31 23:59:59 -0400')
83         for msg in self.poentries:
84             poe = polib.POEntry()
85             for x in msg['occurrences']:
86                 poe.occurrences.append((x['line'], x['name']))
87             poe.msgid = msg['msgid']
88             pogen.pot.append(poe)
89         pogen.savepot(self.savefile)
90
91         self.assertEqual(filecmp.cmp(self.savefile, self.canonpot), 1)
92
93 if __name__ == '__main__':
94     unittest.main()