|
1 | | -"""Supporting definitions for the Python regression test.""" |
| 1 | +"""Supporting definitions for the Python regression tests.""" |
2 | 2 |
|
3 | 3 | if __name__ != 'test.test_support': |
4 | 4 | raise ImportError, 'test_support must be imported from the test package' |
@@ -50,18 +50,33 @@ def unload(name): |
50 | 50 | pass |
51 | 51 |
|
52 | 52 | def forget(modname): |
| 53 | + '''"Forget" a module was ever imported by removing it from sys.modules and |
| 54 | + deleting any .pyc and .pyo files.''' |
53 | 55 | unload(modname) |
54 | 56 | import os |
55 | 57 | for dirname in sys.path: |
56 | 58 | try: |
57 | 59 | os.unlink(os.path.join(dirname, modname + '.pyc')) |
58 | 60 | except os.error: |
59 | 61 | 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 |
60 | 69 |
|
61 | 70 | def is_resource_enabled(resource): |
| 71 | + """Test whether a resource is enabled. Known resources are set by |
| 72 | + regrtest.py.""" |
62 | 73 | return use_resources is not None and resource in use_resources |
63 | 74 |
|
64 | 75 | 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.""" |
65 | 80 | # see if the caller's module is __main__ - if so, treat as if |
66 | 81 | # the resource was set |
67 | 82 | if sys._getframe().f_back.f_globals.get("__name__") == "__main__": |
@@ -141,6 +156,9 @@ def fcmp(x, y): # fuzzy comparison function |
141 | 156 | from os import unlink |
142 | 157 |
|
143 | 158 | 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).""" |
144 | 162 | import os |
145 | 163 | if os.path.isabs(file): |
146 | 164 | return file |
|
0 commit comments