blob: 99bacda8e9385f93c782b7e3d7e7eeeb59a09e3f [file] [log] [blame]
Fred Drake1790dd42000-07-24 06:55:00 +00001"""Supporting definitions for the Python regression test."""
Guido van Rossum3bead091992-01-27 17:00:37 +00002
Fred Drake1790dd42000-07-24 06:55:00 +00003
4class Error(Exception):
5 """Base class for regression test exceptions."""
6
7class TestFailed(Error):
8 """Test failed."""
9
10class TestSkipped(Error):
11 """Test skipped.
12
13 This can be raised to indicate that a test was deliberatly
14 skipped, but not because a feature wasn't available. For
15 example, if some resource can't be used, such as the network
16 appears to be unavailable, this should be raised instead of
17 TestFailed.
18
19 """
20
Guido van Rossum3bead091992-01-27 17:00:37 +000021
Guido van Rossum531661c1996-12-20 02:58:22 +000022verbose = 1 # Flag set to 0 by regrtest.py
Fred Drake1790dd42000-07-24 06:55:00 +000023use_large_resources = 1 # Flag set to 0 by regrtest.py
Guido van Rossum531661c1996-12-20 02:58:22 +000024
Guido van Rossum3bead091992-01-27 17:00:37 +000025def unload(name):
26 import sys
27 try:
28 del sys.modules[name]
29 except KeyError:
30 pass
31
32def forget(modname):
33 unload(modname)
34 import sys, os
35 for dirname in sys.path:
36 try:
37 os.unlink(os.path.join(dirname, modname + '.pyc'))
38 except os.error:
39 pass
40
Guido van Rossum35fb82a1993-01-26 13:04:43 +000041FUZZ = 1e-6
42
43def fcmp(x, y): # fuzzy comparison function
44 if type(x) == type(0.0) or type(y) == type(0.0):
45 try:
46 x, y = coerce(x, y)
47 fuzz = (abs(x) + abs(y)) * FUZZ
48 if abs(x-y) <= fuzz:
49 return 0
50 except:
51 pass
52 elif type(x) == type(y) and type(x) in (type(()), type([])):
53 for i in range(min(len(x), len(y))):
54 outcome = fcmp(x[i], y[i])
55 if outcome <> 0:
56 return outcome
57 return cmp(len(x), len(y))
58 return cmp(x, y)
59
Guido van Rossum3bead091992-01-27 17:00:37 +000060TESTFN = '@test' # Filename used for testing
61from os import unlink
Guido van Rossume26132c1998-04-23 20:13:30 +000062
63def findfile(file, here=__file__):
64 import os
Guido van Rossume614fb11998-06-09 19:20:12 +000065 if os.path.isabs(file):
Guido van Rossume26132c1998-04-23 20:13:30 +000066 return file
Guido van Rossume614fb11998-06-09 19:20:12 +000067 import sys
68 path = sys.path
Guido van Rossume26132c1998-04-23 20:13:30 +000069 path = [os.path.dirname(here)] + path
Guido van Rossume614fb11998-06-09 19:20:12 +000070 for dn in path:
71 fn = os.path.join(dn, file)
72 if os.path.exists(fn): return fn
73 return file