diff options
author | Brett Cannon <bcannon@gmail.com> | 2008-03-19 23:01:17 (GMT) |
---|---|---|
committer | Brett Cannon <bcannon@gmail.com> | 2008-03-19 23:01:17 (GMT) |
commit | 48581c5f08d368942840f99687fce7f10758fa7c (patch) | |
tree | 14cc33ca66d541c3b8bae9643cc29682e841e13e /Lib | |
parent | a0ce6b6b7123378f0a13bd3b9dfd9eb9eeea2eb2 (diff) | |
download | cpython-48581c5f08d368942840f99687fce7f10758fa7c.zip cpython-48581c5f08d368942840f99687fce7f10758fa7c.tar.gz cpython-48581c5f08d368942840f99687fce7f10758fa7c.tar.bz2 |
Make sure that the warnings filter is not reset or changed beyond the current
running test file.
Closes issue2407. Thanks Jerry Seutter.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/bsddb/test/test_1413192.py | 9 | ||||
-rw-r--r-- | Lib/test/test_hmac.py | 6 | ||||
-rw-r--r-- | Lib/test/test_unicode_file.py | 45 |
3 files changed, 24 insertions, 36 deletions
diff --git a/Lib/bsddb/test/test_1413192.py b/Lib/bsddb/test/test_1413192.py index e8e73a1..c5d0036 100644 --- a/Lib/bsddb/test/test_1413192.py +++ b/Lib/bsddb/test/test_1413192.py @@ -5,7 +5,9 @@ import shutil import tempfile +from test.test_support import catch_warning import warnings + try: # For Pythons w/distutils and add-on pybsddb from bsddb3 import db @@ -33,12 +35,11 @@ class Context: del self.the_txn -warnings.filterwarnings('ignore', 'DBTxn aborted in destructor') -try: +with catch_warning(): + warnings.filterwarnings('ignore', 'DBTxn aborted in destructor') context = Context() del context -finally: - warnings.resetwarnings() + # try not to leave a turd try: diff --git a/Lib/test/test_hmac.py b/Lib/test/test_hmac.py index 6c18715..c57ac7f 100644 --- a/Lib/test/test_hmac.py +++ b/Lib/test/test_hmac.py @@ -211,8 +211,8 @@ class TestVectorsTestCase(unittest.TestCase): def digest(self): return self._x.digest() - warnings.simplefilter('error', RuntimeWarning) - try: + with test_support.catch_warning(): + warnings.simplefilter('error', RuntimeWarning) try: hmac.HMAC('a', 'b', digestmod=MockCrazyHash) except RuntimeWarning: @@ -227,8 +227,6 @@ class TestVectorsTestCase(unittest.TestCase): pass else: self.fail('Expected warning about small block_size') - finally: - warnings.resetwarnings() diff --git a/Lib/test/test_unicode_file.py b/Lib/test/test_unicode_file.py index ee2960a..305f98b 100644 --- a/Lib/test/test_unicode_file.py +++ b/Lib/test/test_unicode_file.py @@ -75,7 +75,7 @@ class TestUnicodeFiles(unittest.TestCase): # Do as many "equivalancy' tests as we can - ie, check that although we # have different types for the filename, they refer to the same file. - def _do_equivilent(self, filename1, filename2): + def _do_equivalent(self, filename1, filename2): # Note we only check "filename1 against filename2" - we don't bother # checking "filename2 against 1", as we assume we are called again with # the args reversed. @@ -98,31 +98,20 @@ class TestUnicodeFiles(unittest.TestCase): os.rename(filename1 + ".new", filename2) self.failUnless(os.path.isfile(filename2)) - # Try using shutil on the filenames. - try: - filename1==filename2 - except UnicodeDecodeError: - # these filenames can't be compared - shutil.copy tries to do - # just that. This is really a bug in 'shutil' - if one of shutil's - # 2 params are Unicode and the other isn't, it should coerce the - # string to Unicode with the filesystem encoding before comparison. - pass - else: - # filenames can be compared. - shutil.copy(filename1, filename2 + ".new") - os.unlink(filename1 + ".new") # remove using equiv name. - # And a couple of moves, one using each name. - shutil.move(filename1, filename2 + ".new") - self.failUnless(not os.path.exists(filename2)) - shutil.move(filename1 + ".new", filename2) - self.failUnless(os.path.exists(filename1)) - # Note - due to the implementation of shutil.move, - # it tries a rename first. This only fails on Windows when on - # different file systems - and this test can't ensure that. - # So we test the shutil.copy2 function, which is the thing most - # likely to fail. - shutil.copy2(filename1, filename2 + ".new") - os.unlink(filename1 + ".new") + shutil.copy(filename1, filename2 + ".new") + os.unlink(filename1 + ".new") # remove using equiv name. + # And a couple of moves, one using each name. + shutil.move(filename1, filename2 + ".new") + self.failUnless(not os.path.exists(filename2)) + shutil.move(filename1 + ".new", filename2) + self.failUnless(os.path.exists(filename1)) + # Note - due to the implementation of shutil.move, + # it tries a rename first. This only fails on Windows when on + # different file systems - and this test can't ensure that. + # So we test the shutil.copy2 function, which is the thing most + # likely to fail. + shutil.copy2(filename1, filename2 + ".new") + os.unlink(filename1 + ".new") def _do_directory(self, make_name, chdir_name, encoded): cwd = os.getcwd() @@ -173,7 +162,7 @@ class TestUnicodeFiles(unittest.TestCase): f = file(filename1, "w") f.close() try: - self._do_equivilent(filename1, filename2) + self._do_equivalent(filename1, filename2) finally: os.unlink(filename1) @@ -190,7 +179,7 @@ class TestUnicodeFiles(unittest.TestCase): self._test_equivalent(TESTFN_UNICODE, TESTFN_ENCODED) def test_directories(self): - # For all 'equivilent' combinations: + # For all 'equivalent' combinations: # Make dir with encoded, chdir with unicode, checkdir with encoded # (or unicode/encoded/unicode, etc ext = ".dir" |