Merged revisions 62873,62887,62892-62896,62904 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r62873 | raymond.hettinger | 2008-05-08 12:18:13 -0500 (Thu, 08 May 2008) | 1 line
Issue 2778. Document the temporary frozenset swap in __contains__(), remove(), and discard().
........
r62887 | brett.cannon | 2008-05-08 14:50:51 -0500 (Thu, 08 May 2008) | 5 lines
Make test.test_support.catch_warning() take an argument specifying if any
triggered warnings should be captured. This allows the context manager to be
used to just prevent the internal state of the 'warnings' framework and thus
allow triggered warnings to be displayed.
........
r62892 | brett.cannon | 2008-05-08 15:20:24 -0500 (Thu, 08 May 2008) | 4 lines
Fix a bug introduced by the addition of the 'record' argument to
test.test_support.catch_warning() where showwarning() was not being set
properly.
........
r62893 | brett.cannon | 2008-05-08 15:20:54 -0500 (Thu, 08 May 2008) | 2 lines
Document the 'record' argument for test.test_support.catch_warning().
........
r62894 | brett.cannon | 2008-05-08 15:23:06 -0500 (Thu, 08 May 2008) | 4 lines
Fix sys.flags to properly expose bytes_warning.
Closes issue #2790.
........
r62895 | brett.cannon | 2008-05-08 15:23:54 -0500 (Thu, 08 May 2008) | 2 lines
Add a missing entry on the fix for issue #2790.
........
r62896 | brett.cannon | 2008-05-08 15:24:43 -0500 (Thu, 08 May 2008) | 2 lines
Add test.test_support.catch_warning()'s new argument.
........
r62904 | benjamin.peterson | 2008-05-08 17:09:54 -0500 (Thu, 08 May 2008) | 2 lines
Replace instances of os.path.walk with os.walk
........
diff --git a/Lib/test/test_repr.py b/Lib/test/test_repr.py
index af66e97..ac1a0a0 100644
--- a/Lib/test/test_repr.py
+++ b/Lib/test/test_repr.py
@@ -197,10 +197,6 @@
fp.write(text)
fp.close()
-def zap(actions, dirname, names):
- for name in names:
- actions.append(os.path.join(dirname, name))
-
class LongReprTest(unittest.TestCase):
def setUp(self):
longname = 'areallylongpackageandmodulenametotestreprtruncation'
@@ -219,7 +215,9 @@
def tearDown(self):
actions = []
- os.path.walk(self.pkgname, zap, actions)
+ for dirpath, dirnames, filenames in os.walk(self.pkgname):
+ for name in dirnames + filenames:
+ actions.append(os.path.join(dirpath, name))
actions.append(self.pkgname)
actions.sort()
actions.reverse()
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py
index 431b66b..92592eb 100644
--- a/Lib/test/test_support.py
+++ b/Lib/test/test_support.py
@@ -37,6 +37,19 @@
and unexpected skips.
"""
+def import_module(name, deprecated=False):
+ """Import the module to be tested, raising TestSkipped if it is not
+ available."""
+ with catch_warning(record=False):
+ if deprecated:
+ warnings.filterwarnings("ignore", ".+ module", DeprecationWarning)
+ try:
+ module = __import__(name, level=0)
+ except ImportError:
+ raise TestSkipped("No module named " + name)
+ else:
+ return module
+
verbose = 1 # Flag set to 0 by regrtest.py
use_resources = None # Flag set to [] by regrtest.py
max_memuse = 0 # Disable bigmem tests (they will still be run with
@@ -373,7 +386,7 @@
@contextlib.contextmanager
-def catch_warning(module=warnings):
+def catch_warning(module=warnings, record=True):
"""
Guard the warnings filter from being permanently changed and record the
data of the last warning that has been issued.
@@ -384,12 +397,13 @@
warnings.warn("foo")
assert str(w.message) == "foo"
"""
- warning_obj = WarningMessage()
original_filters = module.filters[:]
original_showwarning = module.showwarning
- module.showwarning = warning_obj._showwarning
+ if record:
+ warning_obj = WarningMessage()
+ module.showwarning = warning_obj._showwarning
try:
- yield warning_obj
+ yield warning_obj if record else None
finally:
module.showwarning = original_showwarning
module.filters = original_filters
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index 7961837..3a0abe1 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -324,7 +324,8 @@
self.failUnless(sys.flags)
attrs = ("debug", "division_warning",
"inspect", "interactive", "optimize", "dont_write_bytecode",
- "no_site", "ignore_environment", "tabcheck", "verbose")
+ "no_site", "ignore_environment", "tabcheck", "verbose",
+ "bytes_warning")
for attr in attrs:
self.assert_(hasattr(sys.flags, attr), attr)
self.assertEqual(type(getattr(sys.flags, attr)), int, attr)