summaryrefslogtreecommitdiff
path: root/src/zope
diff options
context:
space:
mode:
authorMaurits van Rees <maurits@vanrees.org>2014-01-13 16:08:48 +0100
committerMaurits van Rees <maurits@vanrees.org>2014-01-13 16:08:48 +0100
commit3c0c3230d35843a8b0c8e5ffcf6a5eee1bd04b5c (patch)
treee04f7b0275ddabfb95a603ef24ea935582a0e338 /src/zope
parent5efa988a516569468673d9ac4697af65bb28266b (diff)
downloadzope-tal-3c0c3230d35843a8b0c8e5ffcf6a5eee1bd04b5c.tar.gz
Catch warnings in test_translate_existing.
Otherwise a warning is printed each time you run the tests.
Diffstat (limited to 'src/zope')
-rw-r--r--src/zope/tal/talgettext.py21
-rw-r--r--src/zope/tal/tests/test_talgettext.py10
2 files changed, 19 insertions, 12 deletions
diff --git a/src/zope/tal/talgettext.py b/src/zope/tal/talgettext.py
index 7979f1e..4d8de80 100644
--- a/src/zope/tal/talgettext.py
+++ b/src/zope/tal/talgettext.py
@@ -34,6 +34,7 @@ import sys
import time
import getopt
import traceback
+import warnings
from zope.interface import implementer
from zope.tal.htmltalparser import HTMLTALParser
@@ -137,16 +138,16 @@ class POEngine(DummyEngine):
for location in domain[msgid]])
# Note: a lot of encode calls here are needed so
# Python 3 does not break.
- print(("Warning: msgid '%s' in %s already exists "
- "with a different default (bad: %s, should be: %s)\n"
- "The references for the existent value are:\n%s\n" %
- (msgid.encode('utf-8'),
- self.file.encode('utf-8') + ':'.encode('utf-8')
- + str(position).encode('utf-8'),
- msgid.default.encode('utf-8'),
- existing_msgid.default.encode('utf-8'),
- references.encode('utf-8'))),
- file=sys.stderr)
+ warnings.warn(
+ "Warning: msgid '%s' in %s already exists "
+ "with a different default (bad: %s, should be: %s)\n"
+ "The references for the existent value are:\n%s\n" %
+ (msgid.encode('utf-8'),
+ self.file.encode('utf-8') + ':'.encode('utf-8')
+ + str(position).encode('utf-8'),
+ msgid.default.encode('utf-8'),
+ existing_msgid.default.encode('utf-8'),
+ references.encode('utf-8')))
domain[msgid].append((self.file, position))
return 'x'
diff --git a/src/zope/tal/tests/test_talgettext.py b/src/zope/tal/tests/test_talgettext.py
index d024213..8f74daf 100644
--- a/src/zope/tal/tests/test_talgettext.py
+++ b/src/zope/tal/tests/test_talgettext.py
@@ -15,6 +15,7 @@
"""
import sys
import unittest
+import warnings
try:
# Python 2.x
@@ -76,8 +77,13 @@ class test_POEngine(unittest.TestCase):
default=u'Read more\u2026', position=13)
# Adding the same key with a different default is bad and
# triggers a warning.
- engine.translate('foo', 'domain',
- default='Read still more&hellip;', position=42)
+ with warnings.catch_warnings(record=True) as log:
+ warnings.simplefilter("always")
+ engine.translate('foo', 'domain',
+ default='Read still more&hellip;', position=42)
+ self.assertEqual(len(log), 1)
+ self.assertTrue("already exists with a different default"
+ in log[0].message.message)
def test_dynamic_msgids(self):
sample_source = """