/usr/lib/python2.7/dist-packages/zope/i18n/tests/test_zcml.py is in python-zope.i18n 4.1.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | ##############################################################################
#
# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Test the gts ZCML namespace directives.
"""
import sys
import doctest
import os
import shutil
import stat
import unittest
from zope.component import getUtility
from zope.component import queryUtility
from zope.component.testing import PlacelessSetup
import zope.i18n.tests
from zope.i18n.interfaces import ITranslationDomain
from zope.i18n import config
from .._compat import _u
PY3 = sys.version_info[0] == 3
if PY3:
unicode = str
template = """\
<configure
xmlns='http://namespaces.zope.org/zope'
xmlns:i18n='http://namespaces.zope.org/i18n'>
%s
</configure>"""
class DirectivesTest(PlacelessSetup, unittest.TestCase):
# This test suite needs the [zcml] and [compile] extra dependencies
level = 2
def setUp(self):
from zope.configuration import xmlconfig
super(DirectivesTest, self).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()
config.ALLOWED_LANGUAGES = self.allowed
def testRegisterTranslations(self):
from zope.configuration import xmlconfig
self.assertTrue(queryUtility(ITranslationDomain) is None)
xmlconfig.string(
template % '''
<configure package="zope.i18n.tests">
<i18n:registerTranslations directory="locale" />
</configure>
''', self.context)
path = os.path.join(os.path.dirname(zope.i18n.tests.__file__),
'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'), [unicode(path)])
def testAllowedTranslations(self):
from zope.configuration import xmlconfig
self.assertTrue(queryUtility(ITranslationDomain) is None)
config.ALLOWED_LANGUAGES = ('de', 'fr')
xmlconfig.string(
template % '''
<configure package="zope.i18n.tests">
<i18n:registerTranslations directory="locale" />
</configure>
''', self.context)
path = os.path.join(os.path.dirname(zope.i18n.tests.__file__),
'locale', 'de', 'LC_MESSAGES', 'zope-i18n.mo')
util = getUtility(ITranslationDomain, 'zope-i18n')
self.assertEqual(util._catalogs,
{'test': ['test'], 'de': [unicode(path)]})
def testRegisterDistributedTranslations(self):
from zope.configuration import xmlconfig
self.assertTrue(queryUtility(ITranslationDomain, 'zope-i18n') is None)
xmlconfig.string(
template % '''
<configure package="zope.i18n.tests">
<i18n:registerTranslations directory="locale" />
</configure>
''', self.context)
xmlconfig.string(
template % '''
<configure package="zope.i18n.tests">
<i18n:registerTranslations directory="locale2" />
</configure>
''', self.context)
path1 = os.path.join(os.path.dirname(zope.i18n.tests.__file__),
'locale', 'en', 'LC_MESSAGES', 'zope-i18n.mo')
path2 = os.path.join(os.path.dirname(zope.i18n.tests.__file__),
'locale2', 'en', 'LC_MESSAGES', 'zope-i18n.mo')
util = getUtility(ITranslationDomain, 'zope-i18n')
self.assertEqual(util._catalogs.get('test'), ['test', 'test'])
self.assertEqual(util._catalogs.get('en'),
[unicode(path1), unicode(path2)])
msg = util.translate(_u("Additional message"), target_language='en')
self.assertEqual(msg, _u("Additional message translated"))
msg = util.translate(_u("New Domain"), target_language='en')
self.assertEqual(msg, _u("New Domain translated"))
msg = util.translate(_u("New Language"), target_language='en')
self.assertEqual(msg, _u("New Language translated"))
def testRegisterAndCompileTranslations(self):
from zope.configuration import xmlconfig
config.COMPILE_MO_FILES = True
self.assertTrue(queryUtility(ITranslationDomain) is None)
# Copy an old and outdated file over, so we can test if the
# newer file check works
testpath = os.path.join(os.path.dirname(zope.i18n.tests.__file__))
basepath = os.path.join(testpath, 'locale3', 'en', 'LC_MESSAGES')
in_ = os.path.join(basepath, 'zope-i18n.in')
path = os.path.join(basepath, 'zope-i18n.mo')
shutil.copy2(in_, path)
# Make sure the older mo file always has an older time stamp
# than the po file
path_atime = os.stat(path)[stat.ST_ATIME]
path_mtime = os.stat(path)[stat.ST_MTIME]
os.utime(path, (path_atime, path_mtime - 6000))
xmlconfig.string(
template % '''
<configure package="zope.i18n.tests">
<i18n:registerTranslations directory="locale3" />
</configure>
''', self.context)
util = getUtility(ITranslationDomain, 'zope-i18n')
self.assertEqual(util._catalogs,
{'test': ['test'], 'en': [unicode(path)]})
msg = util.translate(_u("I'm a newer file"), target_language='en')
self.assertEqual(msg, _u("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"))
# Reset the mtime of the mo file
os.utime(path, (path_atime, path_mtime))
def testRegisterTranslationsForDomain(self):
from zope.configuration import xmlconfig
self.assertTrue(queryUtility(ITranslationDomain, 'zope-i18n') is None)
self.assertTrue(queryUtility(ITranslationDomain, 'zope-i18n2') is None)
xmlconfig.string(
template % '''
<configure package="zope.i18n.tests">
<i18n:registerTranslations directory="locale3" domain="zope-i18n" />
</configure>
''', self.context)
path = os.path.join(os.path.dirname(zope.i18n.tests.__file__),
'locale3', 'en', 'LC_MESSAGES', 'zope-i18n.mo')
util = getUtility(ITranslationDomain, 'zope-i18n')
self.assertEqual(util._catalogs,
{'test': ['test'], 'en': [unicode(path)]})
self.assertTrue(queryUtility(ITranslationDomain, 'zope-i18n2') is None)
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(DirectivesTest),
doctest.DocFileSuite('configure.txt'),
))
|