summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_warnings
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-05-26 09:39:41 (GMT)
committerMartin Panter <vadmium+py@gmail.com>2016-05-26 09:39:41 (GMT)
commitb6ae2ae47ca754aed313e84990f220777cf45905 (patch)
tree39a3d3e4e0bc7765bb1e50ea83b84316d31d4d7e /Lib/test/test_warnings
parentf157982b2c66be30d94a3f3ce0dfc2d9ebd3bd19 (diff)
parent43593a1892b73754e509713799a043ac756ae1e1 (diff)
downloadcpython-b6ae2ae47ca754aed313e84990f220777cf45905.zip
cpython-b6ae2ae47ca754aed313e84990f220777cf45905.tar.gz
cpython-b6ae2ae47ca754aed313e84990f220777cf45905.tar.bz2
Issue #18383: Merge warnings fix from 3.5
Diffstat (limited to 'Lib/test/test_warnings')
-rw-r--r--Lib/test/test_warnings/__init__.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/Lib/test/test_warnings/__init__.py b/Lib/test/test_warnings/__init__.py
index 42c7603..3c52b29 100644
--- a/Lib/test/test_warnings/__init__.py
+++ b/Lib/test/test_warnings/__init__.py
@@ -267,6 +267,53 @@ class FilterTests(BaseTest):
self.module.warn_explicit(UserWarning("b"), None, "f.py", 42)
self.assertEqual(str(w[-1].message), "b")
+ def test_filterwarnings_duplicate_filters(self):
+ with original_warnings.catch_warnings(module=self.module):
+ self.module.resetwarnings()
+ self.module.filterwarnings("error", category=UserWarning)
+ self.assertEqual(len(self.module.filters), 1)
+ self.module.filterwarnings("ignore", category=UserWarning)
+ self.module.filterwarnings("error", category=UserWarning)
+ self.assertEqual(
+ len(self.module.filters), 2,
+ "filterwarnings inserted duplicate filter"
+ )
+ self.assertEqual(
+ self.module.filters[0][0], "error",
+ "filterwarnings did not promote filter to "
+ "the beginning of list"
+ )
+
+ def test_simplefilter_duplicate_filters(self):
+ with original_warnings.catch_warnings(module=self.module):
+ self.module.resetwarnings()
+ self.module.simplefilter("error", category=UserWarning)
+ self.assertEqual(len(self.module.filters), 1)
+ self.module.simplefilter("ignore", category=UserWarning)
+ self.module.simplefilter("error", category=UserWarning)
+ self.assertEqual(
+ len(self.module.filters), 2,
+ "simplefilter inserted duplicate filter"
+ )
+ self.assertEqual(
+ self.module.filters[0][0], "error",
+ "simplefilter did not promote filter to the beginning of list"
+ )
+ def test_append_duplicate(self):
+ with original_warnings.catch_warnings(module=self.module,
+ record=True) as w:
+ self.module.resetwarnings()
+ self.module.simplefilter("ignore")
+ self.module.simplefilter("error", append=True)
+ self.module.simplefilter("ignore", append=True)
+ self.module.warn("test_append_duplicate", category=UserWarning)
+ self.assertEqual(len(self.module.filters), 2,
+ "simplefilter inserted duplicate filter"
+ )
+ self.assertEqual(len(w), 0,
+ "appended duplicate changed order of filters"
+ )
+
class CFilterTests(FilterTests, unittest.TestCase):
module = c_warnings