[Zope3-checkins] CVS: Zope3/src/zope/i18n/tests - test_locales.py:1.3 test_formats.py:1.5
Jeremy Hylton
jeremy@zope.com
Mon, 27 Jan 2003 16:51:59 -0500
Update of /cvs-repository/Zope3/src/zope/i18n/tests
In directory cvs.zope.org:/tmp/cvs-serv30153/tests
Modified Files:
test_locales.py test_formats.py
Log Message:
Refactor tests to do the slow XML parsing a minimum number of times.
XXX This could probably be simplfied further still, but the current
approach was the least invasive.
Many of the tests used setUp() to parse an XML file and create some
i18n data structure. The tests only read the data structure, so
there's no need to re-parse the data each time.
The changes reduces the time it takes to run the zope.i18n tests from
several hundred seconds to 17 seconds on my machine.
=== Zope3/src/zope/i18n/tests/test_locales.py 1.2 => 1.3 ===
--- Zope3/src/zope/i18n/tests/test_locales.py:1.2 Thu Jan 9 14:20:23 2003
+++ Zope3/src/zope/i18n/tests/test_locales.py Mon Jan 27 16:51:56 2003
@@ -31,10 +31,8 @@
from zope.i18n.locales import ICULocaleTimeZone, ICULocaleCalendar
from zope.i18n.locales import ICULocaleNumberFormat, ICULocaleCurrency
-def testdir():
- from zope.i18n import tests
- return os.path.dirname(tests.__file__)
-
+from zope.i18n import tests
+testdir = os.path.dirname(tests.__file__)
class TestILocaleProvider(TestCase):
"""Test the functionality of an implmentation of the ILocaleProvider
@@ -74,7 +72,7 @@
class TestLocaleProvider(TestILocaleProvider):
def _makeNewProvider(self):
- return LocaleProvider(os.path.join(testdir(), 'xmllocales'))
+ return LocaleProvider(os.path.join(testdir, 'xmllocales'))
def test_loadLocale(self):
self.locales.loadLocale(None, None, None)
@@ -385,15 +383,14 @@
class TestICUXMLLocaleFactory(TestCase):
- def setUp(self):
- self.factory0 = ICUXMLLocaleFactory(
- os.path.join(testdir(), 'xmllocales', 'root.xml'))
- self.factory = ICUXMLLocaleFactory(
- os.path.join(testdir(), 'xmllocales', 'de.xml'))
- self.factory2 = ICUXMLLocaleFactory(
- os.path.join(testdir(), 'xmllocales', 'de_DE.xml'))
- self.factory3 = ICUXMLLocaleFactory(
- os.path.join(testdir(), 'xmllocales', 'de_DE_PREEURO.xml'))
+ factory0 = ICUXMLLocaleFactory(
+ os.path.join(testdir, 'xmllocales', 'root.xml'))
+ factory = ICUXMLLocaleFactory(
+ os.path.join(testdir, 'xmllocales', 'de.xml'))
+ factory2 = ICUXMLLocaleFactory(
+ os.path.join(testdir, 'xmllocales', 'de_DE.xml'))
+ factory3 = ICUXMLLocaleFactory(
+ os.path.join(testdir, 'xmllocales', 'de_DE_PREEURO.xml'))
def test_GermanySpecificGermanLocale(self):
# Well, if the factory can create the Locale we are in good
@@ -488,21 +485,11 @@
self.assertEqual(curr[2], True)
-class TestILocale(TestCase):
-
- def _newLocale(self):
- raise NotImplemented
-
- def setUp(self):
- self.locale = self._newLocale()
-
-
-class TestICULocale(TestILocale):
+class TestICULocale(TestCase):
- def _newLocale(self):
- path = os.path.join(testdir(), 'xmllocales', 'root.xml')
- localeFactory = ICUXMLLocaleFactory(path)
- return localeFactory()
+ path = os.path.join(testdir, 'xmllocales', 'root.xml')
+ localeFactory = ICUXMLLocaleFactory(path)
+ locale = localeFactory()
def testId(self):
id = self.locale.id
@@ -610,16 +597,18 @@
class TestICULocaleAndProvider(TestCase):
+
+ # Set the locale on the class so that test cases don't have
+ # to pay to construct a new one each time.
- def setUp(self):
- orig = locales._locale_dir
- locales._locale_dir = os.path.join(testdir(), 'xmllocales')
- locales.loadLocale(None, None, None)
- locales.loadLocale('de', None, None)
- locales.loadLocale('de', 'DE', None)
- locales.loadLocale('de', 'DE', 'PREEURO')
- self.locale = locales.getLocale('de', 'DE', 'PREEURO')
- locales._locale_dir = orig
+ orig = locales._locale_dir
+ locales._locale_dir = os.path.join(testdir, 'xmllocales')
+ locales.loadLocale(None, None, None)
+ locales.loadLocale('de', None, None)
+ locales.loadLocale('de', 'DE', None)
+ locales.loadLocale('de', 'DE', 'PREEURO')
+ locale = locales.getLocale('de', 'DE', 'PREEURO')
+ locales._locale_dir = orig
def test_getDisplayLanguage(self):
self.assertEqual(self.locale.getDisplayLanguage('de'), 'Deutsch')
=== Zope3/src/zope/i18n/tests/test_formats.py 1.4 => 1.5 ===
--- Zope3/src/zope/i18n/tests/test_formats.py:1.4 Thu Jan 9 14:20:23 2003
+++ Zope3/src/zope/i18n/tests/test_formats.py Mon Jan 27 16:51:56 2003
@@ -28,7 +28,10 @@
from zope.i18n.format import NumberFormat
from zope.i18n.format import parseNumberPattern
-from test_locales import testdir, ICUXMLLocaleFactory
+from zope.i18n.locales import ICUXMLLocaleFactory
+
+from zope.i18n import tests
+testdir = os.path.dirname(tests.__file__)
class LocaleStub:
pass
@@ -130,10 +133,9 @@
method with the German locale.
"""
- def setUp(self):
- path = os.path.join(testdir(), 'xmllocales', 'de.xml')
- self.locale = ICUXMLLocaleFactory(path)()
- self.info = buildDateTimeParseInfo(self.locale.getDefaultCalendar())
+ path = os.path.join(testdir, 'xmllocales', 'de.xml')
+ locale = ICUXMLLocaleFactory(path)()
+ info = buildDateTimeParseInfo(locale.getDefaultCalendar())
def testEra(self):
self.assertEqual(self.info[('G', 1)], '(v. Chr.|n. Chr.)')
@@ -163,10 +165,9 @@
"""Test the functionality of an implmentation of the ILocaleProvider
interface."""
- def setUp(self):
- path = os.path.join(testdir(), 'xmllocales', 'de.xml')
- locale = ICUXMLLocaleFactory(path)()
- self.format = DateTimeFormat(calendar=locale.getDefaultCalendar())
+ path = os.path.join(testdir, 'xmllocales', 'de.xml')
+ locale = ICUXMLLocaleFactory(path)()
+ format = DateTimeFormat(calendar=locale.getDefaultCalendar())
def testInterfaceConformity(self):
self.assert_(IDateTimeFormat.isImplementedBy(self.format))
@@ -458,10 +459,9 @@
class TestNumberFormat(TestCase):
"""Test the functionality of an implmentation of the NumberFormat."""
- def setUp(self):
- path = os.path.join(testdir(), 'xmllocales', 'de_DE.xml')
- locale = ICUXMLLocaleFactory(path)()
- self.format = NumberFormat(
+ path = os.path.join(testdir, 'xmllocales', 'de_DE.xml')
+ locale = ICUXMLLocaleFactory(path)()
+ format = NumberFormat(
symbols=locale.getDefaultNumberFormat().getSymbolMap())
def testInterfaceConformity(self):