blob: 3839c79be9cbbbf03c1de071b327fb03c253482b [file] [log] [blame]
Guido van Rossum5c971671996-07-22 15:23:25 +00001# Python test set -- supporting definitions.
2
3TestFailed = 'test_support -- test failed' # Exception
4
Guido van Rossum228b8e81997-04-02 06:13:34 +00005verbose = 1 # Flag set to 0 by regrtest.py
6
Guido van Rossum5c971671996-07-22 15:23:25 +00007def unload(name):
8 import sys
9 try:
10 del sys.modules[name]
11 except KeyError:
12 pass
13
14def 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
23FUZZ = 1e-6
24
25def 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
42TESTFN = '@test' # Filename used for testing
43from os import unlink
Guido van Rossume03c0501998-08-12 02:38:11 +000044
45def 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