From 4ea61d4621afb2a6ab72d542ba4965afb0fa73cc Mon Sep 17 00:00:00 2001 From: dbs Date: Mon, 10 Dec 2007 02:23:11 +0000 Subject: [PATCH] Test suite for fieldmapper IDL i18n (and a fix - yay, tests). git-svn-id: svn://svn.open-ils.org/ILS/trunk@8187 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- build/i18n/scripts/fieldmapper.py | 17 +-- build/i18n/tests/data/testidl.ent | 42 +++++++ build/i18n/tests/data/testidl.po | 176 +++++++++++++++++++++++++++ build/i18n/tests/data/testidl.pot | 176 +++++++++++++++++++++++++++ build/i18n/tests/data/testidl.xml | 106 ++++++++++++++++ build/i18n/tests/data/testidlent.xml | 110 +++++++++++++++++ build/i18n/tests/testIDL.py | 100 +++++++++++++++ build/i18n/tests/testbase.py | 2 +- 8 files changed, 720 insertions(+), 9 deletions(-) create mode 100644 build/i18n/tests/data/testidl.ent create mode 100644 build/i18n/tests/data/testidl.po create mode 100644 build/i18n/tests/data/testidl.pot create mode 100644 build/i18n/tests/data/testidl.xml create mode 100644 build/i18n/tests/data/testidlent.xml create mode 100644 build/i18n/tests/testIDL.py diff --git a/build/i18n/scripts/fieldmapper.py b/build/i18n/scripts/fieldmapper.py index 4f1874ecd8..38888a97be 100755 --- a/build/i18n/scripts/fieldmapper.py +++ b/build/i18n/scripts/fieldmapper.py @@ -101,10 +101,11 @@ class IDLHandler(xml.sax.handler.ContentHandler): xml.sax.handler.ContentHandler.__init__(self) self.entities = dict() self.classid = None - self.entityized = u"" \ - " " \ - "]>" + self.entityized = u""" + +]> +""" self.locator = None def setDocumentLocator(self, locator): @@ -130,9 +131,9 @@ class IDLHandler(xml.sax.handler.ContentHandler): attributes['name']) label = attributes['reporter:label'] if not self.entities.has_key(label): - self.entities[label] = [(lineno, str(entity))] + self.entities[label] = [(str(entity), lineno)] else: - self.entities[label].append((lineno, str(entity))) + self.entities[label].append((str(entity), lineno)) # Now we'll render an entity-ized version of this element element = "<%s" % (name) @@ -198,7 +199,7 @@ def main(): if options.outfile: outfile = open(options.outfile, 'w') for entity in pot.definitions: - outfile.write(entity) + outfile.write(entity + "\n") else: for entity in pot.definitions: print(entity) @@ -206,7 +207,7 @@ def main(): elif options.convert: pot.get_strings(options.convert) if options.outfile: - outfile = open(options.outfile) + outfile = open(options.outfile, 'w') outfile.write(pot.idl) else: sys.stdout.write(pot.idl) diff --git a/build/i18n/tests/data/testidl.ent b/build/i18n/tests/data/testidl.ent new file mode 100644 index 0000000000..6094c58b9f --- /dev/null +++ b/build/i18n/tests/data/testidl.ent @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build/i18n/tests/data/testidl.po b/build/i18n/tests/data/testidl.po new file mode 100644 index 0000000000..886c18bec9 --- /dev/null +++ b/build/i18n/tests/data/testidl.po @@ -0,0 +1,176 @@ +# +msgid "" +msgstr "" +"Project-Id-Version: Evergreen 1.4" +"Report-Msgid-Bugs-To: open-ils-dev@list.georgialibraries.org" +"POT-Creation-Date: +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE" +"Last-Translator: FULL NAME " +"Language-Team: LANGUAGE " +"MIME-Version: 1.0" +"Content-Type: text/plain; charset=utf-8" +"Content-Transfer-Encoding: 8-bit" + +#: field.auoi.org_unit.label:29 +msgid "Allowed Org Unit" +msgstr "Lorem ipsum" + +#: field.rodcirc.checkin_staff.label:58 +msgid "Check In Staff" +msgstr "dolor sit amet" + +#: class.rodcirc.label:52 +msgid "Overdue Circulation" +msgstr "consectetuer adipiscing elit" + +#: field.rodcirc.stop_fines_time.label:76 +msgid "Fine Stop Date/Time" +msgstr "Quisque suscipit" + +#: field.rodcirc.checkin_lib.label:57 +msgid "Check In Library" +msgstr "magna non dui" + +#: field.rodcirc.circ_type.label:84 +msgid "Circulation Type" +msgstr "Integer urna" + +#: field.rodcirc.fine_interval.label:66 +msgid "Fine Interval" +msgstr "Ut élementum" + +#: field.rodcirc.billing_total.label:85 +msgid "Billing Totals" +msgstr "ante sed velit" + +#: field.rodcirc.duration.label:64 +msgid "Circulation Duration" +msgstr "Quisque pharetra" + +#: field.aws.name.label:45 +msgid "Workstation Name" +msgstr "lectus vitae aliquam" + +#: class.auoi.label:20 +msgid "User Sharing Opt-in" +msgstr "venenatis, mi nisl" + +#: field.rodcirc.recuring_fine_rule.label:73 +msgid "Recurring Fine Rule" +msgstr "suscipit sapien, eu sollicitudin" + +#: field.rodcirc.duration_rule.label:65 +msgid "Circ Duration Rule" +msgstr "neque dolor a nulla" + +#: field.auoi.id.label:25 +msgid "Opt-in ID" +msgstr "Phasellus aliquam vulputate justo" + +#: field.rodcirc.payment_total.label:86 +msgid "Payment Totals" +msgstr "Proin augue libero" + +#: field.rodcirc.phone_renewal.label:71 +msgid "Phone Renewal" +msgstr "hendrerit pretium" + +#: field.rodcirc.circ_lib.label:60 +msgid "Circulating Library" +msgstr "rutrum pretium" + +#: field.rodcirc.max_fine.label:68 +msgid "Max Fine Amount" +msgstr "commodo nec, neque" + +#: field.rodcirc.xact_finish.label:79 +msgid "Transaction Finish Date/Time" +msgstr "Vestibulum ante ipsum" + +#: field.auoi.usr.label:28 +msgid "User" +msgstr "primis" + +#: field.auoi.opt_in_ws.label:39 class.aws.label:26 +msgid "Workstation" +msgstr "in faucibus orci luctus" + +#: field.rodcirc.stop_fines.label:75 +msgid "Fine Stop Reason" +msgstr "ultrices posuere cubilia Curae" + +#: field.rodcirc.opac_renewal.label:70 +msgid "OPAC Renewal" +msgstr "Sed vel lectus" + +#: field.rodcirc.circ_staff.label:61 +msgid "Circulating Staff" +msgstr "Ut dictum mollis turpis" + +#: field.rodcirc.payments.label:82 +msgid "Transaction Payments" +msgstr "Proin et orci" + +#: field.rodcirc.checkin_time.label:59 +msgid "Check In Date/Time" +msgstr "Phasellus vel justo" + +#: field.rodcirc.max_fine_rule.label:69 +msgid "Max Fine Rule" +msgstr "ultricies quam" + +#: field.rodcirc.xact_start.label:80 +msgid "Check Out Date/Time" +msgstr "lacinia accumsan" + +#: field.rodcirc.billable_transaction.label:83 +msgid "Base Transaction" +msgstr "Nullam imperdiet" + +#: field.rodcirc.recuring_fine.label:72 +msgid "Recurring Fine Amount" +msgstr "tincidunt mauris" + +#: field.auoi.staff.label:27 +msgid "Staff Member" +msgstr "" + +#: field.aws.id.label:44 +msgid "Workstation ID" +msgstr "" + +#: field.rodcirc.usr.label:78 +msgid "Patron" +msgstr "Mauris ac diam" + +#: field.rodcirc.due_date.label:63 +msgid "Due Date/Time" +msgstr "Nam egestas bibendum lectus" + +#: field.rodcirc.billings.label:81 +msgid "Transaction Billings" +msgstr "Praesent hendrerit" + +#: field.auoi.opt_in_ts.label:30 +msgid "Opt-in Date/Time" +msgstr "sapien id velit nonummy" + +#: field.rodcirc.desk_renewal.label:62 +msgid "Desk Renewal" +msgstr "congue, neque" + +#: field.rodcirc.target_copy.label:77 +msgid "Circulating Item" +msgstr "ut ullamcorper faucibus" + +#: field.rodcirc.renewal_remaining.label:74 +msgid "Remaining Renewals" +msgstr "diam felis" + +#: field.aws.owning_lib.label:46 +msgid "Owning Library" +msgstr "" + +#: field.rodcirc.id.label:67 +msgid "Circ ID" +msgstr "pulvinar augue" diff --git a/build/i18n/tests/data/testidl.pot b/build/i18n/tests/data/testidl.pot new file mode 100644 index 0000000000..efb2adb01d --- /dev/null +++ b/build/i18n/tests/data/testidl.pot @@ -0,0 +1,176 @@ +# +msgid "" +msgstr "" +"Project-Id-Version: Evergreen 1.4" +"Report-Msgid-Bugs-To: open-ils-dev@list.georgialibraries.org" +"POT-Creation-Date: +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE" +"Last-Translator: FULL NAME " +"Language-Team: LANGUAGE " +"MIME-Version: 1.0" +"Content-Type: text/plain; charset=utf-8" +"Content-Transfer-Encoding: 8-bit" + +#: 29:field.auoi.org_unit.label +msgid "Allowed Org Unit" +msgstr "" + +#: 58:field.rodcirc.checkin_staff.label +msgid "Check In Staff" +msgstr "" + +#: 52:class.rodcirc.label +msgid "Overdue Circulation" +msgstr "" + +#: 76:field.rodcirc.stop_fines_time.label +msgid "Fine Stop Date/Time" +msgstr "" + +#: 57:field.rodcirc.checkin_lib.label +msgid "Check In Library" +msgstr "" + +#: 84:field.rodcirc.circ_type.label +msgid "Circulation Type" +msgstr "" + +#: 66:field.rodcirc.fine_interval.label +msgid "Fine Interval" +msgstr "" + +#: 85:field.rodcirc.billing_total.label +msgid "Billing Totals" +msgstr "" + +#: 64:field.rodcirc.duration.label +msgid "Circulation Duration" +msgstr "" + +#: 45:field.aws.name.label +msgid "Workstation Name" +msgstr "" + +#: 20:class.auoi.label +msgid "User Sharing Opt-in" +msgstr "" + +#: 73:field.rodcirc.recuring_fine_rule.label +msgid "Recurring Fine Rule" +msgstr "" + +#: 65:field.rodcirc.duration_rule.label +msgid "Circ Duration Rule" +msgstr "" + +#: 25:field.auoi.id.label +msgid "Opt-in ID" +msgstr "" + +#: 86:field.rodcirc.payment_total.label +msgid "Payment Totals" +msgstr "" + +#: 71:field.rodcirc.phone_renewal.label +msgid "Phone Renewal" +msgstr "" + +#: 60:field.rodcirc.circ_lib.label +msgid "Circulating Library" +msgstr "" + +#: 68:field.rodcirc.max_fine.label +msgid "Max Fine Amount" +msgstr "" + +#: 79:field.rodcirc.xact_finish.label +msgid "Transaction Finish Date/Time" +msgstr "" + +#: 28:field.auoi.usr.label +msgid "User" +msgstr "" + +#: 26:field.auoi.opt_in_ws.label 39:class.aws.label +msgid "Workstation" +msgstr "" + +#: 75:field.rodcirc.stop_fines.label +msgid "Fine Stop Reason" +msgstr "" + +#: 70:field.rodcirc.opac_renewal.label +msgid "OPAC Renewal" +msgstr "" + +#: 61:field.rodcirc.circ_staff.label +msgid "Circulating Staff" +msgstr "" + +#: 82:field.rodcirc.payments.label +msgid "Transaction Payments" +msgstr "" + +#: 59:field.rodcirc.checkin_time.label +msgid "Check In Date/Time" +msgstr "" + +#: 69:field.rodcirc.max_fine_rule.label +msgid "Max Fine Rule" +msgstr "" + +#: 80:field.rodcirc.xact_start.label +msgid "Check Out Date/Time" +msgstr "" + +#: 83:field.rodcirc.billable_transaction.label +msgid "Base Transaction" +msgstr "" + +#: 72:field.rodcirc.recuring_fine.label +msgid "Recurring Fine Amount" +msgstr "" + +#: 27:field.auoi.staff.label +msgid "Staff Member" +msgstr "" + +#: 44:field.aws.id.label +msgid "Workstation ID" +msgstr "" + +#: 78:field.rodcirc.usr.label +msgid "Patron" +msgstr "" + +#: 63:field.rodcirc.due_date.label +msgid "Due Date/Time" +msgstr "" + +#: 81:field.rodcirc.billings.label +msgid "Transaction Billings" +msgstr "" + +#: 30:field.auoi.opt_in_ts.label +msgid "Opt-in Date/Time" +msgstr "" + +#: 62:field.rodcirc.desk_renewal.label +msgid "Desk Renewal" +msgstr "" + +#: 77:field.rodcirc.target_copy.label +msgid "Circulating Item" +msgstr "" + +#: 74:field.rodcirc.renewal_remaining.label +msgid "Remaining Renewals" +msgstr "" + +#: 46:field.aws.owning_lib.label +msgid "Owning Library" +msgstr "" + +#: 67:field.rodcirc.id.label +msgid "Circ ID" +msgstr "" diff --git a/build/i18n/tests/data/testidl.xml b/build/i18n/tests/data/testidl.xml new file mode 100644 index 0000000000..b8c9c83caf --- /dev/null +++ b/build/i18n/tests/data/testidl.xml @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build/i18n/tests/data/testidlent.xml b/build/i18n/tests/data/testidlent.xml new file mode 100644 index 0000000000..edc6764664 --- /dev/null +++ b/build/i18n/tests/data/testidlent.xml @@ -0,0 +1,110 @@ + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/build/i18n/tests/testIDL.py b/build/i18n/tests/testIDL.py new file mode 100644 index 0000000000..3dfaf4f802 --- /dev/null +++ b/build/i18n/tests/testIDL.py @@ -0,0 +1,100 @@ +#!/usr/bin/env python +# vim: set fileencoding=utf-8 : +""" + Perform the following tests: + 1. Generate an entityized version of an abbreviated version of fm_IDL.xml + 2. Generate a POT file from fm_IDL.xml + 3. Generate an entity definition file from a PO file +""" + +import filecmp +import os +import polib +import re +import subprocess +import sys +import unittest + +class TestIDLL10N(unittest.TestCase): + + tmpdirs = [('tmp/')] + savepot = 'tmp/testsave.pot' + saveidlent = 'tmp/testidlent.xml' + saveentities = 'tmp/testentity.ent' + idlfile = 'data/testidl.xml' + idlentfile = 'data/testidlent.xml' + idlentities = 'data/testidl.ent' + testpot = 'data/testidl.pot' + testpo = 'data/testidl.po' + + 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 testentityize(self): + """ + Convert an en-US IDL file to an entityized version + """ + devnull = open('/dev/null', 'w') + proc = subprocess.Popen( + ('python', '../scripts/fieldmapper.py', '--convert', self.idlfile, + '--output', self.saveidlent), + 0, None, None, devnull, devnull).wait() + + self.assertEqual(filecmp.cmp(self.saveidlent, self.idlentfile), 1) + + def testsavepot(self): + """ + Create a POT file from a fieldmapper IDL file + """ + devnull = open('/dev/null', 'w') + proc = subprocess.Popen( + ('python', '../scripts/fieldmapper.py', '--pot', self.idlfile, + '--output', self.savepot), + 0, None, None, devnull, devnull).wait() + + mungepothead(self.savepot) + mungepothead(self.testpot) + + self.assertEqual(filecmp.cmp(self.savepot, self.testpot), 1) + + def testgenent(self): + """ + Generate an entity definition file from a PO file + """ + devnull = open('/dev/null', 'w') + proc = subprocess.Popen( + ('python', '../scripts/fieldmapper.py', '--entity', self.testpo, + '--output', self.saveentities), + 0, None, None, devnull, devnull).wait() + self.assertEqual(filecmp.cmp(self.saveentities, self.idlentities), 1) + + +def mungepothead(file): + """ + Change POT header to avoid annoying timestamp mismatch + """ + lines = [] + mungefile = open(file) + for line in mungefile: + line = re.sub(r'^("POT-Creation-Date: ).+"$', r'\1', line) + lines.append(line) + mungefile.close() + + # Write the changed lines back out + mungefile = open(file, 'w') + for line in lines: + mungefile.write(line) + mungefile.close() + +if __name__ == '__main__': + unittest.main() diff --git a/build/i18n/tests/testbase.py b/build/i18n/tests/testbase.py index d79fa70fee..56aeee23bb 100644 --- a/build/i18n/tests/testbase.py +++ b/build/i18n/tests/testbase.py @@ -74,7 +74,7 @@ class TestBaseL10N(unittest.TestCase): def testsavepot(self): """ - Save a generated POT file and compate to a known good one + Save a generated POT file and compare to a known good one """ import basel10n pogen = basel10n.BaseL10N() -- 2.43.2