Back to index

plone3  3.1.7
test_i18n.py
Go to the documentation of this file.
00001 import os, sys
00002 
00003 from Testing import ZopeTestCase
00004 from Products.i18ntestcase import PotTestCase, PoTestCase
00005 from Products.i18ntestcase.I18NTestCase import getPoFiles, getPotFiles, getProductFromPath
00006 from i18ndude import catalog
00007 from Globals import package_home
00008 
00009 GLOBALS = globals()
00010 PACKAGE_HOME = os.path.normpath(os.path.join(package_home(GLOBALS), '..'))
00011 
00012 head, tail = os.path.split(PACKAGE_HOME)
00013 if tail == 'tests':
00014     PACKAGE_HOME = os.path.join(PACKAGE_HOME, '..')
00015 
00016 i18ndir = os.path.normpath(PACKAGE_HOME)
00017 
00018 tests=[]
00019 products=[]
00020 pots={}
00021 pot_catalogs={}
00022 pot_lens={}
00023 
00024 for potFile in getPotFiles(path=i18ndir):
00025     product = getProductFromPath(potFile)
00026     if product not in products:
00027         products.append(product)
00028     if product not in pot_catalogs:
00029         cat = catalog.MessageCatalog(filename=potFile)
00030         cat_len = len(cat)
00031         pots.update({product: potFile})
00032         pot_catalogs.update({product: cat})
00033         pot_lens.update({product: cat_len})
00034 
00035 for product in products:
00036     class TestOnePOT(PotTestCase.PotTestCase):
00037         product = product
00038         pot = pots[product]
00039     tests.append(TestOnePOT)
00040 
00041     for poFile in getPoFiles(path=i18ndir, product=product):
00042         class TestOnePoFile(PoTestCase.PoTestCase):
00043             po = poFile
00044             product = product
00045             pot_cat = pot_catalogs[product]
00046             pot_len = pot_lens[product]
00047         tests.append(TestOnePoFile)
00048 
00049     import unittest
00050     def test_suite():
00051         suite = unittest.TestSuite()
00052         for test in tests:
00053             suite.addTest(unittest.makeSuite(test))
00054         return suite