mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon)
This commit is contained in:
parent
9fa5a2828c
commit
d2e0938362
11 changed files with 254 additions and 93 deletions
|
@ -5,7 +5,7 @@ import shutil
|
|||
import sys
|
||||
import py_compile
|
||||
import warnings
|
||||
from test.test_support import unlink, TESTFN, unload, run_unittest
|
||||
from test.test_support import unlink, TESTFN, unload, run_unittest, check_warnings
|
||||
|
||||
|
||||
def remove_files(name):
|
||||
|
@ -279,17 +279,17 @@ class RelativeImport(unittest.TestCase):
|
|||
check_relative()
|
||||
# Check relative fails with only __package__ wrong
|
||||
ns = dict(__package__='foo', __name__='test.notarealmodule')
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
with check_warnings() as w:
|
||||
check_absolute()
|
||||
self.assert_('foo' in str(w[-1].message))
|
||||
self.assertEqual(w[-1].category, RuntimeWarning)
|
||||
self.assert_('foo' in str(w.message))
|
||||
self.assertEqual(w.category, RuntimeWarning)
|
||||
self.assertRaises(SystemError, check_relative)
|
||||
# Check relative fails with __package__ and __name__ wrong
|
||||
ns = dict(__package__='foo', __name__='notarealpkg.notarealmodule')
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
with check_warnings() as w:
|
||||
check_absolute()
|
||||
self.assert_('foo' in str(w[-1].message))
|
||||
self.assertEqual(w[-1].category, RuntimeWarning)
|
||||
self.assert_('foo' in str(w.message))
|
||||
self.assertEqual(w.category, RuntimeWarning)
|
||||
self.assertRaises(SystemError, check_relative)
|
||||
# Check both fail with package set to a non-string
|
||||
ns = dict(__package__=object())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue