From 760e1ec3018d3c94d09725d893247608150aa7fd Mon Sep 17 00:00:00 2001 From: dbs Date: Sun, 9 Dec 2007 05:04:34 +0000 Subject: [PATCH] Unit test for generating and loading PO files. git-svn-id: svn://svn.open-ils.org/ILS/trunk@8181 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- build/i18n/tests/testbase.py | 72 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 build/i18n/tests/testbase.py diff --git a/build/i18n/tests/testbase.py b/build/i18n/tests/testbase.py new file mode 100644 index 0000000000..a0e8133620 --- /dev/null +++ b/build/i18n/tests/testbase.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python +# vim: set fileencoding=utf-8 : +""" +Test the BaseL10N class to ensure that we have a solid foundation. +""" + +import os +import polib +import sys +import unittest + +class TestBaseL10N(unittest.TestCase): + + tmpdirs = ('tmp') + poentries = [{ + 'msgid': 'Using Library', + 'msgstr': 'Utiliser la bibliothèque', + 'occurences': [ + {'line': 240, 'name': 'field.aihu.org_unit.label'}, + {'line': 257, 'name': 'field.ancihu.org_unit.label'}, + ]}, + { + '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', + 'msgstr': 'ôèàéç', + 'occurences': [ + {'line': 2475, 'name': 'field.rxbt.voided.label'}, + ]}, + { + 'msgid': 'Record Source', + 'occurences': [ + {'line': 524, 'name': 'field.bre.source.label'}, + ]}, + ] + + def setUp(self): + sys.path.append('../scripts/') + self.tearDown() + for dir in self.tmpdirs: + os.mkdir(dir) + + def tearDown(self): + for dir in self.tmpdirs: + if os.access(dir, os.F_OK): + for file in os.listdir(dir): + os.remove(os.path.join(dir, file)) + os.rmdir(dir) + + def testload(self): + """ + Load a translated PO file and compare to a generated one + """ + import basel10n + poload = basel10n.BaseL10N() + poload.loadpo('data/complex.po') + pogen = basel10n.BaseL10N() + pogen.pothead('Evergreen 1.4', '1999-12-31 23:59:59 -0400') + pogen.pot.metadata['PO-Revision-Date'] = '2007-12-08 23:14:20 -0400' + pogen.pot.metadata['Last-Translator'] = ' Dan Scott ' + pogen.pot.metadata['Language-Team'] = 'fr-CA ' + for msg in self.poentries: + poe = polib.POEntry() + for x in msg['occurences']: + poe.occurences.append((x['line'], x['name'])) + poe.msgid = msg['msgid'] + if msg.has_key('msgstr'): + poe.msgstr = msg['msgstr'] + pogen.pot.append(poe) + + self.assertEqual(str(poload), str(pogen)) + +if __name__ == '__main__': + unittest.main() -- 2.11.0