[Python-checkins] cpython (merge 3.5 -> default): Issue #27528: Merge warning doc and test from 3.5

martin.panter python-checkins at python.org
Mon Jul 18 22:51:15 EDT 2016


https://hg.python.org/cpython/rev/e0761e817deb
changeset:   102403:e0761e817deb
parent:      102400:c10fe99afced
parent:      102402:7571432200a2
user:        Martin Panter <vadmium+py at gmail.com>
date:        Tue Jul 19 02:50:51 2016 +0000
summary:
  Issue #27528: Merge warning doc and test from 3.5

files:
  Doc/library/warnings.rst           |   7 ++++---
  Lib/test/test_warnings/__init__.py |  12 ++++++++++++
  2 files changed, 16 insertions(+), 3 deletions(-)


diff --git a/Doc/library/warnings.rst b/Doc/library/warnings.rst
--- a/Doc/library/warnings.rst
+++ b/Doc/library/warnings.rst
@@ -141,14 +141,15 @@
   |               | warnings, regardless of location             |
   +---------------+----------------------------------------------+
 
-* *message* is a string containing a regular expression that the warning message
-  must match (the match is compiled to always be case-insensitive).
+* *message* is a string containing a regular expression that the start of
+  the warning message must match.  The expression is compiled to always be
+  case-insensitive.
 
 * *category* is a class (a subclass of :exc:`Warning`) of which the warning
   category must be a subclass in order to match.
 
 * *module* is a string containing a regular expression that the module name must
-  match (the match is compiled to be case-sensitive).
+  match.  The expression is compiled to be case-sensitive.
 
 * *lineno* is an integer that the line number where the warning occurred must
   match, or ``0`` to match all line numbers.
diff --git a/Lib/test/test_warnings/__init__.py b/Lib/test/test_warnings/__init__.py
--- a/Lib/test/test_warnings/__init__.py
+++ b/Lib/test/test_warnings/__init__.py
@@ -263,6 +263,18 @@
             self.assertEqual(str(w[-1].message), text)
             self.assertTrue(w[-1].category is UserWarning)
 
+    def test_message_matching(self):
+        with original_warnings.catch_warnings(record=True,
+                module=self.module) as w:
+            self.module.simplefilter("ignore", UserWarning)
+            self.module.filterwarnings("error", "match", UserWarning)
+            self.assertRaises(UserWarning, self.module.warn, "match")
+            self.assertRaises(UserWarning, self.module.warn, "match prefix")
+            self.module.warn("suffix match")
+            self.assertEqual(w, [])
+            self.module.warn("something completely different")
+            self.assertEqual(w, [])
+
     def test_mutate_filter_list(self):
         class X:
             def match(self, a):

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list