Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f1cfb62

Browse files
committed
'forget' now also deletes any proper .pyo files.
Added some docstrings.
1 parent 015dd82 commit f1cfb62

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

Lib/test/test_support.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Supporting definitions for the Python regression test."""
1+
"""Supporting definitions for the Python regression tests."""
22

33
if __name__ != 'test.test_support':
44
raise ImportError, 'test_support must be imported from the test package'
@@ -50,18 +50,33 @@ def unload(name):
5050
pass
5151

5252
def forget(modname):
53+
'''"Forget" a module was ever imported by removing it from sys.modules and
54+
deleting any .pyc and .pyo files.'''
5355
unload(modname)
5456
import os
5557
for dirname in sys.path:
5658
try:
5759
os.unlink(os.path.join(dirname, modname + '.pyc'))
5860
except os.error:
5961
pass
62+
# Deleting the .pyo file cannot be within the 'try' for the .pyc since
63+
# the chance exists that there is no .pyc (and thus the 'try' statement
64+
# is exited) but there is a .pyo file.
65+
try:
66+
os.unlink(os.path.join(dirname, modname + '.pyo'))
67+
except os.error:
68+
pass
6069

6170
def is_resource_enabled(resource):
71+
"""Test whether a resource is enabled. Known resources are set by
72+
regrtest.py."""
6273
return use_resources is not None and resource in use_resources
6374

6475
def requires(resource, msg=None):
76+
"""Raise ResourceDenied if the specified resource is not available.
77+
78+
If the caller's module is __main__ then automatically return True. The
79+
possibility of False being returned occurs when regrtest.py is executing."""
6580
# see if the caller's module is __main__ - if so, treat as if
6681
# the resource was set
6782
if sys._getframe().f_back.f_globals.get("__name__") == "__main__":
@@ -141,6 +156,9 @@ def fcmp(x, y): # fuzzy comparison function
141156
from os import unlink
142157

143158
def findfile(file, here=__file__):
159+
"""Try to find a file on sys.path and the working directory. If it is not
160+
found the argument passed to the function is returned (this does not
161+
necessarily signal failure; could still be the legitimate path)."""
144162
import os
145163
if os.path.isabs(file):
146164
return file

0 commit comments

Comments
 (0)