Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Lib/test/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ def inner_raising_func():
pass
obj = None
obj = wr()
self.assertTrue(obj is None, "%s" % obj)
self.assertIsNone(obj)

# Qualified "except" without "as"
obj = MyObj()
Expand All @@ -548,7 +548,7 @@ def inner_raising_func():
pass
obj = None
obj = wr()
self.assertTrue(obj is None, "%s" % obj)
self.assertIsNone(obj)

# Bare "except"
obj = MyObj()
Expand All @@ -559,7 +559,7 @@ def inner_raising_func():
pass
obj = None
obj = wr()
self.assertTrue(obj is None, "%s" % obj)
self.assertIsNone(obj)

# "except" with premature block leave
obj = MyObj()
Expand All @@ -571,7 +571,7 @@ def inner_raising_func():
break
obj = None
obj = wr()
self.assertTrue(obj is None, "%s" % obj)
self.assertIsNone(obj)

# "except" block raising another exception
obj = MyObj()
Expand All @@ -592,7 +592,7 @@ def inner_raising_func():
# guarantee no ref cycles on CPython (don't gc_collect)
if check_impl_detail(cpython=False):
gc_collect()
self.assertTrue(obj is None, "%s" % obj)
self.assertIsNone(obj)

# Some complicated construct
obj = MyObj()
Expand All @@ -611,7 +611,7 @@ def inner_raising_func():
if check_impl_detail(cpython=False):
gc_collect()
obj = wr()
self.assertTrue(obj is None, "%s" % obj)
self.assertIsNone(obj)

# Inside an exception-silencing "with" block
class Context:
Expand All @@ -627,7 +627,7 @@ def __exit__ (self, exc_type, exc_value, exc_tb):
if check_impl_detail(cpython=False):
gc_collect()
obj = wr()
self.assertTrue(obj is None, "%s" % obj)
self.assertIsNone(obj)

def test_exception_target_in_nested_scope(self):
# issue 4617: This used to raise a SyntaxError
Expand Down Expand Up @@ -779,7 +779,7 @@ def raising_gen():
testfunc(g)
g = obj = None
obj = wr()
self.assertIs(obj, None)
self.assertIsNone(obj)

def test_generator_throw_cleanup_exc_state(self):
def do_throw(g):
Expand Down Expand Up @@ -904,7 +904,7 @@ def g():
except RecursionError:
return sys.exc_info()
e, v, tb = g()
self.assertTrue(isinstance(v, RecursionError), type(v))
self.assertIsInstance(v, RecursionError, type(v))
self.assertIn("maximum recursion depth exceeded", str(v))


Expand Down
12 changes: 6 additions & 6 deletions Lib/test/test_raise.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_reraise(self):
exc1 = e
raise
except IndexError as exc2:
self.assertTrue(exc1 is exc2)
self.assertIs(exc1, exc2)
else:
self.fail("No exception raised")

Expand Down Expand Up @@ -84,7 +84,7 @@ def test_raise_from_None(self):
except:
raise ValueError() from None
except ValueError as e:
self.assertTrue(isinstance(e.__context__, TypeError))
self.assertIsInstance(e.__context__, TypeError)
self.assertIsNone(e.__cause__)

def test_with_reraise1(self):
Expand Down Expand Up @@ -190,7 +190,7 @@ def test_instance_cause(self):
try:
raise IndexError from cause
except IndexError as e:
self.assertTrue(e.__cause__ is cause)
self.assertIs(e.__cause__, cause)
else:
self.fail("No exception raised")

Expand Down Expand Up @@ -296,7 +296,7 @@ def test_noraise_finally(self):
finally:
raise OSError
except OSError as e:
self.assertTrue(e.__context__ is None)
self.assertIsNone(e.__context__)
else:
self.fail("No exception raised")

Expand Down Expand Up @@ -333,7 +333,7 @@ def test_cycle_broken(self):
except ZeroDivisionError as e:
raise e
except ZeroDivisionError as e:
self.assertTrue(e.__context__ is None, e.__context__)
self.assertIsNone(e.__context__)

def test_reraise_cycle_broken(self):
# Non-trivial context cycles (through re-raising a previous exception)
Expand All @@ -347,7 +347,7 @@ def test_reraise_cycle_broken(self):
except ZeroDivisionError:
raise a
except NameError as e:
self.assertTrue(e.__context__.__context__ is None)
self.assertIsNone(e.__context__.__context__)

def test_3118(self):
# deleting the generator caused the __context__ to be cleared
Expand Down
40 changes: 20 additions & 20 deletions Lib/test/test_warnings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def test_filterwarnings(self):
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'
Expand All @@ -261,7 +261,7 @@ def test_filterwarnings(self):
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,
Expand Down Expand Up @@ -353,7 +353,7 @@ def test_message(self):
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):
Expand Down Expand Up @@ -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):
Expand All @@ -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__'))


Expand Down Expand Up @@ -884,20 +884,20 @@ def test_catch_warnings_restore(self):
# 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")
Expand All @@ -910,8 +910,8 @@ def test_catch_warnings_recording(self):
# 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
Expand All @@ -932,17 +932,17 @@ def test_catch_warnings_defaults(self):
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
Expand Down