diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2006-01-23 07:51:27 (GMT) |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2006-01-23 07:51:27 (GMT) |
commit | 0e17f8cd38a4013ccab83f308968353810fd970d (patch) | |
tree | 1b3abec8421afb68ce787a31543e02663659ae6a /Lib | |
parent | 9730bcb4a6d3d2dfc1717fa6e64cf4845d418637 (diff) | |
download | cpython-0e17f8cd38a4013ccab83f308968353810fd970d.zip cpython-0e17f8cd38a4013ccab83f308968353810fd970d.tar.gz cpython-0e17f8cd38a4013ccab83f308968353810fd970d.tar.bz2 |
Convenience function to remove a possibly non-existant file
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_support.py | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py index bec1a0f..cc71366 100644 --- a/Lib/test/test_support.py +++ b/Lib/test/test_support.py @@ -49,23 +49,24 @@ def unload(name): except KeyError: pass +def unlink(filename): + import os + try: + os.unlink(filename) + except OSError: + pass + def forget(modname): '''"Forget" a module was ever imported by removing it from sys.modules and deleting any .pyc and .pyo files.''' unload(modname) import os for dirname in sys.path: - try: - os.unlink(os.path.join(dirname, modname + os.extsep + 'pyc')) - except os.error: - pass + unlink(os.path.join(dirname, modname + os.extsep + 'pyc')) # Deleting the .pyo file cannot be within the 'try' for the .pyc since # the chance exists that there is no .pyc (and thus the 'try' statement # is exited) but there is a .pyo file. - try: - os.unlink(os.path.join(dirname, modname + os.extsep + 'pyo')) - except os.error: - pass + unlink(os.path.join(dirname, modname + os.extsep + 'pyo')) def is_resource_enabled(resource): """Test whether a resource is enabled. Known resources are set by @@ -175,14 +176,9 @@ except IOError: (TESTFN, TMP_TESTFN)) if fp is not None: fp.close() - try: - os.unlink(TESTFN) - except: - pass + unlink(TESTFN) del os, fp -from os import unlink - def findfile(file, here=__file__): """Try to find a file on sys.path and the working directory. If it is not found the argument passed to the function is returned (this does not |