mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 07:31:38 +00:00 
			
		
		
		
	Make sure that the warnings filter is not reset or changed beyond the current
running test file. Closes issue2407. Thanks Jerry Seutter.
This commit is contained in:
		
							parent
							
								
									a0ce6b6b71
								
							
						
					
					
						commit
						48581c5f08
					
				
					 3 changed files with 24 additions and 36 deletions
				
			
		| 
						 | 
					@ -5,7 +5,9 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import shutil
 | 
					import shutil
 | 
				
			||||||
import tempfile
 | 
					import tempfile
 | 
				
			||||||
 | 
					from test.test_support import catch_warning
 | 
				
			||||||
import warnings
 | 
					import warnings
 | 
				
			||||||
 | 
					
 | 
				
			||||||
try:
 | 
					try:
 | 
				
			||||||
    # For Pythons w/distutils and add-on pybsddb
 | 
					    # For Pythons w/distutils and add-on pybsddb
 | 
				
			||||||
    from bsddb3 import db
 | 
					    from bsddb3 import db
 | 
				
			||||||
| 
						 | 
					@ -33,12 +35,11 @@ def __init__(self):
 | 
				
			||||||
        del self.the_txn
 | 
					        del self.the_txn
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					with catch_warning():
 | 
				
			||||||
    warnings.filterwarnings('ignore', 'DBTxn aborted in destructor')
 | 
					    warnings.filterwarnings('ignore', 'DBTxn aborted in destructor')
 | 
				
			||||||
try:
 | 
					 | 
				
			||||||
    context = Context()
 | 
					    context = Context()
 | 
				
			||||||
    del context
 | 
					    del context
 | 
				
			||||||
finally:
 | 
					
 | 
				
			||||||
    warnings.resetwarnings()
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
# try not to leave a turd
 | 
					# try not to leave a turd
 | 
				
			||||||
try:
 | 
					try:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -211,8 +211,8 @@ def update(self, v):
 | 
				
			||||||
            def digest(self):
 | 
					            def digest(self):
 | 
				
			||||||
                return self._x.digest()
 | 
					                return self._x.digest()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        with test_support.catch_warning():
 | 
				
			||||||
            warnings.simplefilter('error', RuntimeWarning)
 | 
					            warnings.simplefilter('error', RuntimeWarning)
 | 
				
			||||||
        try:
 | 
					 | 
				
			||||||
            try:
 | 
					            try:
 | 
				
			||||||
                hmac.HMAC('a', 'b', digestmod=MockCrazyHash)
 | 
					                hmac.HMAC('a', 'b', digestmod=MockCrazyHash)
 | 
				
			||||||
            except RuntimeWarning:
 | 
					            except RuntimeWarning:
 | 
				
			||||||
| 
						 | 
					@ -227,8 +227,6 @@ def digest(self):
 | 
				
			||||||
                pass
 | 
					                pass
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                self.fail('Expected warning about small block_size')
 | 
					                self.fail('Expected warning about small block_size')
 | 
				
			||||||
        finally:
 | 
					 | 
				
			||||||
            warnings.resetwarnings()
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -75,7 +75,7 @@ def _do_single(self, filename):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Do as many "equivalancy' tests as we can - ie, check that although we
 | 
					    # 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.
 | 
					    # 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
 | 
					        # Note we only check "filename1 against filename2" - we don't bother
 | 
				
			||||||
        # checking "filename2 against 1", as we assume we are called again with
 | 
					        # checking "filename2 against 1", as we assume we are called again with
 | 
				
			||||||
        # the args reversed.
 | 
					        # the args reversed.
 | 
				
			||||||
| 
						 | 
					@ -98,17 +98,6 @@ def _do_copyish(self, filename1, filename2):
 | 
				
			||||||
        os.rename(filename1 + ".new", filename2)
 | 
					        os.rename(filename1 + ".new", filename2)
 | 
				
			||||||
        self.failUnless(os.path.isfile(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")
 | 
					        shutil.copy(filename1, filename2 + ".new")
 | 
				
			||||||
        os.unlink(filename1 + ".new") # remove using equiv name.
 | 
					        os.unlink(filename1 + ".new") # remove using equiv name.
 | 
				
			||||||
        # And a couple of moves, one using each name.
 | 
					        # And a couple of moves, one using each name.
 | 
				
			||||||
| 
						 | 
					@ -173,7 +162,7 @@ def _test_equivalent(self, filename1, filename2):
 | 
				
			||||||
        f = file(filename1, "w")
 | 
					        f = file(filename1, "w")
 | 
				
			||||||
        f.close()
 | 
					        f.close()
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            self._do_equivilent(filename1, filename2)
 | 
					            self._do_equivalent(filename1, filename2)
 | 
				
			||||||
        finally:
 | 
					        finally:
 | 
				
			||||||
            os.unlink(filename1)
 | 
					            os.unlink(filename1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -190,7 +179,7 @@ def test_equivalent_files(self):
 | 
				
			||||||
        self._test_equivalent(TESTFN_UNICODE, TESTFN_ENCODED)
 | 
					        self._test_equivalent(TESTFN_UNICODE, TESTFN_ENCODED)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_directories(self):
 | 
					    def test_directories(self):
 | 
				
			||||||
        # For all 'equivilent' combinations:
 | 
					        # For all 'equivalent' combinations:
 | 
				
			||||||
        #  Make dir with encoded, chdir with unicode, checkdir with encoded
 | 
					        #  Make dir with encoded, chdir with unicode, checkdir with encoded
 | 
				
			||||||
        #  (or unicode/encoded/unicode, etc
 | 
					        #  (or unicode/encoded/unicode, etc
 | 
				
			||||||
        ext = ".dir"
 | 
					        ext = ".dir"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue