Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_support.py @ 4566:6403c94de50d legacy-trunk
Added safeguard against failure in __del__.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 27 Nov 1996 19:39:58 +0000 |
| parents | 675a02820d66 |
| children | a2fd80eed27f |
| rev | line source |
|---|---|
| 653 | 1 # Python test set -- supporting definitions. |
| 2 | |
| 3 TestFailed = 'test_support -- test failed' # Exception | |
| 4 | |
| 5 def unload(name): | |
| 6 import sys | |
| 7 try: | |
| 8 del sys.modules[name] | |
| 9 except KeyError: | |
| 10 pass | |
| 11 | |
| 12 def forget(modname): | |
| 13 unload(modname) | |
| 14 import sys, os | |
| 15 for dirname in sys.path: | |
| 16 try: | |
| 17 os.unlink(os.path.join(dirname, modname + '.pyc')) | |
| 18 except os.error: | |
| 19 pass | |
| 20 | |
|
1197
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
21 FUZZ = 1e-6 |
|
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
22 |
|
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
23 def fcmp(x, y): # fuzzy comparison function |
|
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
24 if type(x) == type(0.0) or type(y) == type(0.0): |
|
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
25 try: |
|
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
26 x, y = coerce(x, y) |
|
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
27 fuzz = (abs(x) + abs(y)) * FUZZ |
|
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
28 if abs(x-y) <= fuzz: |
|
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
29 return 0 |
|
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
30 except: |
|
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
31 pass |
|
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
32 elif type(x) == type(y) and type(x) in (type(()), type([])): |
|
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
33 for i in range(min(len(x), len(y))): |
|
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
34 outcome = fcmp(x[i], y[i]) |
|
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
35 if outcome <> 0: |
|
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
36 return outcome |
|
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
37 return cmp(len(x), len(y)) |
|
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
38 return cmp(x, y) |
|
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
39 |
| 653 | 40 TESTFN = '@test' # Filename used for testing |
| 41 from os import unlink |
