summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_warnings
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-03-30 15:05:08 (GMT)
committerGitHub <noreply@github.com>2017-03-30 15:05:08 (GMT)
commitf15c4d374a07c576c0e8349b16604f6dbad0b953 (patch)
tree21bb1b432ad3485296391e4c7ef13e8b0fabca86 /Lib/test/test_warnings
parent16f852345bcdec1bbb15e5363fad6b33bf960912 (diff)
downloadcpython-f15c4d374a07c576c0e8349b16604f6dbad0b953.zip
cpython-f15c4d374a07c576c0e8349b16604f6dbad0b953.tar.gz
cpython-f15c4d374a07c576c0e8349b16604f6dbad0b953.tar.bz2
bpo-20548: Use specific asserts in warnings and exceptions tests (#788)
Diffstat (limited to 'Lib/test/test_warnings')
-rw-r--r--Lib/test/test_warnings/__init__.py40
1 files changed, 20 insertions, 20 deletions
diff --git a/Lib/test/test_warnings/__init__.py b/Lib/test/test_warnings/__init__.py
index 0cddf4a..8fc5d3c 100644
--- a/Lib/test/test_warnings/__init__.py
+++ b/Lib/test/test_warnings/__init__.py
@@ -248,7 +248,7 @@ class FilterTests(BaseTest):
text = 'handle normally'
self.module.warn(text)
self.assertEqual(str(w[-1].message), text)
- self.assertTrue(w[-1].category is UserWarning)
+ self.assertIs(w[-1].category, UserWarning)
self.module.filterwarnings("ignore", "", Warning, "", 0)
text = 'filtered out'
@@ -261,7 +261,7 @@ class FilterTests(BaseTest):
text = 'nonmatching text'
self.module.warn(text)
self.assertEqual(str(w[-1].message), text)
- self.assertTrue(w[-1].category is UserWarning)
+ self.assertIs(w[-1].category, UserWarning)
def test_message_matching(self):
with original_warnings.catch_warnings(record=True,
@@ -353,7 +353,7 @@ class WarnTests(BaseTest):
text = 'multi %d' %i # Different text on each call.
self.module.warn(text)
self.assertEqual(str(w[-1].message), text)
- self.assertTrue(w[-1].category is UserWarning)
+ self.assertIs(w[-1].category, UserWarning)
# Issue 3639
def test_warn_nonstandard_types(self):
@@ -575,7 +575,7 @@ class CWarnTests(WarnTests, unittest.TestCase):
# As an early adopter, we sanity check the
# test.support.import_fresh_module utility function
def test_accelerated(self):
- self.assertFalse(original_warnings is self.module)
+ self.assertIsNot(original_warnings, self.module)
self.assertFalse(hasattr(self.module.warn, '__code__'))
class PyWarnTests(WarnTests, unittest.TestCase):
@@ -584,7 +584,7 @@ class PyWarnTests(WarnTests, unittest.TestCase):
# As an early adopter, we sanity check the
# test.support.import_fresh_module utility function
def test_pure_python(self):
- self.assertFalse(original_warnings is self.module)
+ self.assertIsNot(original_warnings, self.module)
self.assertTrue(hasattr(self.module.warn, '__code__'))
@@ -884,20 +884,20 @@ class CatchWarningTests(BaseTest):
# Ensure both showwarning and filters are restored when recording
with wmod.catch_warnings(module=wmod, record=True):
wmod.filters = wmod.showwarning = object()
- self.assertTrue(wmod.filters is orig_filters)
- self.assertTrue(wmod.showwarning is orig_showwarning)
+ self.assertIs(wmod.filters, orig_filters)
+ self.assertIs(wmod.showwarning, orig_showwarning)
# Same test, but with recording disabled
with wmod.catch_warnings(module=wmod, record=False):
wmod.filters = wmod.showwarning = object()
- self.assertTrue(wmod.filters is orig_filters)
- self.assertTrue(wmod.showwarning is orig_showwarning)
+ self.assertIs(wmod.filters, orig_filters)
+ self.assertIs(wmod.showwarning, orig_showwarning)
def test_catch_warnings_recording(self):
wmod = self.module
# Ensure warnings are recorded when requested
with wmod.catch_warnings(module=wmod, record=True) as w:
self.assertEqual(w, [])
- self.assertTrue(type(w) is list)
+ self.assertIs(type(w), list)
wmod.simplefilter("always")
wmod.warn("foo")
self.assertEqual(str(w[-1].message), "foo")
@@ -910,8 +910,8 @@ class CatchWarningTests(BaseTest):
# Ensure warnings are not recorded when not requested
orig_showwarning = wmod.showwarning
with wmod.catch_warnings(module=wmod, record=False) as w:
- self.assertTrue(w is None)
- self.assertTrue(wmod.showwarning is orig_showwarning)
+ self.assertIsNone(w)
+ self.assertIs(wmod.showwarning, orig_showwarning)
def test_catch_warnings_reentry_guard(self):
wmod = self.module
@@ -932,17 +932,17 @@ class CatchWarningTests(BaseTest):
orig_showwarning = wmod.showwarning
# Ensure default behaviour is not to record warnings
with wmod.catch_warnings(module=wmod) as w:
- self.assertTrue(w is None)
- self.assertTrue(wmod.showwarning is orig_showwarning)
- self.assertTrue(wmod.filters is not orig_filters)
- self.assertTrue(wmod.filters is orig_filters)
+ self.assertIsNone(w)
+ self.assertIs(wmod.showwarning, orig_showwarning)
+ self.assertIsNot(wmod.filters, orig_filters)
+ self.assertIs(wmod.filters, orig_filters)
if wmod is sys.modules['warnings']:
# Ensure the default module is this one
with wmod.catch_warnings() as w:
- self.assertTrue(w is None)
- self.assertTrue(wmod.showwarning is orig_showwarning)
- self.assertTrue(wmod.filters is not orig_filters)
- self.assertTrue(wmod.filters is orig_filters)
+ self.assertIsNone(w)
+ self.assertIs(wmod.showwarning, orig_showwarning)
+ self.assertIsNot(wmod.filters, orig_filters)
+ self.assertIs(wmod.filters, orig_filters)
def test_record_override_showwarning_before(self):
# Issue #28835: If warnings.showwarning() was overriden, make sure