diff options
Diffstat (limited to 'src/zope/i18n/tests')
-rw-r--r-- | src/zope/i18n/tests/locale3/en/LC_MESSAGES/zope-i18n2.mo | bin | 0 -> 291 bytes | |||
-rw-r--r-- | src/zope/i18n/tests/test.py | 6 | ||||
-rw-r--r-- | src/zope/i18n/tests/test_compile.py | 8 | ||||
-rw-r--r-- | src/zope/i18n/tests/test_formats.py | 81 | ||||
-rw-r--r-- | src/zope/i18n/tests/test_gettextmessagecatalog.py | 1 | ||||
-rw-r--r-- | src/zope/i18n/tests/test_imessagecatalog.py | 4 | ||||
-rw-r--r-- | src/zope/i18n/tests/test_itranslationdomain.py | 17 | ||||
-rw-r--r-- | src/zope/i18n/tests/test_negotiator.py | 11 | ||||
-rw-r--r-- | src/zope/i18n/tests/test_plurals.py | 25 | ||||
-rw-r--r-- | src/zope/i18n/tests/test_simpletranslationdomain.py | 10 | ||||
-rw-r--r-- | src/zope/i18n/tests/test_testmessagecatalog.py | 6 | ||||
-rw-r--r-- | src/zope/i18n/tests/test_translationdomain.py | 61 | ||||
-rw-r--r-- | src/zope/i18n/tests/test_zcml.py | 37 | ||||
-rw-r--r-- | src/zope/i18n/tests/testi18nawareobject.py | 7 |
14 files changed, 136 insertions, 138 deletions
diff --git a/src/zope/i18n/tests/locale3/en/LC_MESSAGES/zope-i18n2.mo b/src/zope/i18n/tests/locale3/en/LC_MESSAGES/zope-i18n2.mo Binary files differnew file mode 100644 index 0000000..ecfe91c --- /dev/null +++ b/src/zope/i18n/tests/locale3/en/LC_MESSAGES/zope-i18n2.mo diff --git a/src/zope/i18n/tests/test.py b/src/zope/i18n/tests/test.py index 62082c3..07897be 100644 --- a/src/zope/i18n/tests/test.py +++ b/src/zope/i18n/tests/test.py @@ -13,10 +13,12 @@ ############################################################################## """Misc tests """ +import doctest import unittest -import doctest -from zope.component.testing import setUp, tearDown +from zope.component.testing import setUp +from zope.component.testing import tearDown + from zope.i18n.testing import unicode_checker diff --git a/src/zope/i18n/tests/test_compile.py b/src/zope/i18n/tests/test_compile.py index d82c3e7..0a20cf9 100644 --- a/src/zope/i18n/tests/test_compile.py +++ b/src/zope/i18n/tests/test_compile.py @@ -31,9 +31,9 @@ class TestCompile(unittest.TestCase): self.assertIsNone(compile.compile_mo_file('no_such_domain', '')) def test_po_exists_but_invalid(self): - import tempfile - import shutil import os.path + import shutil + import tempfile td = tempfile.mkdtemp(suffix=".zopei18n_test_compile") self.addCleanup(shutil.rmtree, td) @@ -47,10 +47,10 @@ class TestCompile(unittest.TestCase): str(self.handler)) def test_po_exists_cannot_write_mo(self): - import tempfile - import shutil import os import os.path + import shutil + import tempfile td = tempfile.mkdtemp(suffix=".zopei18n_test_compile") self.addCleanup(shutil.rmtree, td) diff --git a/src/zope/i18n/tests/test_formats.py b/src/zope/i18n/tests/test_formats.py index a266de6..2f993fd 100644 --- a/src/zope/i18n/tests/test_formats.py +++ b/src/zope/i18n/tests/test_formats.py @@ -13,31 +13,33 @@ ############################################################################## """This module tests the Formats and everything that goes with it. """ -import decimal import datetime +import decimal import pickle from unittest import TestCase import pytz -from zope.i18n.interfaces import IDateTimeFormat from zope.i18n.format import DateTimeFormat -from zope.i18n.format import parseDateTimePattern, buildDateTimeParseInfo -from zope.i18n.format import DateTimePatternParseError, DateTimeParseError - -from zope.i18n.interfaces import INumberFormat -from zope.i18n.format import NumberFormat, NumberParseError -from zope.i18n.format import parseNumberPattern +from zope.i18n.format import DateTimeParseError +from zope.i18n.format import DateTimePatternParseError +from zope.i18n.format import NumberFormat +from zope.i18n.format import NumberParseError from zope.i18n.format import NumberPatternParseError +from zope.i18n.format import buildDateTimeParseInfo +from zope.i18n.format import parseDateTimePattern +from zope.i18n.format import parseNumberPattern +from zope.i18n.interfaces import IDateTimeFormat +from zope.i18n.interfaces import INumberFormat -class LocaleStub(object): +class LocaleStub: pass -class LocaleCalendarStub(object): +class LocaleCalendarStub: - type = u"gregorian" + type = "gregorian" months = { 1: ('Januar', 'Jan'), @@ -102,14 +104,7 @@ class LocaleCalendarStub(object): raise NotImplementedError() -class _TestCase(TestCase): - # Avoid deprecation warnings in Python 3 by making the preferred - # method name available for Python 2. - assertRaisesRegex = getattr( - TestCase, 'assertRaisesRegex', TestCase.assertRaisesRegexp) - - -class TestDateTimePatternParser(_TestCase): +class TestDateTimePatternParser(TestCase): """Extensive tests for the ICU-based-syntax datetime pattern parser.""" def testParseSimpleTimePattern(self): @@ -207,7 +202,7 @@ class TestDateTimePatternParser(_TestCase): ) -class TestBuildDateTimeParseInfo(_TestCase): +class TestBuildDateTimeParseInfo(TestCase): """This class tests the functionality of the buildDateTimeParseInfo() method with the German locale. """ @@ -250,9 +245,9 @@ class TestBuildDateTimeParseInfo(_TestCase): self.assertEqual(self.info(('M', 2)), '([0-9]{2})') def testMonthNames(self): - names = [u"Januar", u"Februar", u"Maerz", u"April", - u"Mai", u"Juni", u"Juli", u"August", u"September", u"Oktober", - u"November", u"Dezember"] + names = ["Januar", "Februar", "Maerz", "April", + "Mai", "Juni", "Juli", "August", "September", "Oktober", + "November", "Dezember"] self.assertEqual(self.info(('M', 4)), '(' + '|'.join(names) + ')') def testMonthAbbr(self): @@ -276,7 +271,7 @@ class TestBuildDateTimeParseInfo(_TestCase): self.assertEqual(self.info(('E', 3)), '(' + '|'.join(names) + ')') -class TestDateTimeFormat(_TestCase): +class TestDateTimeFormat(TestCase): """Test the functionality of an implmentation of the ILocaleProvider interface.""" @@ -630,69 +625,69 @@ class TestDateTimeFormat(_TestCase): def testFormatDayInYear(self): self.assertEqual( self.format.format(datetime.date(2003, 1, 3), 'D'), - u"3") + "3") self.assertEqual( self.format.format(datetime.date(2003, 1, 3), 'DD'), - u"03") + "03") self.assertEqual( self.format.format(datetime.date(2003, 1, 3), 'DDD'), - u"003") + "003") self.assertEqual( self.format.format(datetime.date(2003, 12, 31), 'D'), - u"365") + "365") self.assertEqual( self.format.format(datetime.date(2003, 12, 31), 'DD'), - u"365") + "365") self.assertEqual( self.format.format(datetime.date(2003, 12, 31), 'DDD'), - u"365") + "365") self.assertEqual( self.format.format(datetime.date(2004, 12, 31), 'DDD'), - u"366") + "366") def testFormatDayOfWeekInMOnth(self): self.assertEqual( self.format.format(datetime.date(2003, 1, 3), 'F'), - u"1") + "1") self.assertEqual( self.format.format(datetime.date(2003, 1, 10), 'F'), - u"2") + "2") self.assertEqual( self.format.format(datetime.date(2003, 1, 17), 'F'), - u"3") + "3") self.assertEqual( self.format.format(datetime.date(2003, 1, 24), 'F'), - u"4") + "4") self.assertEqual( self.format.format(datetime.date(2003, 1, 31), 'F'), - u"5") + "5") self.assertEqual( self.format.format(datetime.date(2003, 1, 6), 'F'), - u"1") + "1") def testFormatUnusualFormats(self): self.assertEqual( self.format.format(datetime.date(2003, 1, 3), 'DDD-yyyy'), - u"003-2003") + "003-2003") self.assertEqual( self.format.format(datetime.date(2003, 1, 10), "F. EEEE 'im' MMMM, yyyy"), - u"2. Freitag im Januar, 2003") + "2. Freitag im Januar, 2003") def testFormatGregorianEra(self): self.assertEqual( self.format.format(datetime.date(2017, 12, 17), 'G'), - u'n. Chr.' + 'n. Chr.' ) def testFormateMonthLengthOne(self): self.assertEqual( self.format.format(datetime.date(2017, 12, 17), 'M'), - u'12' + '12' ) -class TestNumberPatternParser(_TestCase): +class TestNumberPatternParser(TestCase): """Extensive tests for the ICU-based-syntax number pattern parser.""" def testParseSimpleIntegerPattern(self): @@ -1047,7 +1042,7 @@ class TestNumberPatternParser(_TestCase): neg_pattern) -class TestNumberFormat(_TestCase): +class TestNumberFormat(TestCase): """Test the functionality of an implmentation of the NumberFormat.""" format = NumberFormat(symbols={ diff --git a/src/zope/i18n/tests/test_gettextmessagecatalog.py b/src/zope/i18n/tests/test_gettextmessagecatalog.py index 5bd93df..0272898 100644 --- a/src/zope/i18n/tests/test_gettextmessagecatalog.py +++ b/src/zope/i18n/tests/test_gettextmessagecatalog.py @@ -14,6 +14,7 @@ """Test a gettext implementation of a Message Catalog. """ import os + from zope.i18n.gettextmessagecatalog import GettextMessageCatalog from zope.i18n.tests import test_imessagecatalog diff --git a/src/zope/i18n/tests/test_imessagecatalog.py b/src/zope/i18n/tests/test_imessagecatalog.py index 36fb43c..95295cd 100644 --- a/src/zope/i18n/tests/test_imessagecatalog.py +++ b/src/zope/i18n/tests/test_imessagecatalog.py @@ -14,10 +14,12 @@ """This is an 'abstract' test for the IMessageCatalog interface. """ import unittest + from zope.interface.verify import verifyObject -from zope.i18n.interfaces import IMessageCatalog from zope.schema import getValidationErrors +from zope.i18n.interfaces import IMessageCatalog + class TestIMessageCatalog(unittest.TestCase): diff --git a/src/zope/i18n/tests/test_itranslationdomain.py b/src/zope/i18n/tests/test_itranslationdomain.py index bea5360..81bec8a 100644 --- a/src/zope/i18n/tests/test_itranslationdomain.py +++ b/src/zope/i18n/tests/test_itranslationdomain.py @@ -14,22 +14,21 @@ """This is an 'abstract' test for the ITranslationDomain interface. """ import unittest -from zope.interface.verify import verifyObject -from zope.interface import implementer import zope.component from zope.component.testing import PlacelessSetup - +from zope.interface import implementer +from zope.interface.verify import verifyObject from zope.schema import getValidationErrors -from zope.i18n._compat import text_type -from zope.i18n.negotiator import negotiator -from zope.i18n.interfaces import INegotiator, IUserPreferredLanguages +from zope.i18n.interfaces import INegotiator from zope.i18n.interfaces import ITranslationDomain +from zope.i18n.interfaces import IUserPreferredLanguages +from zope.i18n.negotiator import negotiator @implementer(IUserPreferredLanguages) -class Environment(object): +class Environment: def __init__(self, langs=()): self.langs = langs @@ -45,7 +44,7 @@ class TestITranslationDomain(PlacelessSetup): raise NotImplementedError() def setUp(self): - super(TestITranslationDomain, self).setUp() + super().setUp() self._domain = self._getTranslationDomain() # Setup the negotiator utility @@ -94,7 +93,7 @@ class TestITranslationDomain(PlacelessSetup): translate = self._domain.translate translated = translate('no way', target_language='en') self.assertEqual(translated, "no way") - self.assertIsInstance(translated, text_type) + self.assertIsInstance(translated, str) def testNoTargetLanguage(self): translate = self._domain.translate diff --git a/src/zope/i18n/tests/test_negotiator.py b/src/zope/i18n/tests/test_negotiator.py index 9267332..bf5ba4d 100644 --- a/src/zope/i18n/tests/test_negotiator.py +++ b/src/zope/i18n/tests/test_negotiator.py @@ -15,14 +15,15 @@ """ import unittest -from zope.i18n.negotiator import Negotiator -from zope.i18n.interfaces import IUserPreferredLanguages from zope.component.testing import PlacelessSetup from zope.interface import implementer +from zope.i18n.interfaces import IUserPreferredLanguages +from zope.i18n.negotiator import Negotiator + @implementer(IUserPreferredLanguages) -class Env(object): +class Env: def __init__(self, langs=()): self.langs = langs @@ -34,7 +35,7 @@ class Env(object): class NegotiatorTest(PlacelessSetup, unittest.TestCase): def setUp(self): - super(NegotiatorTest, self).setUp() + super().setUp() self.negotiator = Negotiator() def test_findLanguages(self): @@ -55,5 +56,5 @@ class NegotiatorTest(PlacelessSetup, unittest.TestCase): def test_suite(): return unittest.TestSuite(( - unittest.makeSuite(NegotiatorTest), + unittest.defaultTestLoader.loadTestsFromTestCase(NegotiatorTest), )) diff --git a/src/zope/i18n/tests/test_plurals.py b/src/zope/i18n/tests/test_plurals.py index bc97bf3..2577bed 100644 --- a/src/zope/i18n/tests/test_plurals.py +++ b/src/zope/i18n/tests/test_plurals.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- ############################################################################## # # Copyright (c) 2001, 2002 Zope Foundation and Contributors. @@ -18,24 +17,26 @@ import os import unittest import zope.component -from zope.i18n import tests, translate -from zope.i18n.translationdomain import TranslationDomain -from zope.i18n.gettextmessagecatalog import GettextMessageCatalog from zope.i18nmessageid import MessageFactory + +from zope.i18n import tests +from zope.i18n import translate +from zope.i18n.gettextmessagecatalog import GettextMessageCatalog from zope.i18n.interfaces import ITranslationDomain +from zope.i18n.translationdomain import TranslationDomain class TestPlurals(unittest.TestCase): def _getMessageCatalog(self, locale, variant="default"): path = os.path.dirname(tests.__file__) - self._path = os.path.join(path, '%s-%s.mo' % (locale, variant)) + self._path = os.path.join(path, '{}-{}.mo'.format(locale, variant)) catalog = GettextMessageCatalog(locale, variant, self._path) return catalog def _getTranslationDomain(self, locale, variant="default"): path = os.path.dirname(tests.__file__) - self._path = os.path.join(path, '%s-%s.mo' % (locale, variant)) + self._path = os.path.join(path, '{}-{}.mo'.format(locale, variant)) catalog = GettextMessageCatalog(locale, variant, self._path) domain = TranslationDomain('default') domain.addCatalog(catalog) @@ -124,22 +125,22 @@ class TestPlurals(unittest.TestCase): self.assertEqual(catalog.getPluralMessage( 'There is one file.', 'There are %d files.', 0), - u"Istnieją 0 plików.") + "Istnieją 0 plików.") self.assertEqual(catalog.getPluralMessage( 'There is one file.', 'There are %d files.', 1), - u"Istnieje 1 plik.") + "Istnieje 1 plik.") self.assertEqual(catalog.getPluralMessage( 'There is one file.', 'There are %d files.', 3), - u"Istnieją 3 pliki.") + "Istnieją 3 pliki.") self.assertEqual(catalog.getPluralMessage( 'There is one file.', 'There are %d files.', 17), - u"Istnieją 17 plików.") + "Istnieją 17 plików.") self.assertEqual(catalog.getPluralMessage( 'There is one file.', 'There are %d files.', 23), - u"Istnieją 23 pliki.") + "Istnieją 23 pliki.") self.assertEqual(catalog.getPluralMessage( 'There is one file.', 'There are %d files.', 28), - u"Istnieją 28 plików.") + "Istnieją 28 plików.") def test_floater(self): """Test with the number being a float. diff --git a/src/zope/i18n/tests/test_simpletranslationdomain.py b/src/zope/i18n/tests/test_simpletranslationdomain.py index 2f233d6..4c88d8e 100644 --- a/src/zope/i18n/tests/test_simpletranslationdomain.py +++ b/src/zope/i18n/tests/test_simpletranslationdomain.py @@ -14,6 +14,7 @@ """This module tests the regular persistent Translation Domain. """ import unittest + from zope.i18n.simpletranslationdomain import SimpleTranslationDomain from zope.i18n.tests.test_itranslationdomain import TestITranslationDomain @@ -22,7 +23,8 @@ data = { ('en', 'short_greeting'): 'Hello!', ('de', 'short_greeting'): 'Hallo!', ('en', 'greeting'): 'Hello $name, how are you?', - ('de', 'greeting'): 'Hallo $name, wie geht es Dir?'} + ('de', 'greeting'): 'Hallo $name, wie geht es Dir?', +} class TestSimpleTranslationDomain(unittest.TestCase, TestITranslationDomain): @@ -36,9 +38,3 @@ class TestSimpleTranslationDomain(unittest.TestCase, TestITranslationDomain): def _getTranslationDomain(self): domain = SimpleTranslationDomain('default', data) return domain - - -def test_suite(): - suite = unittest.TestSuite() - suite.addTest(unittest.makeSuite(TestSimpleTranslationDomain)) - return suite diff --git a/src/zope/i18n/tests/test_testmessagecatalog.py b/src/zope/i18n/tests/test_testmessagecatalog.py index e5c8e57..a28148a 100644 --- a/src/zope/i18n/tests/test_testmessagecatalog.py +++ b/src/zope/i18n/tests/test_testmessagecatalog.py @@ -12,11 +12,11 @@ # ############################################################################## -import unittest import doctest +import unittest def test_suite(): - return unittest.TestSuite(( + return unittest.TestSuite( doctest.DocFileSuite('../testmessagecatalog.rst') - )) + ) diff --git a/src/zope/i18n/tests/test_translationdomain.py b/src/zope/i18n/tests/test_translationdomain.py index 5d55156..b681dc4 100644 --- a/src/zope/i18n/tests/test_translationdomain.py +++ b/src/zope/i18n/tests/test_translationdomain.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- ############################################################################## # # Copyright (c) 2001-2008 Zope Foundation and Contributors. @@ -14,16 +13,18 @@ ############################################################################## """This module tests the regular persistent Translation Domain. """ -import unittest import os -from zope.i18n.translationdomain import TranslationDomain -from zope.i18n.gettextmessagecatalog import GettextMessageCatalog -from zope.i18n.tests.test_itranslationdomain import \ - TestITranslationDomain, Environment +import unittest + +import zope.component from zope.i18nmessageid import MessageFactory + +from zope.i18n.gettextmessagecatalog import GettextMessageCatalog from zope.i18n.interfaces import ITranslationDomain +from zope.i18n.tests.test_itranslationdomain import Environment +from zope.i18n.tests.test_itranslationdomain import TestITranslationDomain +from zope.i18n.translationdomain import TranslationDomain -import zope.component testdir = os.path.dirname(__file__) @@ -68,19 +69,19 @@ class TestGlobalTranslationDomain(TestITranslationDomain, unittest.TestCase): def testEmptyStringTranslate(self): translate = self._domain.translate - self.assertEqual(translate(u"", target_language='en'), u"") - self.assertEqual(translate(u"", target_language='foo'), u"") + self.assertEqual(translate("", target_language='en'), "") + self.assertEqual(translate("", target_language='foo'), "") def testStringTranslate(self): self.assertEqual( - self._domain.translate(u"short_greeting", target_language='en'), - u"Hello!") + self._domain.translate("short_greeting", target_language='en'), + "Hello!") def testMessageIDTranslate(self): factory = MessageFactory('default') translate = self._domain.translate - msgid = factory(u"short_greeting", 'default') - self.assertEqual(translate(msgid, target_language='en'), u"Hello!") + msgid = factory("short_greeting", 'default') + self.assertEqual(translate(msgid, target_language='en'), "Hello!") # MessageID attributes override arguments msgid = factory('43-not-there', 'this ${that} the other', mapping={'that': 'THAT'}) @@ -91,13 +92,13 @@ class TestGlobalTranslationDomain(TestITranslationDomain, unittest.TestCase): def testMessageIDRecursiveTranslate(self): factory = MessageFactory('default') translate = self._domain.translate - msgid_sub1 = factory(u"44-not-there", '${blue}', + msgid_sub1 = factory("44-not-there", '${blue}', mapping={'blue': 'BLUE'}) - msgid_sub2 = factory(u"45-not-there", '${yellow}', + msgid_sub2 = factory("45-not-there", '${yellow}', mapping={'yellow': 'YELLOW'}) mapping = {'color1': msgid_sub1, 'color2': msgid_sub2} - msgid = factory(u"46-not-there", 'Color: ${color1}/${color2}', + msgid = factory("46-not-there", 'Color: ${color1}/${color2}', mapping=mapping) self.assertEqual( translate(msgid, target_language='en', default="default"), @@ -106,9 +107,9 @@ class TestGlobalTranslationDomain(TestITranslationDomain, unittest.TestCase): self.assertEqual(msgid.mapping, {'color1': msgid_sub1, 'color2': msgid_sub2}) # A circular reference should not lead to crashes - msgid1 = factory(u"47-not-there", 'Message 1 and $msg2', + msgid1 = factory("47-not-there", 'Message 1 and $msg2', mapping={}) - msgid2 = factory(u"48-not-there", 'Message 2 and $msg1', + msgid2 = factory("48-not-there", 'Message 2 and $msg1', mapping={}) msgid1.mapping['msg2'] = msgid2 msgid2.mapping['msg1'] = msgid1 @@ -118,7 +119,7 @@ class TestGlobalTranslationDomain(TestITranslationDomain, unittest.TestCase): # message id but a Unicode with a directly passed mapping self.assertEqual( "Color: BLUE/YELLOW", - translate(u"Color: ${color1}/${color2}", mapping=mapping, + translate("Color: ${color1}/${color2}", mapping=mapping, target_language='en')) # If we have mapping with a message id from a different @@ -126,9 +127,9 @@ class TestGlobalTranslationDomain(TestITranslationDomain, unittest.TestCase): # message domain is not registered yet, we should return a # default translation. alt_factory = MessageFactory('alt') - msgid_sub = alt_factory(u"special", default=u"oohhh") + msgid_sub = alt_factory("special", default="oohhh") mapping = {'message': msgid_sub} - msgid = factory(u"46-not-there", 'Message: ${message}', + msgid = factory("46-not-there", 'Message: ${message}', mapping=mapping) # test we get a default with no domain registered self.assertEqual( @@ -156,9 +157,9 @@ class TestGlobalTranslationDomain(TestITranslationDomain, unittest.TestCase): zope.component.provideUtility(domain, ITranslationDomain, 'alt') factory = MessageFactory('alt') - msgid = factory(u"special", 'default') + msgid = factory("special", 'default') self.assertEqual( - self._domain.translate(msgid, target_language='en'), u"Wow") + self._domain.translate(msgid, target_language='en'), "Wow") def testSimpleFallbackTranslation(self): translate = self._domain.translate @@ -166,11 +167,11 @@ class TestGlobalTranslationDomain(TestITranslationDomain, unittest.TestCase): # Test that a translation in an unsupported language returns a # translation in the fallback language (by default, English) eq(translate('short_greeting', target_language='es'), - u"Hello!") + "Hello!") # Same test, but use the context argument instead of target_language context = Environment() eq(translate('short_greeting', context=context), - u"Hello!") + "Hello!") def testInterpolationWithoutTranslation(self): translate = self._domain.translate @@ -233,7 +234,7 @@ class TestGlobalTranslationDomain(TestITranslationDomain, unittest.TestCase): domain.addCatalog(standard_catalog) self.assertEqual( domain.translate('short_greeting', target_language='sr'), - u"Hello in Serbian Standard!", + "Hello in Serbian Standard!", ) # Test the Latin file. @@ -241,12 +242,12 @@ class TestGlobalTranslationDomain(TestITranslationDomain, unittest.TestCase): domain.addCatalog(latin_catalog) self.assertEqual( domain.translate('short_greeting', target_language='sr'), - u"Hello in Serbian Latin!", + "Hello in Serbian Latin!", ) # Note that sr@Latn is not recognizes as language id. self.assertEqual( domain.translate('short_greeting', target_language='sr@Latn'), - u"short_greeting", + "short_greeting", ) # Test the Cyrillic file. @@ -254,7 +255,7 @@ class TestGlobalTranslationDomain(TestITranslationDomain, unittest.TestCase): domain.addCatalog(cyrillic_catalog) self.assertEqual( domain.translate('short_greeting', target_language='sr'), - u"Hello in српски!", + "Hello in српски!", ) # When I have all three locales, this is the order that @@ -266,5 +267,5 @@ class TestGlobalTranslationDomain(TestITranslationDomain, unittest.TestCase): # The Latin one is first, so it wins. self.assertEqual( domain.translate('short_greeting', target_language='sr'), - u"Hello in Serbian Latin!", + "Hello in Serbian Latin!", ) diff --git a/src/zope/i18n/tests/test_zcml.py b/src/zope/i18n/tests/test_zcml.py index cd3d2b4..5540beb 100644 --- a/src/zope/i18n/tests/test_zcml.py +++ b/src/zope/i18n/tests/test_zcml.py @@ -25,9 +25,8 @@ from zope.component.testing import PlacelessSetup from zope.configuration import xmlconfig import zope.i18n.tests -from zope.i18n._compat import text_type -from zope.i18n.interfaces import ITranslationDomain from zope.i18n import config +from zope.i18n.interfaces import ITranslationDomain template = """\ @@ -43,13 +42,13 @@ class DirectivesTest(PlacelessSetup, unittest.TestCase): # This test suite needs the [zcml] and [compile] extra dependencies def setUp(self): - super(DirectivesTest, self).setUp() + super().setUp() self.context = xmlconfig.file('meta.zcml', zope.i18n) self.allowed = config.ALLOWED_LANGUAGES config.ALLOWED_LANGUAGES = None def tearDown(self): - super(DirectivesTest, self).tearDown() + super().tearDown() config.ALLOWED_LANGUAGES = self.allowed def testRegisterTranslations(self): @@ -64,7 +63,7 @@ class DirectivesTest(PlacelessSetup, unittest.TestCase): 'locale', 'en', 'LC_MESSAGES', 'zope-i18n.mo') util = getUtility(ITranslationDomain, 'zope-i18n') self.assertEqual(util._catalogs.get('test'), ['test']) - self.assertEqual(util._catalogs.get('en'), [text_type(path)]) + self.assertEqual(util._catalogs.get('en'), [str(path)]) def testAllowedTranslations(self): self.assertTrue(queryUtility(ITranslationDomain) is None) @@ -79,7 +78,7 @@ class DirectivesTest(PlacelessSetup, unittest.TestCase): 'locale', 'de', 'LC_MESSAGES', 'zope-i18n.mo') util = getUtility(ITranslationDomain, 'zope-i18n') self.assertEqual(util._catalogs, - {'test': ['test'], 'de': [text_type(path)]}) + {'test': ['test'], 'de': [str(path)]}) def testRegisterDistributedTranslations(self): self.assertTrue(queryUtility(ITranslationDomain, 'zope-i18n') is None) @@ -102,16 +101,16 @@ class DirectivesTest(PlacelessSetup, unittest.TestCase): util = getUtility(ITranslationDomain, 'zope-i18n') self.assertEqual(util._catalogs.get('test'), ['test', 'test']) self.assertEqual(util._catalogs.get('en'), - [text_type(path1), text_type(path2)]) + [str(path1), str(path2)]) - msg = util.translate(u"Additional message", target_language='en') - self.assertEqual(msg, u"Additional message translated") + msg = util.translate("Additional message", target_language='en') + self.assertEqual(msg, "Additional message translated") - msg = util.translate(u"New Domain", target_language='en') - self.assertEqual(msg, u"New Domain translated") + msg = util.translate("New Domain", target_language='en') + self.assertEqual(msg, "New Domain translated") - msg = util.translate(u"New Language", target_language='en') - self.assertEqual(msg, u"New Language translated") + msg = util.translate("New Language", target_language='en') + self.assertEqual(msg, "New Language translated") def testRegisterAndCompileTranslations(self): config.COMPILE_MO_FILES = True @@ -139,14 +138,14 @@ class DirectivesTest(PlacelessSetup, unittest.TestCase): ''', self.context) util = getUtility(ITranslationDomain, 'zope-i18n') self.assertEqual(util._catalogs, - {'test': ['test'], 'en': [text_type(path)]}) + {'test': ['test'], 'en': [str(path)]}) - msg = util.translate(u"I'm a newer file", target_language='en') - self.assertEqual(msg, u"I'm a newer file translated") + msg = util.translate("I'm a newer file", target_language='en') + self.assertEqual(msg, "I'm a newer file translated") util = getUtility(ITranslationDomain, 'zope-i18n2') - msg = util.translate(u"I'm a new file", target_language='en') - self.assertEqual(msg, u"I'm a new file translated") + msg = util.translate("I'm a new file", target_language='en') + self.assertEqual(msg, "I'm a new file translated") # Reset the mtime of the mo file os.utime(path, (path_atime, path_mtime)) @@ -165,7 +164,7 @@ class DirectivesTest(PlacelessSetup, unittest.TestCase): 'locale3', 'en', 'LC_MESSAGES', 'zope-i18n.mo') util = getUtility(ITranslationDomain, 'zope-i18n') self.assertEqual(util._catalogs, - {'test': ['test'], 'en': [text_type(path)]}) + {'test': ['test'], 'en': [str(path)]}) self.assertTrue(queryUtility(ITranslationDomain, 'zope-i18n2') is None) diff --git a/src/zope/i18n/tests/testi18nawareobject.py b/src/zope/i18n/tests/testi18nawareobject.py index 996416b..bc71044 100644 --- a/src/zope/i18n/tests/testi18nawareobject.py +++ b/src/zope/i18n/tests/testi18nawareobject.py @@ -15,12 +15,13 @@ """ import unittest -from zope.i18n.interfaces import II18nAware from zope.interface import implementer +from zope.i18n.interfaces import II18nAware + @implementer(II18nAware) -class I18nAwareContentObject(object): +class I18nAwareContentObject: def __init__(self): self.content = {} @@ -55,7 +56,7 @@ class I18nAwareContentObject(object): ############################################################ -class AbstractTestII18nAwareMixin(object): +class AbstractTestII18nAwareMixin: def setUp(self): self.object = self._createObject() |