]> git.evergreen-ils.org Git - working/Evergreen.git/blob - build/i18n/tests/testbase.py
LP1183964: Payment Limit Options
[working/Evergreen.git] / build / i18n / tests / testbase.py
1 #!/usr/bin/env python
2 # -*- coding: utf=8 -*-
3 # vim: set fileencoding=utf-8 :
4 """
5 Test the BaseL10N class to ensure that we have a solid foundation.
6 """
7
8 import filecmp
9 import os
10 import polib
11 import sys
12 import unittest
13
14 class TestBaseL10N(unittest.TestCase):
15
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')
21     poentries = [{
22         'msgid': 'Using Library', 
23         'msgstr': u'Utiliser la bibliothèque',
24         'occurrences': [
25             {'line': 240, 'name': 'field.aihu.org_unit.label'},
26             {'line': 257, 'name': 'field.ancihu.org_unit.label'},
27         ]},
28         {
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', 
30         'msgstr': u'ôèàéç',
31         'occurrences': [
32             {'line': 2475, 'name': 'field.rxbt.voided.label'},
33         ]},
34         {
35         'msgid': 'Record Source', 
36         'occurrences': [
37             {'line': 524, 'name': 'field.bre.source.label'},
38         ]},
39     ]
40
41     def setUp(self):
42         sys.path.append(os.path.join(self.basedir, '../scripts/'))
43         self.tearDown()
44         for tmpdir in self.tmpdirs:
45             os.mkdir(tmpdir)
46
47     def tearDown(self):
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))
52                 os.rmdir(tmpdir)
53
54     def testload(self):
55         """
56         Load a translated PO file and compare to a generated one
57         """
58         import basel10n
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:
67             poe = polib.POEntry()
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']
73             pogen.pot.append(poe)
74
75         self.assertEqual(unicode(poload), unicode(pogen))
76
77     def testsavepot(self):
78         """
79         Save a generated POT file and compare to a known good one
80         """
81         import basel10n
82         pogen = basel10n.BaseL10N()
83         pogen.pothead('Evergreen 1.4', '1999-12-31 23:59:59 -0400')
84         for msg in self.poentries:
85             poe = polib.POEntry()
86             for x in msg['occurrences']:
87                 poe.occurrences.append((x['line'], x['name']))
88             poe.msgid = msg['msgid']
89             pogen.pot.append(poe)
90         pogen.savepot(self.savefile)
91
92         self.assertEqual(filecmp.cmp(self.savefile, self.canonpot), 1)
93
94 if __name__ == '__main__':
95     unittest.main()