Commit ff47b70e authored by Jim Fulton's avatar Jim Fulton

Include unexpected non-text in warning

parent 752e4d2b
......@@ -758,7 +758,7 @@ def text_or_warn(s):
if isinstance(s, text_type):
return s
warnings.warn("Expected text", DeprecationWarning, stacklevel=3)
warnings.warn("Expected text, got %r" % s, DeprecationWarning, stacklevel=3)
if isinstance(s, bytes):
return s.decode('utf-8', 'replace')
else:
......
......@@ -1014,16 +1014,21 @@ class TransactionTests(unittest.TestCase):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
txn.note(42)
self.assertNonTextDeprecationWarning(w)
self.assertNonTextDeprecationWarning(w, '42')
self.assertEqual(txn.description, u'42')
def assertNonTextDeprecationWarning(self, w):
def assertNonTextDeprecationWarning(self, w, expect=None):
[w] = w
self.assertEqual(
(DeprecationWarning, "Expected text",
os.path.splitext(__file__)[0]),
(w.category, str(w.message), os.path.splitext(w.filename)[0]),
)
prefix = "Expected text, got "
str_message = str(w.message)
if expect:
self.assertEqual(prefix + expect, str_message)
else:
self.assertTrue(str_message.startswith(prefix))
self.assertEqual((DeprecationWarning, os.path.splitext(__file__)[0]),
(w.category, os.path.splitext(w.filename)[0]),
)
def test_description_bytes(self):
txn = self._makeOne()
......@@ -1038,7 +1043,7 @@ class TransactionTests(unittest.TestCase):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
txn.description = 42
self.assertNonTextDeprecationWarning(w)
self.assertNonTextDeprecationWarning(w, '42')
self.assertEqual(txn.description, u'42')
def test_description_None(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment