Guido van Rossum | 5c97167 | 1996-07-22 15:23:25 +0000 | [diff] [blame] | 1 | # Python test set -- supporting definitions. |
| 2 | |
| 3 | TestFailed = 'test_support -- test failed' # Exception |
| 4 | |
Guido van Rossum | 228b8e8 | 1997-04-02 06:13:34 +0000 | [diff] [blame] | 5 | verbose = 1 # Flag set to 0 by regrtest.py |
| 6 | |
Guido van Rossum | 5c97167 | 1996-07-22 15:23:25 +0000 | [diff] [blame] | 7 | def unload(name): |
| 8 | import sys |
| 9 | try: |
| 10 | del sys.modules[name] |
| 11 | except KeyError: |
| 12 | pass |
| 13 | |
| 14 | def forget(modname): |
| 15 | unload(modname) |
| 16 | import sys, os |
| 17 | for dirname in sys.path: |
| 18 | try: |
| 19 | os.unlink(os.path.join(dirname, modname + '.pyc')) |
| 20 | except os.error: |
| 21 | pass |
| 22 | |
| 23 | FUZZ = 1e-6 |
| 24 | |
| 25 | def fcmp(x, y): # fuzzy comparison function |
| 26 | if type(x) == type(0.0) or type(y) == type(0.0): |
| 27 | try: |
| 28 | x, y = coerce(x, y) |
| 29 | fuzz = (abs(x) + abs(y)) * FUZZ |
| 30 | if abs(x-y) <= fuzz: |
| 31 | return 0 |
| 32 | except: |
| 33 | pass |
| 34 | elif type(x) == type(y) and type(x) in (type(()), type([])): |
| 35 | for i in range(min(len(x), len(y))): |
| 36 | outcome = fcmp(x[i], y[i]) |
| 37 | if outcome <> 0: |
| 38 | return outcome |
| 39 | return cmp(len(x), len(y)) |
| 40 | return cmp(x, y) |
| 41 | |
| 42 | TESTFN = '@test' # Filename used for testing |
| 43 | from os import unlink |
Guido van Rossum | e03c050 | 1998-08-12 02:38:11 +0000 | [diff] [blame] | 44 | |
| 45 | def findfile(file, here=__file__): |
| 46 | import os |
| 47 | if os.path.isabs(file): |
| 48 | return file |
| 49 | import sys |
| 50 | path = sys.path |
| 51 | path = [os.path.dirname(here)] + path |
| 52 | for dn in path: |
| 53 | fn = os.path.join(dn, file) |
| 54 | if os.path.exists(fn): return fn |
| 55 | return file |