Make test_runpy close all references to test modules before trying to delete the underlying files
This commit is contained in:
parent
21d3a7cd2e
commit
5424ad8a2a
|
@ -113,13 +113,6 @@ class RunModuleTest(unittest.TestCase):
|
||||||
return pkg_dir, mod_fname, mod_name
|
return pkg_dir, mod_fname, mod_name
|
||||||
|
|
||||||
def _del_pkg(self, top, depth, mod_name):
|
def _del_pkg(self, top, depth, mod_name):
|
||||||
for root, dirs, files in os.walk(top, topdown=False):
|
|
||||||
for name in files:
|
|
||||||
os.remove(os.path.join(root, name))
|
|
||||||
for name in dirs:
|
|
||||||
os.rmdir(os.path.join(root, name))
|
|
||||||
os.rmdir(top)
|
|
||||||
if verbose: print " Removed package tree"
|
|
||||||
for i in range(depth+1): # Don't forget the module itself
|
for i in range(depth+1): # Don't forget the module itself
|
||||||
parts = mod_name.rsplit(".", i)
|
parts = mod_name.rsplit(".", i)
|
||||||
entry = parts[0]
|
entry = parts[0]
|
||||||
|
@ -127,6 +120,13 @@ class RunModuleTest(unittest.TestCase):
|
||||||
if verbose: print " Removed sys.modules entries"
|
if verbose: print " Removed sys.modules entries"
|
||||||
del sys.path[0]
|
del sys.path[0]
|
||||||
if verbose: print " Removed sys.path entry"
|
if verbose: print " Removed sys.path entry"
|
||||||
|
for root, dirs, files in os.walk(top, topdown=False):
|
||||||
|
for name in files:
|
||||||
|
os.remove(os.path.join(root, name))
|
||||||
|
for name in dirs:
|
||||||
|
os.rmdir(os.path.join(root, name))
|
||||||
|
os.rmdir(top)
|
||||||
|
if verbose: print " Removed package tree"
|
||||||
|
|
||||||
def _check_module(self, depth):
|
def _check_module(self, depth):
|
||||||
pkg_dir, mod_fname, mod_name = (
|
pkg_dir, mod_fname, mod_name = (
|
||||||
|
@ -134,13 +134,16 @@ class RunModuleTest(unittest.TestCase):
|
||||||
try:
|
try:
|
||||||
if verbose: print "Running from source:", mod_name
|
if verbose: print "Running from source:", mod_name
|
||||||
d1 = run_module(mod_name) # Read from source
|
d1 = run_module(mod_name) # Read from source
|
||||||
|
self.failUnless(d1["x"] == 1)
|
||||||
|
del d1 # Ensure __loader__ entry doesn't keep file open
|
||||||
__import__(mod_name)
|
__import__(mod_name)
|
||||||
os.remove(mod_fname)
|
os.remove(mod_fname)
|
||||||
if verbose: print "Running from compiled:", mod_name
|
if verbose: print "Running from compiled:", mod_name
|
||||||
d2 = run_module(mod_name) # Read from bytecode
|
d2 = run_module(mod_name) # Read from bytecode
|
||||||
|
self.failUnless(d2["x"] == 1)
|
||||||
|
del d2 # Ensure __loader__ entry doesn't keep file open
|
||||||
finally:
|
finally:
|
||||||
self._del_pkg(pkg_dir, depth, mod_name)
|
self._del_pkg(pkg_dir, depth, mod_name)
|
||||||
self.failUnless(d1["x"] == d2["x"] == 1)
|
|
||||||
if verbose: print "Module executed successfully"
|
if verbose: print "Module executed successfully"
|
||||||
|
|
||||||
def test_run_module(self):
|
def test_run_module(self):
|
||||||
|
|
Loading…
Reference in New Issue