[Checkins] SVN: zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/ Moar coverage for z.c.fields.MessageID.

Tres Seaver cvs-admin at zope.org
Wed May 9 20:24:22 UTC 2012


Log message for revision 125791:
  Moar coverage for z.c.fields.MessageID.

Changed:
  U   zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/fields.py
  U   zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_fields.py

-=-
Modified: zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/fields.py
===================================================================
--- zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/fields.py	2012-05-09 20:24:15 UTC (rev 125790)
+++ zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/fields.py	2012-05-09 20:24:19 UTC (rev 125791)
@@ -152,7 +152,7 @@
     def fromUnicode(self, u):
         context = self.context
         domain = getattr(context, 'i18n_domain', '')
-        if not doain:
+        if not domain:
             domain = 'untranslated'
             warnings.warn(
                 "You did not specify an i18n translation domain for the "\

Modified: zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_fields.py
===================================================================
--- zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_fields.py	2012-05-09 20:24:15 UTC (rev 125790)
+++ zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_fields.py	2012-05-09 20:24:19 UTC (rev 125791)
@@ -234,7 +234,7 @@
         self.assertRaises(ValidationError, bo.fromUnicode, 'notvalid')
 
 
-class MessageIDTests(unittest.TestCase):
+class MessageIDTests(unittest.TestCase, _ConformsToIFromUnicode):
 
     def _getTargetClass(self):
         from zope.configuration.fields import MessageID
@@ -243,8 +243,65 @@
     def _makeOne(self, *args, **kw):
         return self._getTargetClass()(*args, **kw)
 
+    def _makeContext(self, domain='testing_domain'):
+        class Info(object):
+            file = 'test_file'
+            line = 42
+        class Context(object):
+            i18n_domain = domain
+            def __init__(self):
+                self.i18n_strings = {}
+                self.info = Info()
+        return Context()
 
+    def test_wo_domain(self):
+        import warnings
+        from zope.configuration._compat import u
+        mid = self._makeOne()
+        context = self._makeContext(None)
+        bound = mid.bind(context)
+        with warnings.catch_warnings(record=True) as log:
+            msgid = bound.fromUnicode(u('testing'))
+        self.assertEqual(len(log), 1)
+        self.assertTrue(str(log[0].message).startswith(
+                            'You did not specify an i18n translation domain'))
+        self.assertEqual(msgid, 'testing')
+        self.assertEqual(msgid.default, None)
+        self.assertEqual(msgid.domain, 'untranslated')
+        self.assertEqual(context.i18n_strings,
+                         {'untranslated': {'testing': [('test_file', 42)]}})
 
+    def test_w_empty_id(self):
+        import warnings
+        from zope.configuration._compat import u
+        mid = self._makeOne()
+        context = self._makeContext()
+        bound = mid.bind(context)
+        with warnings.catch_warnings(record=True) as log:
+            msgid = bound.fromUnicode(u('[] testing'))
+        self.assertEqual(len(log), 0)
+        self.assertEqual(msgid, 'testing')
+        self.assertEqual(msgid.default, None)
+        self.assertEqual(msgid.domain, 'testing_domain')
+        self.assertEqual(context.i18n_strings,
+                         {'testing_domain': {'testing': [('test_file', 42)]}})
+
+    def test_w_id_and_default(self):
+        import warnings
+        from zope.configuration._compat import u
+        mid = self._makeOne()
+        context = self._makeContext()
+        bound = mid.bind(context)
+        with warnings.catch_warnings(record=True) as log:
+            msgid = bound.fromUnicode(u('[testing] default'))
+        self.assertEqual(len(log), 0)
+        self.assertEqual(msgid, 'testing')
+        self.assertEqual(msgid.default, 'default')
+        self.assertEqual(msgid.domain, 'testing_domain')
+        self.assertEqual(context.i18n_strings,
+                         {'testing_domain': {'testing': [('test_file', 42)]}})
+
+
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite(PythonIdentifierTests),



More information about the checkins mailing list