/usr/lib/python3/dist-packages/zope/i18nmessageid/tests.py is in python3-zope.i18nmessageid 4.0.3-2build2.
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 | ##############################################################################
#
# Copyright (c) 2003 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.
#
##############################################################################
"""Message ID tests.
"""
import unittest
class PyMessageTests(unittest.TestCase):
_TEST_REAOONLY = True
def _getTargetClass(self):
from zope.i18nmessageid.message import pyMessage
return pyMessage
def _makeOne(self, *args, **kw):
return self._getTargetClass()(*args, **kw)
def test_ctor_defaults(self):
message = self._makeOne('testing')
self.assertEqual(message, 'testing')
self.assertEqual(message.domain, None)
self.assertEqual(message.default, None)
self.assertEqual(message.mapping, None)
if self._TEST_REAOONLY:
self.assertTrue(message._readonly)
def test_ctor_explicit(self):
mapping = {'key': 'value'}
message = self._makeOne('testing', 'domain', 'default', mapping)
self.assertEqual(message, 'testing')
self.assertEqual(message.domain, 'domain')
self.assertEqual(message.default, 'default')
self.assertEqual(message.mapping, mapping)
if self._TEST_REAOONLY:
self.assertTrue(message._readonly)
def test_ctor_copy(self):
mapping = {'key': 'value'}
source = self._makeOne('testing', 'domain', 'default', mapping)
message = self._makeOne(source)
self.assertEqual(message, 'testing')
self.assertEqual(message.domain, 'domain')
self.assertEqual(message.default, 'default')
self.assertEqual(message.mapping, mapping)
if self._TEST_REAOONLY:
self.assertTrue(message._readonly)
def test_ctor_copy_w_overrides(self):
mapping = {'key': 'value'}
source = self._makeOne('testing')
message = self._makeOne(source, 'domain', 'default', mapping)
self.assertEqual(message, 'testing')
self.assertEqual(message.domain, 'domain')
self.assertEqual(message.default, 'default')
self.assertEqual(message.mapping, mapping)
if self._TEST_REAOONLY:
self.assertTrue(message._readonly)
def test_domain_immutable(self):
message = self._makeOne('testing')
def _try():
message.domain = 'domain'
self.assertRaises(TypeError, _try)
def test_default_immutable(self):
message = self._makeOne('testing')
def _try():
message.default = 'default'
self.assertRaises(TypeError, _try)
def test_mapping_immutable(self):
mapping = {'key': 'value'}
message = self._makeOne('testing')
def _try():
message.mapping = mapping
self.assertRaises(TypeError, _try)
def test_unknown_immutable(self):
message = self._makeOne('testing')
def _try():
message.unknown = 'unknown'
# C version raises AttributeError, Python version TypeError
self.assertRaises((TypeError, AttributeError), _try)
def test___reduce__(self):
mapping = {'key': 'value'}
source = self._makeOne('testing')
message = self._makeOne(source, 'domain', 'default', mapping)
klass, state = message.__reduce__()
self.assertTrue(klass is self._getTargetClass())
self.assertEqual(state, ('testing', 'domain', 'default', mapping))
class MessageTests(PyMessageTests):
_TEST_REAOONLY = False
def _getTargetClass(self):
from zope.i18nmessageid.message import Message
return Message
class MessageFactoryTests(unittest.TestCase):
def _getTargetClass(self):
from zope.i18nmessageid.message import MessageFactory
return MessageFactory
def _makeOne(self, *args, **kw):
return self._getTargetClass()(*args, **kw)
def test___call___defaults(self):
from zope.i18nmessageid.message import Message
factory = self._makeOne('domain')
message = factory('testing')
self.assertTrue(isinstance(message, Message))
self.assertEqual(message, 'testing')
self.assertEqual(message.domain, 'domain')
self.assertEqual(message.default, None)
self.assertEqual(message.mapping, None)
def test___call___explicit(self):
from zope.i18nmessageid.message import Message
mapping = {'key': 'value'}
factory = self._makeOne('domain')
message = factory('testing', 'default', mapping)
self.assertTrue(isinstance(message, Message))
self.assertEqual(message, 'testing')
self.assertEqual(message.domain, 'domain')
self.assertEqual(message.default, 'default')
self.assertEqual(message.mapping, mapping)
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(PyMessageTests),
unittest.makeSuite(MessageTests),
unittest.makeSuite(MessageFactoryTests),
))
|