Back to index

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