Added 'description' class attribute to every command class (to help the
[python/dscho.git] / Lib / test / test_support.py
blob3839c79be9cbbbf03c1de071b327fb03c253482b
1 # Python test set -- supporting definitions.
3 TestFailed = 'test_support -- test failed' # Exception
5 verbose = 1 # Flag set to 0 by regrtest.py
7 def unload(name):
8 import sys
9 try:
10 del sys.modules[name]
11 except KeyError:
12 pass
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
23 FUZZ = 1e-6
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)
42 TESTFN = '@test' # Filename used for testing
43 from os import unlink
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