Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_support.py @ 27998:e27f58a50737 legacy-trunk
SF bug #690377: Dud footnote reference in distutils docs
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Fri, 21 Feb 2003 02:47:09 +0000 |
| parents | 974f196abb87 |
| children | 3f90d21debe9 |
| rev | line source |
|---|---|
|
13682
7de18f04f85a
Restore TestSkipped exception; appears to have disappeared in last checkin.
Fred Drake <fdrake@acm.org>
parents:
13647
diff
changeset
|
1 """Supporting definitions for the Python regression test.""" |
|
7de18f04f85a
Restore TestSkipped exception; appears to have disappeared in last checkin.
Fred Drake <fdrake@acm.org>
parents:
13647
diff
changeset
|
2 |
|
24442
226ba34bd998
Complete the absolute import patch for the test suite. All relative
Barry Warsaw <barry@python.org>
parents:
21595
diff
changeset
|
3 if __name__ != 'test.test_support': |
|
226ba34bd998
Complete the absolute import patch for the test suite. All relative
Barry Warsaw <barry@python.org>
parents:
21595
diff
changeset
|
4 raise ImportError, 'test_support must be imported from the test package' |
|
226ba34bd998
Complete the absolute import patch for the test suite. All relative
Barry Warsaw <barry@python.org>
parents:
21595
diff
changeset
|
5 |
|
17109
7eb8b240dd6c
Just import sys at the top instead of inside lots of functions.
Fred Drake <fdrake@acm.org>
parents:
17036
diff
changeset
|
6 import sys |
|
7eb8b240dd6c
Just import sys at the top instead of inside lots of functions.
Fred Drake <fdrake@acm.org>
parents:
17036
diff
changeset
|
7 |
|
13682
7de18f04f85a
Restore TestSkipped exception; appears to have disappeared in last checkin.
Fred Drake <fdrake@acm.org>
parents:
13647
diff
changeset
|
8 class Error(Exception): |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
9 """Base class for regression test exceptions.""" |
|
13682
7de18f04f85a
Restore TestSkipped exception; appears to have disappeared in last checkin.
Fred Drake <fdrake@acm.org>
parents:
13647
diff
changeset
|
10 |
|
7de18f04f85a
Restore TestSkipped exception; appears to have disappeared in last checkin.
Fred Drake <fdrake@acm.org>
parents:
13647
diff
changeset
|
11 class TestFailed(Error): |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
12 """Test failed.""" |
| 653 | 13 |
|
13682
7de18f04f85a
Restore TestSkipped exception; appears to have disappeared in last checkin.
Fred Drake <fdrake@acm.org>
parents:
13647
diff
changeset
|
14 class TestSkipped(Error): |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
15 """Test skipped. |
|
13682
7de18f04f85a
Restore TestSkipped exception; appears to have disappeared in last checkin.
Fred Drake <fdrake@acm.org>
parents:
13647
diff
changeset
|
16 |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
17 This can be raised to indicate that a test was deliberatly |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
18 skipped, but not because a feature wasn't available. For |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
19 example, if some resource can't be used, such as the network |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
20 appears to be unavailable, this should be raised instead of |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
21 TestFailed. |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
22 """ |
|
13682
7de18f04f85a
Restore TestSkipped exception; appears to have disappeared in last checkin.
Fred Drake <fdrake@acm.org>
parents:
13647
diff
changeset
|
23 |
|
27636
974f196abb87
test_support.requires(): Instead of raising TestSkipped, raise a new
Fred Drake <fdrake@acm.org>
parents:
26527
diff
changeset
|
24 class ResourceDenied(TestSkipped): |
|
974f196abb87
test_support.requires(): Instead of raising TestSkipped, raise a new
Fred Drake <fdrake@acm.org>
parents:
26527
diff
changeset
|
25 """Test skipped because it requested a disallowed resource. |
|
974f196abb87
test_support.requires(): Instead of raising TestSkipped, raise a new
Fred Drake <fdrake@acm.org>
parents:
26527
diff
changeset
|
26 |
|
974f196abb87
test_support.requires(): Instead of raising TestSkipped, raise a new
Fred Drake <fdrake@acm.org>
parents:
26527
diff
changeset
|
27 This is raised when a test calls requires() for a resource that |
|
974f196abb87
test_support.requires(): Instead of raising TestSkipped, raise a new
Fred Drake <fdrake@acm.org>
parents:
26527
diff
changeset
|
28 has not be enabled. It is used to distinguish between expected |
|
974f196abb87
test_support.requires(): Instead of raising TestSkipped, raise a new
Fred Drake <fdrake@acm.org>
parents:
26527
diff
changeset
|
29 and unexpected skips. |
|
974f196abb87
test_support.requires(): Instead of raising TestSkipped, raise a new
Fred Drake <fdrake@acm.org>
parents:
26527
diff
changeset
|
30 """ |
|
974f196abb87
test_support.requires(): Instead of raising TestSkipped, raise a new
Fred Drake <fdrake@acm.org>
parents:
26527
diff
changeset
|
31 |
|
19416
a6ce2d16d739
use_large_resources => use_resources
Barry Warsaw <barry@python.org>
parents:
19343
diff
changeset
|
32 verbose = 1 # Flag set to 0 by regrtest.py |
|
19768
d4f53b1fb424
Two small changes to the resource usage option:
Guido van Rossum <guido@python.org>
parents:
19416
diff
changeset
|
33 use_resources = None # Flag set to [] by regrtest.py |
|
4791
a2fd80eed27f
Add verbose flag for regression test to clear.
Guido van Rossum <guido@python.org>
parents:
1197
diff
changeset
|
34 |
|
20091
40d4d1cd6c84
Guido points out that sys.__stdout__ is a bit bucket under IDLE. So keep
Tim Peters <tim.peters@gmail.com>
parents:
20088
diff
changeset
|
35 # _original_stdout is meant to hold stdout at the time regrtest began. |
|
40d4d1cd6c84
Guido points out that sys.__stdout__ is a bit bucket under IDLE. So keep
Tim Peters <tim.peters@gmail.com>
parents:
20088
diff
changeset
|
36 # This may be "the real" stdout, or IDLE's emulation of stdout, or whatever. |
|
40d4d1cd6c84
Guido points out that sys.__stdout__ is a bit bucket under IDLE. So keep
Tim Peters <tim.peters@gmail.com>
parents:
20088
diff
changeset
|
37 # The point is to have some flavor of stdout the user can actually see. |
|
40d4d1cd6c84
Guido points out that sys.__stdout__ is a bit bucket under IDLE. So keep
Tim Peters <tim.peters@gmail.com>
parents:
20088
diff
changeset
|
38 _original_stdout = None |
|
40d4d1cd6c84
Guido points out that sys.__stdout__ is a bit bucket under IDLE. So keep
Tim Peters <tim.peters@gmail.com>
parents:
20088
diff
changeset
|
39 def record_original_stdout(stdout): |
|
40d4d1cd6c84
Guido points out that sys.__stdout__ is a bit bucket under IDLE. So keep
Tim Peters <tim.peters@gmail.com>
parents:
20088
diff
changeset
|
40 global _original_stdout |
|
40d4d1cd6c84
Guido points out that sys.__stdout__ is a bit bucket under IDLE. So keep
Tim Peters <tim.peters@gmail.com>
parents:
20088
diff
changeset
|
41 _original_stdout = stdout |
|
40d4d1cd6c84
Guido points out that sys.__stdout__ is a bit bucket under IDLE. So keep
Tim Peters <tim.peters@gmail.com>
parents:
20088
diff
changeset
|
42 |
|
40d4d1cd6c84
Guido points out that sys.__stdout__ is a bit bucket under IDLE. So keep
Tim Peters <tim.peters@gmail.com>
parents:
20088
diff
changeset
|
43 def get_original_stdout(): |
|
40d4d1cd6c84
Guido points out that sys.__stdout__ is a bit bucket under IDLE. So keep
Tim Peters <tim.peters@gmail.com>
parents:
20088
diff
changeset
|
44 return _original_stdout or sys.stdout |
|
40d4d1cd6c84
Guido points out that sys.__stdout__ is a bit bucket under IDLE. So keep
Tim Peters <tim.peters@gmail.com>
parents:
20088
diff
changeset
|
45 |
| 653 | 46 def unload(name): |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
47 try: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
48 del sys.modules[name] |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
49 except KeyError: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
50 pass |
| 653 | 51 |
| 52 def forget(modname): | |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
53 unload(modname) |
|
17109
7eb8b240dd6c
Just import sys at the top instead of inside lots of functions.
Fred Drake <fdrake@acm.org>
parents:
17036
diff
changeset
|
54 import os |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
55 for dirname in sys.path: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
56 try: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
57 os.unlink(os.path.join(dirname, modname + '.pyc')) |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
58 except os.error: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
59 pass |
| 653 | 60 |
|
26527
18dcf80e6f8d
Rearrange test_socket_ssl so that a skip is expected iff the network
Tim Peters <tim.peters@gmail.com>
parents:
26139
diff
changeset
|
61 def is_resource_enabled(resource): |
|
18dcf80e6f8d
Rearrange test_socket_ssl so that a skip is expected iff the network
Tim Peters <tim.peters@gmail.com>
parents:
26139
diff
changeset
|
62 return use_resources is not None and resource in use_resources |
|
18dcf80e6f8d
Rearrange test_socket_ssl so that a skip is expected iff the network
Tim Peters <tim.peters@gmail.com>
parents:
26139
diff
changeset
|
63 |
|
19416
a6ce2d16d739
use_large_resources => use_resources
Barry Warsaw <barry@python.org>
parents:
19343
diff
changeset
|
64 def requires(resource, msg=None): |
|
26527
18dcf80e6f8d
Rearrange test_socket_ssl so that a skip is expected iff the network
Tim Peters <tim.peters@gmail.com>
parents:
26139
diff
changeset
|
65 if not is_resource_enabled(resource): |
|
19416
a6ce2d16d739
use_large_resources => use_resources
Barry Warsaw <barry@python.org>
parents:
19343
diff
changeset
|
66 if msg is None: |
|
a6ce2d16d739
use_large_resources => use_resources
Barry Warsaw <barry@python.org>
parents:
19343
diff
changeset
|
67 msg = "Use of the `%s' resource not enabled" % resource |
|
27636
974f196abb87
test_support.requires(): Instead of raising TestSkipped, raise a new
Fred Drake <fdrake@acm.org>
parents:
26527
diff
changeset
|
68 raise ResourceDenied(msg) |
|
19416
a6ce2d16d739
use_large_resources => use_resources
Barry Warsaw <barry@python.org>
parents:
19343
diff
changeset
|
69 |
|
1197
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
70 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
|
71 |
|
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
72 def fcmp(x, y): # fuzzy comparison function |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
73 if type(x) == type(0.0) or type(y) == type(0.0): |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
74 try: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
75 x, y = coerce(x, y) |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
76 fuzz = (abs(x) + abs(y)) * FUZZ |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
77 if abs(x-y) <= fuzz: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
78 return 0 |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
79 except: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
80 pass |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
81 elif type(x) == type(y) and type(x) in (type(()), type([])): |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
82 for i in range(min(len(x), len(y))): |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
83 outcome = fcmp(x[i], y[i]) |
|
15540
9d43129c8c55
Update the code to better reflect recommended style:
Fred Drake <fdrake@acm.org>
parents:
15305
diff
changeset
|
84 if outcome != 0: |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
85 return outcome |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
86 return cmp(len(x), len(y)) |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
87 return cmp(x, y) |
|
1197
675a02820d66
* os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents:
653
diff
changeset
|
88 |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18635
diff
changeset
|
89 try: |
|
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18635
diff
changeset
|
90 unicode |
|
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18635
diff
changeset
|
91 have_unicode = 1 |
|
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18635
diff
changeset
|
92 except NameError: |
|
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18635
diff
changeset
|
93 have_unicode = 0 |
|
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18635
diff
changeset
|
94 |
|
25982
e1bf4604c0a5
Patch #631972: Adds an is_jython flag.
Finn Bock <bckfnn@worldonline.dk>
parents:
24442
diff
changeset
|
95 is_jython = sys.platform.startswith('java') |
|
e1bf4604c0a5
Patch #631972: Adds an is_jython flag.
Finn Bock <bckfnn@worldonline.dk>
parents:
24442
diff
changeset
|
96 |
|
17036
ad741745cb6c
Oops. A RISCOS patch I forgot to check in.
Guido van Rossum <guido@python.org>
parents:
16723
diff
changeset
|
97 import os |
|
17213
4d6ee7f2bee6
In Jython, `@' is not allowed in module names. Extend the TESTFN test
Barry Warsaw <barry@python.org>
parents:
17171
diff
changeset
|
98 # Filename used for testing |
|
4d6ee7f2bee6
In Jython, `@' is not allowed in module names. Extend the TESTFN test
Barry Warsaw <barry@python.org>
parents:
17171
diff
changeset
|
99 if os.name == 'java': |
|
4d6ee7f2bee6
In Jython, `@' is not allowed in module names. Extend the TESTFN test
Barry Warsaw <barry@python.org>
parents:
17171
diff
changeset
|
100 # Jython disallows @ in module names |
|
4d6ee7f2bee6
In Jython, `@' is not allowed in module names. Extend the TESTFN test
Barry Warsaw <barry@python.org>
parents:
17171
diff
changeset
|
101 TESTFN = '$test' |
|
4d6ee7f2bee6
In Jython, `@' is not allowed in module names. Extend the TESTFN test
Barry Warsaw <barry@python.org>
parents:
17171
diff
changeset
|
102 elif os.name != 'riscos': |
|
4d6ee7f2bee6
In Jython, `@' is not allowed in module names. Extend the TESTFN test
Barry Warsaw <barry@python.org>
parents:
17171
diff
changeset
|
103 TESTFN = '@test' |
|
17817
f7c385226f65
Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents:
17815
diff
changeset
|
104 # Unicode name only used if TEST_FN_ENCODING exists for the platform. |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18635
diff
changeset
|
105 if have_unicode: |
|
26139
144d9d48b96c
Don't try to convert the test filename to Unicode with -U.
Martin v. Löwis <martin@v.loewis.de>
parents:
26128
diff
changeset
|
106 if isinstance('', unicode): |
|
144d9d48b96c
Don't try to convert the test filename to Unicode with -U.
Martin v. Löwis <martin@v.loewis.de>
parents:
26128
diff
changeset
|
107 # python -U |
|
144d9d48b96c
Don't try to convert the test filename to Unicode with -U.
Martin v. Löwis <martin@v.loewis.de>
parents:
26128
diff
changeset
|
108 # XXX perhaps unicode() should accept Unicode strings? |
|
144d9d48b96c
Don't try to convert the test filename to Unicode with -U.
Martin v. Löwis <martin@v.loewis.de>
parents:
26128
diff
changeset
|
109 TESTFN_UNICODE="@test-\xe0\xf2" |
|
144d9d48b96c
Don't try to convert the test filename to Unicode with -U.
Martin v. Löwis <martin@v.loewis.de>
parents:
26128
diff
changeset
|
110 else: |
|
144d9d48b96c
Don't try to convert the test filename to Unicode with -U.
Martin v. Löwis <martin@v.loewis.de>
parents:
26128
diff
changeset
|
111 TESTFN_UNICODE=unicode("@test-\xe0\xf2", "latin-1") # 2 latin characters. |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18635
diff
changeset
|
112 if os.name=="nt": |
|
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18635
diff
changeset
|
113 TESTFN_ENCODING="mbcs" |
|
17036
ad741745cb6c
Oops. A RISCOS patch I forgot to check in.
Guido van Rossum <guido@python.org>
parents:
16723
diff
changeset
|
114 else: |
|
17213
4d6ee7f2bee6
In Jython, `@' is not allowed in module names. Extend the TESTFN test
Barry Warsaw <barry@python.org>
parents:
17171
diff
changeset
|
115 TESTFN = 'test' |
|
26000
83d21ea9457d
Fix SF # 631066, running regrtest in user mode fails
Neal Norwitz <nnorwitz@gmail.com>
parents:
25982
diff
changeset
|
116 |
|
83d21ea9457d
Fix SF # 631066, running regrtest in user mode fails
Neal Norwitz <nnorwitz@gmail.com>
parents:
25982
diff
changeset
|
117 # Make sure we can write to TESTFN, try in /tmp if we can't |
|
83d21ea9457d
Fix SF # 631066, running regrtest in user mode fails
Neal Norwitz <nnorwitz@gmail.com>
parents:
25982
diff
changeset
|
118 fp = None |
|
83d21ea9457d
Fix SF # 631066, running regrtest in user mode fails
Neal Norwitz <nnorwitz@gmail.com>
parents:
25982
diff
changeset
|
119 try: |
|
83d21ea9457d
Fix SF # 631066, running regrtest in user mode fails
Neal Norwitz <nnorwitz@gmail.com>
parents:
25982
diff
changeset
|
120 fp = open(TESTFN, 'w+') |
|
83d21ea9457d
Fix SF # 631066, running regrtest in user mode fails
Neal Norwitz <nnorwitz@gmail.com>
parents:
25982
diff
changeset
|
121 except IOError: |
|
83d21ea9457d
Fix SF # 631066, running regrtest in user mode fails
Neal Norwitz <nnorwitz@gmail.com>
parents:
25982
diff
changeset
|
122 TMP_TESTFN = os.path.join('/tmp', TESTFN) |
|
83d21ea9457d
Fix SF # 631066, running regrtest in user mode fails
Neal Norwitz <nnorwitz@gmail.com>
parents:
25982
diff
changeset
|
123 try: |
|
83d21ea9457d
Fix SF # 631066, running regrtest in user mode fails
Neal Norwitz <nnorwitz@gmail.com>
parents:
25982
diff
changeset
|
124 fp = open(TMP_TESTFN, 'w+') |
|
83d21ea9457d
Fix SF # 631066, running regrtest in user mode fails
Neal Norwitz <nnorwitz@gmail.com>
parents:
25982
diff
changeset
|
125 TESTFN = TMP_TESTFN |
|
83d21ea9457d
Fix SF # 631066, running regrtest in user mode fails
Neal Norwitz <nnorwitz@gmail.com>
parents:
25982
diff
changeset
|
126 del TMP_TESTFN |
|
83d21ea9457d
Fix SF # 631066, running regrtest in user mode fails
Neal Norwitz <nnorwitz@gmail.com>
parents:
25982
diff
changeset
|
127 except IOError: |
|
26128
23ef7c163a12
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
26000
diff
changeset
|
128 print ('WARNING: tests will fail, unable to write to: %s or %s' % |
|
26000
83d21ea9457d
Fix SF # 631066, running regrtest in user mode fails
Neal Norwitz <nnorwitz@gmail.com>
parents:
25982
diff
changeset
|
129 (TESTFN, TMP_TESTFN)) |
|
83d21ea9457d
Fix SF # 631066, running regrtest in user mode fails
Neal Norwitz <nnorwitz@gmail.com>
parents:
25982
diff
changeset
|
130 if fp is not None: |
|
83d21ea9457d
Fix SF # 631066, running regrtest in user mode fails
Neal Norwitz <nnorwitz@gmail.com>
parents:
25982
diff
changeset
|
131 fp.close() |
|
83d21ea9457d
Fix SF # 631066, running regrtest in user mode fails
Neal Norwitz <nnorwitz@gmail.com>
parents:
25982
diff
changeset
|
132 try: |
|
83d21ea9457d
Fix SF # 631066, running regrtest in user mode fails
Neal Norwitz <nnorwitz@gmail.com>
parents:
25982
diff
changeset
|
133 os.unlink(TESTFN) |
|
83d21ea9457d
Fix SF # 631066, running regrtest in user mode fails
Neal Norwitz <nnorwitz@gmail.com>
parents:
25982
diff
changeset
|
134 except: |
|
83d21ea9457d
Fix SF # 631066, running regrtest in user mode fails
Neal Norwitz <nnorwitz@gmail.com>
parents:
25982
diff
changeset
|
135 pass |
|
83d21ea9457d
Fix SF # 631066, running regrtest in user mode fails
Neal Norwitz <nnorwitz@gmail.com>
parents:
25982
diff
changeset
|
136 del os, fp |
|
17036
ad741745cb6c
Oops. A RISCOS patch I forgot to check in.
Guido van Rossum <guido@python.org>
parents:
16723
diff
changeset
|
137 |
| 653 | 138 from os import unlink |
|
8127
047533789359
Move unified findfile() into test_support.py
Guido van Rossum <guido@python.org>
parents:
4791
diff
changeset
|
139 |
|
047533789359
Move unified findfile() into test_support.py
Guido van Rossum <guido@python.org>
parents:
4791
diff
changeset
|
140 def findfile(file, here=__file__): |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
141 import os |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
142 if os.path.isabs(file): |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
143 return file |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
144 path = sys.path |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
145 path = [os.path.dirname(here)] + path |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
146 for dn in path: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
147 fn = os.path.join(dn, file) |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
148 if os.path.exists(fn): return fn |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13682
diff
changeset
|
149 return file |
|
15957
c1a8deb15f0e
This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents:
15540
diff
changeset
|
150 |
|
c1a8deb15f0e
This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents:
15540
diff
changeset
|
151 def verify(condition, reason='test failed'): |
|
16039
4a6658e18f36
Change verify() function to raise TestFailed, not AssertionError.
Guido van Rossum <guido@python.org>
parents:
16024
diff
changeset
|
152 """Verify that condition is true. If not, raise TestFailed. |
|
15957
c1a8deb15f0e
This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents:
15540
diff
changeset
|
153 |
| 16069 | 154 The optional argument reason can be given to provide |
|
16024
0f8127366a3f
Use constructor form of "raise"; normalize <wink> docstrings.
Tim Peters <tim.peters@gmail.com>
parents:
15977
diff
changeset
|
155 a better error text. |
|
0f8127366a3f
Use constructor form of "raise"; normalize <wink> docstrings.
Tim Peters <tim.peters@gmail.com>
parents:
15977
diff
changeset
|
156 """ |
|
15977
f16545f58345
Whitespace normalization. Leaving tokenize_tests.py alone for now.
Tim Peters <tim.peters@gmail.com>
parents:
15957
diff
changeset
|
157 |
|
f16545f58345
Whitespace normalization. Leaving tokenize_tests.py alone for now.
Tim Peters <tim.peters@gmail.com>
parents:
15957
diff
changeset
|
158 if not condition: |
|
16039
4a6658e18f36
Change verify() function to raise TestFailed, not AssertionError.
Guido van Rossum <guido@python.org>
parents:
16024
diff
changeset
|
159 raise TestFailed(reason) |
|
16679
db4fc82aa44b
Add test for syntax error on "x = 1 + 1".
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16069
diff
changeset
|
160 |
|
20780
ab2e315849a7
Fix bad bug in structseq slicing (NULL pointers in result). Reported by
Tim Peters <tim.peters@gmail.com>
parents:
20260
diff
changeset
|
161 def vereq(a, b): |
|
21595
e56047db6538
test_support: add a docstring to vereq().
Tim Peters <tim.peters@gmail.com>
parents:
20780
diff
changeset
|
162 """Raise TestFailed if a == b is false. |
|
e56047db6538
test_support: add a docstring to vereq().
Tim Peters <tim.peters@gmail.com>
parents:
20780
diff
changeset
|
163 |
|
e56047db6538
test_support: add a docstring to vereq().
Tim Peters <tim.peters@gmail.com>
parents:
20780
diff
changeset
|
164 This is better than verify(a == b) because, in case of failure, the |
|
e56047db6538
test_support: add a docstring to vereq().
Tim Peters <tim.peters@gmail.com>
parents:
20780
diff
changeset
|
165 error message incorporates repr(a) and repr(b) so you can see the |
|
e56047db6538
test_support: add a docstring to vereq().
Tim Peters <tim.peters@gmail.com>
parents:
20780
diff
changeset
|
166 inputs. |
|
e56047db6538
test_support: add a docstring to vereq().
Tim Peters <tim.peters@gmail.com>
parents:
20780
diff
changeset
|
167 |
|
e56047db6538
test_support: add a docstring to vereq().
Tim Peters <tim.peters@gmail.com>
parents:
20780
diff
changeset
|
168 Note that "not (a == b)" isn't necessarily the same as "a != b"; the |
|
e56047db6538
test_support: add a docstring to vereq().
Tim Peters <tim.peters@gmail.com>
parents:
20780
diff
changeset
|
169 former is tested. |
|
e56047db6538
test_support: add a docstring to vereq().
Tim Peters <tim.peters@gmail.com>
parents:
20780
diff
changeset
|
170 """ |
|
e56047db6538
test_support: add a docstring to vereq().
Tim Peters <tim.peters@gmail.com>
parents:
20780
diff
changeset
|
171 |
|
20780
ab2e315849a7
Fix bad bug in structseq slicing (NULL pointers in result). Reported by
Tim Peters <tim.peters@gmail.com>
parents:
20260
diff
changeset
|
172 if not (a == b): |
|
ab2e315849a7
Fix bad bug in structseq slicing (NULL pointers in result). Reported by
Tim Peters <tim.peters@gmail.com>
parents:
20260
diff
changeset
|
173 raise TestFailed, "%r == %r" % (a, b) |
|
ab2e315849a7
Fix bad bug in structseq slicing (NULL pointers in result). Reported by
Tim Peters <tim.peters@gmail.com>
parents:
20260
diff
changeset
|
174 |
|
17815
d6df8d371b67
Get rid of the superstitious "~" in dict hashing's "i = (~hash) & mask".
Tim Peters <tim.peters@gmail.com>
parents:
17213
diff
changeset
|
175 def sortdict(dict): |
|
d6df8d371b67
Get rid of the superstitious "~" in dict hashing's "i = (~hash) & mask".
Tim Peters <tim.peters@gmail.com>
parents:
17213
diff
changeset
|
176 "Like repr(dict), but in sorted order." |
|
d6df8d371b67
Get rid of the superstitious "~" in dict hashing's "i = (~hash) & mask".
Tim Peters <tim.peters@gmail.com>
parents:
17213
diff
changeset
|
177 items = dict.items() |
|
d6df8d371b67
Get rid of the superstitious "~" in dict hashing's "i = (~hash) & mask".
Tim Peters <tim.peters@gmail.com>
parents:
17213
diff
changeset
|
178 items.sort() |
|
d6df8d371b67
Get rid of the superstitious "~" in dict hashing's "i = (~hash) & mask".
Tim Peters <tim.peters@gmail.com>
parents:
17213
diff
changeset
|
179 reprpairs = ["%r: %r" % pair for pair in items] |
|
d6df8d371b67
Get rid of the superstitious "~" in dict hashing's "i = (~hash) & mask".
Tim Peters <tim.peters@gmail.com>
parents:
17213
diff
changeset
|
180 withcommas = ", ".join(reprpairs) |
|
d6df8d371b67
Get rid of the superstitious "~" in dict hashing's "i = (~hash) & mask".
Tim Peters <tim.peters@gmail.com>
parents:
17213
diff
changeset
|
181 return "{%s}" % withcommas |
|
d6df8d371b67
Get rid of the superstitious "~" in dict hashing's "i = (~hash) & mask".
Tim Peters <tim.peters@gmail.com>
parents:
17213
diff
changeset
|
182 |
|
16679
db4fc82aa44b
Add test for syntax error on "x = 1 + 1".
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16069
diff
changeset
|
183 def check_syntax(statement): |
|
db4fc82aa44b
Add test for syntax error on "x = 1 + 1".
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16069
diff
changeset
|
184 try: |
|
db4fc82aa44b
Add test for syntax error on "x = 1 + 1".
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16069
diff
changeset
|
185 compile(statement, '<string>', 'exec') |
|
db4fc82aa44b
Add test for syntax error on "x = 1 + 1".
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16069
diff
changeset
|
186 except SyntaxError: |
|
db4fc82aa44b
Add test for syntax error on "x = 1 + 1".
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16069
diff
changeset
|
187 pass |
|
db4fc82aa44b
Add test for syntax error on "x = 1 + 1".
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16069
diff
changeset
|
188 else: |
|
db4fc82aa44b
Add test for syntax error on "x = 1 + 1".
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16069
diff
changeset
|
189 print 'Missing SyntaxError: "%s"' % statement |
|
17109
7eb8b240dd6c
Just import sys at the top instead of inside lots of functions.
Fred Drake <fdrake@acm.org>
parents:
17036
diff
changeset
|
190 |
|
7eb8b240dd6c
Just import sys at the top instead of inside lots of functions.
Fred Drake <fdrake@acm.org>
parents:
17036
diff
changeset
|
191 |
|
7eb8b240dd6c
Just import sys at the top instead of inside lots of functions.
Fred Drake <fdrake@acm.org>
parents:
17036
diff
changeset
|
192 |
|
7eb8b240dd6c
Just import sys at the top instead of inside lots of functions.
Fred Drake <fdrake@acm.org>
parents:
17036
diff
changeset
|
193 #======================================================================= |
|
7eb8b240dd6c
Just import sys at the top instead of inside lots of functions.
Fred Drake <fdrake@acm.org>
parents:
17036
diff
changeset
|
194 # Preliminary PyUNIT integration. |
|
7eb8b240dd6c
Just import sys at the top instead of inside lots of functions.
Fred Drake <fdrake@acm.org>
parents:
17036
diff
changeset
|
195 |
|
7eb8b240dd6c
Just import sys at the top instead of inside lots of functions.
Fred Drake <fdrake@acm.org>
parents:
17036
diff
changeset
|
196 import unittest |
|
7eb8b240dd6c
Just import sys at the top instead of inside lots of functions.
Fred Drake <fdrake@acm.org>
parents:
17036
diff
changeset
|
197 |
|
7eb8b240dd6c
Just import sys at the top instead of inside lots of functions.
Fred Drake <fdrake@acm.org>
parents:
17036
diff
changeset
|
198 |
|
17133
d0fd60c59aef
Updated to latest PyUnit version (1.31 in PyUnit CVS); test_support.py
Steve Purcell <steve@pythonconsulting.com>
parents:
17109
diff
changeset
|
199 class BasicTestRunner: |
|
17109
7eb8b240dd6c
Just import sys at the top instead of inside lots of functions.
Fred Drake <fdrake@acm.org>
parents:
17036
diff
changeset
|
200 def run(self, test): |
|
17133
d0fd60c59aef
Updated to latest PyUnit version (1.31 in PyUnit CVS); test_support.py
Steve Purcell <steve@pythonconsulting.com>
parents:
17109
diff
changeset
|
201 result = unittest.TestResult() |
|
17109
7eb8b240dd6c
Just import sys at the top instead of inside lots of functions.
Fred Drake <fdrake@acm.org>
parents:
17036
diff
changeset
|
202 test(result) |
|
7eb8b240dd6c
Just import sys at the top instead of inside lots of functions.
Fred Drake <fdrake@acm.org>
parents:
17036
diff
changeset
|
203 return result |
|
7eb8b240dd6c
Just import sys at the top instead of inside lots of functions.
Fred Drake <fdrake@acm.org>
parents:
17036
diff
changeset
|
204 |
|
7eb8b240dd6c
Just import sys at the top instead of inside lots of functions.
Fred Drake <fdrake@acm.org>
parents:
17036
diff
changeset
|
205 |
|
20260
1ea5bbbab7d7
run_suite(): If testclass is not available, provide an even more general
Fred Drake <fdrake@acm.org>
parents:
20227
diff
changeset
|
206 def run_suite(suite, testclass=None): |
|
19995
b07cb51d731c
run_suite(): Oops, update a docstring.
Barry Warsaw <barry@python.org>
parents:
19994
diff
changeset
|
207 """Run tests from a unittest.TestSuite-derived class.""" |
|
17109
7eb8b240dd6c
Just import sys at the top instead of inside lots of functions.
Fred Drake <fdrake@acm.org>
parents:
17036
diff
changeset
|
208 if verbose: |
|
17171
4f68d3f8fdc8
When the regression test is run in verbose mode, make the PyUNIT-based
Fred Drake <fdrake@acm.org>
parents:
17133
diff
changeset
|
209 runner = unittest.TextTestRunner(sys.stdout, verbosity=2) |
|
17109
7eb8b240dd6c
Just import sys at the top instead of inside lots of functions.
Fred Drake <fdrake@acm.org>
parents:
17036
diff
changeset
|
210 else: |
|
17133
d0fd60c59aef
Updated to latest PyUnit version (1.31 in PyUnit CVS); test_support.py
Steve Purcell <steve@pythonconsulting.com>
parents:
17109
diff
changeset
|
211 runner = BasicTestRunner() |
|
17109
7eb8b240dd6c
Just import sys at the top instead of inside lots of functions.
Fred Drake <fdrake@acm.org>
parents:
17036
diff
changeset
|
212 |
|
17133
d0fd60c59aef
Updated to latest PyUnit version (1.31 in PyUnit CVS); test_support.py
Steve Purcell <steve@pythonconsulting.com>
parents:
17109
diff
changeset
|
213 result = runner.run(suite) |
|
d0fd60c59aef
Updated to latest PyUnit version (1.31 in PyUnit CVS); test_support.py
Steve Purcell <steve@pythonconsulting.com>
parents:
17109
diff
changeset
|
214 if not result.wasSuccessful(): |
|
18635
c8e4728d2ab0
Give more useful information about a failing PyUnit-style test.
Fred Drake <fdrake@acm.org>
parents:
17817
diff
changeset
|
215 if len(result.errors) == 1 and not result.failures: |
|
c8e4728d2ab0
Give more useful information about a failing PyUnit-style test.
Fred Drake <fdrake@acm.org>
parents:
17817
diff
changeset
|
216 err = result.errors[0][1] |
|
c8e4728d2ab0
Give more useful information about a failing PyUnit-style test.
Fred Drake <fdrake@acm.org>
parents:
17817
diff
changeset
|
217 elif len(result.failures) == 1 and not result.errors: |
|
c8e4728d2ab0
Give more useful information about a failing PyUnit-style test.
Fred Drake <fdrake@acm.org>
parents:
17817
diff
changeset
|
218 err = result.failures[0][1] |
|
c8e4728d2ab0
Give more useful information about a failing PyUnit-style test.
Fred Drake <fdrake@acm.org>
parents:
17817
diff
changeset
|
219 else: |
|
20260
1ea5bbbab7d7
run_suite(): If testclass is not available, provide an even more general
Fred Drake <fdrake@acm.org>
parents:
20227
diff
changeset
|
220 if testclass is None: |
|
1ea5bbbab7d7
run_suite(): If testclass is not available, provide an even more general
Fred Drake <fdrake@acm.org>
parents:
20227
diff
changeset
|
221 msg = "errors occurred; run in verbose mode for details" |
|
1ea5bbbab7d7
run_suite(): If testclass is not available, provide an even more general
Fred Drake <fdrake@acm.org>
parents:
20227
diff
changeset
|
222 else: |
|
1ea5bbbab7d7
run_suite(): If testclass is not available, provide an even more general
Fred Drake <fdrake@acm.org>
parents:
20227
diff
changeset
|
223 msg = "errors occurred in %s.%s" \ |
|
1ea5bbbab7d7
run_suite(): If testclass is not available, provide an even more general
Fred Drake <fdrake@acm.org>
parents:
20227
diff
changeset
|
224 % (testclass.__module__, testclass.__name__) |
|
1ea5bbbab7d7
run_suite(): If testclass is not available, provide an even more general
Fred Drake <fdrake@acm.org>
parents:
20227
diff
changeset
|
225 raise TestFailed(msg) |
|
19807
086ffafaed55
It appears that unittest was changed to stop hoarding raw exception data,
Tim Peters <tim.peters@gmail.com>
parents:
19768
diff
changeset
|
226 raise TestFailed(err) |
|
19817
b7396287cf65
Teach regrtest how to pass on doctest failure msgs. This is done via a
Tim Peters <tim.peters@gmail.com>
parents:
19807
diff
changeset
|
227 |
|
19994
ab6c14822de1
run_suite(): Factor this out of run_unittest() for tests that build
Barry Warsaw <barry@python.org>
parents:
19819
diff
changeset
|
228 |
|
ab6c14822de1
run_suite(): Factor this out of run_unittest() for tests that build
Barry Warsaw <barry@python.org>
parents:
19819
diff
changeset
|
229 def run_unittest(testclass): |
|
ab6c14822de1
run_suite(): Factor this out of run_unittest() for tests that build
Barry Warsaw <barry@python.org>
parents:
19819
diff
changeset
|
230 """Run tests from a unittest.TestCase-derived class.""" |
|
20260
1ea5bbbab7d7
run_suite(): If testclass is not available, provide an even more general
Fred Drake <fdrake@acm.org>
parents:
20227
diff
changeset
|
231 run_suite(unittest.makeSuite(testclass), testclass) |
|
19994
ab6c14822de1
run_suite(): Factor this out of run_unittest() for tests that build
Barry Warsaw <barry@python.org>
parents:
19819
diff
changeset
|
232 |
|
ab6c14822de1
run_suite(): Factor this out of run_unittest() for tests that build
Barry Warsaw <barry@python.org>
parents:
19819
diff
changeset
|
233 |
|
19817
b7396287cf65
Teach regrtest how to pass on doctest failure msgs. This is done via a
Tim Peters <tim.peters@gmail.com>
parents:
19807
diff
changeset
|
234 #======================================================================= |
|
b7396287cf65
Teach regrtest how to pass on doctest failure msgs. This is done via a
Tim Peters <tim.peters@gmail.com>
parents:
19807
diff
changeset
|
235 # doctest driver. |
|
b7396287cf65
Teach regrtest how to pass on doctest failure msgs. This is done via a
Tim Peters <tim.peters@gmail.com>
parents:
19807
diff
changeset
|
236 |
|
b7396287cf65
Teach regrtest how to pass on doctest failure msgs. This is done via a
Tim Peters <tim.peters@gmail.com>
parents:
19807
diff
changeset
|
237 def run_doctest(module, verbosity=None): |
|
20227
92f86436b6be
SF bug [#467336] doctest failures w/ new-style classes.
Tim Peters <tim.peters@gmail.com>
parents:
20091
diff
changeset
|
238 """Run doctest on the given module. Return (#failures, #tests). |
|
19817
b7396287cf65
Teach regrtest how to pass on doctest failure msgs. This is done via a
Tim Peters <tim.peters@gmail.com>
parents:
19807
diff
changeset
|
239 |
|
b7396287cf65
Teach regrtest how to pass on doctest failure msgs. This is done via a
Tim Peters <tim.peters@gmail.com>
parents:
19807
diff
changeset
|
240 If optional argument verbosity is not specified (or is None), pass |
|
19819
53e0cae3cf6c
Repair late-night doc typos.
Tim Peters <tim.peters@gmail.com>
parents:
19817
diff
changeset
|
241 test_support's belief about verbosity on to doctest. Else doctest's |
|
53e0cae3cf6c
Repair late-night doc typos.
Tim Peters <tim.peters@gmail.com>
parents:
19817
diff
changeset
|
242 usual behavior is used (it searches sys.argv for -v). |
|
19817
b7396287cf65
Teach regrtest how to pass on doctest failure msgs. This is done via a
Tim Peters <tim.peters@gmail.com>
parents:
19807
diff
changeset
|
243 """ |
|
b7396287cf65
Teach regrtest how to pass on doctest failure msgs. This is done via a
Tim Peters <tim.peters@gmail.com>
parents:
19807
diff
changeset
|
244 |
|
b7396287cf65
Teach regrtest how to pass on doctest failure msgs. This is done via a
Tim Peters <tim.peters@gmail.com>
parents:
19807
diff
changeset
|
245 import doctest |
|
b7396287cf65
Teach regrtest how to pass on doctest failure msgs. This is done via a
Tim Peters <tim.peters@gmail.com>
parents:
19807
diff
changeset
|
246 |
|
b7396287cf65
Teach regrtest how to pass on doctest failure msgs. This is done via a
Tim Peters <tim.peters@gmail.com>
parents:
19807
diff
changeset
|
247 if verbosity is None: |
|
b7396287cf65
Teach regrtest how to pass on doctest failure msgs. This is done via a
Tim Peters <tim.peters@gmail.com>
parents:
19807
diff
changeset
|
248 verbosity = verbose |
|
b7396287cf65
Teach regrtest how to pass on doctest failure msgs. This is done via a
Tim Peters <tim.peters@gmail.com>
parents:
19807
diff
changeset
|
249 else: |
|
b7396287cf65
Teach regrtest how to pass on doctest failure msgs. This is done via a
Tim Peters <tim.peters@gmail.com>
parents:
19807
diff
changeset
|
250 verbosity = None |
|
b7396287cf65
Teach regrtest how to pass on doctest failure msgs. This is done via a
Tim Peters <tim.peters@gmail.com>
parents:
19807
diff
changeset
|
251 |
|
20088
386fb26e0874
Get rid of the increasingly convoluted global tricks w/ sys.stdout, in
Tim Peters <tim.peters@gmail.com>
parents:
20083
diff
changeset
|
252 # Direct doctest output (normally just errors) to real stdout; doctest |
|
386fb26e0874
Get rid of the increasingly convoluted global tricks w/ sys.stdout, in
Tim Peters <tim.peters@gmail.com>
parents:
20083
diff
changeset
|
253 # output shouldn't be compared by regrtest. |
|
386fb26e0874
Get rid of the increasingly convoluted global tricks w/ sys.stdout, in
Tim Peters <tim.peters@gmail.com>
parents:
20083
diff
changeset
|
254 save_stdout = sys.stdout |
|
20091
40d4d1cd6c84
Guido points out that sys.__stdout__ is a bit bucket under IDLE. So keep
Tim Peters <tim.peters@gmail.com>
parents:
20088
diff
changeset
|
255 sys.stdout = get_original_stdout() |
|
20088
386fb26e0874
Get rid of the increasingly convoluted global tricks w/ sys.stdout, in
Tim Peters <tim.peters@gmail.com>
parents:
20083
diff
changeset
|
256 try: |
|
386fb26e0874
Get rid of the increasingly convoluted global tricks w/ sys.stdout, in
Tim Peters <tim.peters@gmail.com>
parents:
20083
diff
changeset
|
257 f, t = doctest.testmod(module, verbose=verbosity) |
|
386fb26e0874
Get rid of the increasingly convoluted global tricks w/ sys.stdout, in
Tim Peters <tim.peters@gmail.com>
parents:
20083
diff
changeset
|
258 if f: |
|
386fb26e0874
Get rid of the increasingly convoluted global tricks w/ sys.stdout, in
Tim Peters <tim.peters@gmail.com>
parents:
20083
diff
changeset
|
259 raise TestFailed("%d of %d doctests failed" % (f, t)) |
|
20227
92f86436b6be
SF bug [#467336] doctest failures w/ new-style classes.
Tim Peters <tim.peters@gmail.com>
parents:
20091
diff
changeset
|
260 return f, t |
|
20088
386fb26e0874
Get rid of the increasingly convoluted global tricks w/ sys.stdout, in
Tim Peters <tim.peters@gmail.com>
parents:
20083
diff
changeset
|
261 finally: |
|
386fb26e0874
Get rid of the increasingly convoluted global tricks w/ sys.stdout, in
Tim Peters <tim.peters@gmail.com>
parents:
20083
diff
changeset
|
262 sys.stdout = save_stdout |
