]> granicus.if.org Git - python/commitdiff
Issue #27528: Document and test warning messages must match at beginning
authorMartin Panter <vadmium+py@gmail.com>
Tue, 19 Jul 2016 02:26:38 +0000 (02:26 +0000)
committerMartin Panter <vadmium+py@gmail.com>
Tue, 19 Jul 2016 02:26:38 +0000 (02:26 +0000)
Doc/library/warnings.rst
Lib/test/test_warnings.py

index 40a0770d4d7e2fadaa2615215208602314d1cfd6..3af76cee43278e1293efa070f29b991d4e57075f 100644 (file)
@@ -140,14 +140,15 @@ the disposition of the match.  Each entry is a tuple of the form (*action*,
   |               | 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.
index bc7e39847420f9fff709b4abf23766fd5a9d1ab7..607d9f9b7220c855f10a3419b30cb57498e5df3f 100644 (file)
@@ -205,6 +205,18 @@ class FilterTests(object):
             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, [])
+
 class CFilterTests(BaseTest, FilterTests):
     module = c_warnings