append(): Fixing the test for convertability after consultation with
[python/dscho.git] / Lib / test / test___all__.py
bloba0ffa6524c7b0ed9d72ada6846763229953ba5c9
1 from test.test_support import verify, verbose
2 import sys
3 import warnings
5 warnings.filterwarnings("ignore", ".* 'pre' .*", DeprecationWarning,
6 r'pre$')
7 warnings.filterwarnings("ignore", ".* regsub .*", DeprecationWarning,
8 r'^regsub$')
9 warnings.filterwarnings("ignore", ".* statcache .*", DeprecationWarning,
10 r'statcache$')
12 def check_all(modname):
13 names = {}
14 try:
15 exec "import %s" % modname in names
16 except ImportError:
17 # Silent fail here seems the best route since some modules
18 # may not be available in all environments.
19 # Since an ImportError may leave a partial module object in
20 # sys.modules, get rid of that first. Here's what happens if
21 # you don't: importing pty fails on Windows because pty tries to
22 # import FCNTL, which doesn't exist. That raises an ImportError,
23 # caught here. It also leaves a partial pty module in sys.modules.
24 # So when test_pty is called later, the import of pty succeeds,
25 # but shouldn't. As a result, test_pty crashes with an
26 # AttributeError instead of an ImportError, and regrtest interprets
27 # the latter as a test failure (ImportError is treated as "test
28 # skipped" -- which is what test_pty should say on Windows).
29 try:
30 del sys.modules[modname]
31 except KeyError:
32 pass
33 return
34 verify(hasattr(sys.modules[modname], "__all__"),
35 "%s has no __all__ attribute" % modname)
36 names = {}
37 exec "from %s import *" % modname in names
38 if names.has_key("__builtins__"):
39 del names["__builtins__"]
40 keys = names.keys()
41 keys.sort()
42 all = list(sys.modules[modname].__all__) # in case it's a tuple
43 all.sort()
44 verify(keys==all, "%s != %s" % (keys, all))
46 if not sys.platform.startswith('java'):
47 # In case _socket fails to build, make this test fail more gracefully
48 # than an AttributeError somewhere deep in CGIHTTPServer.
49 import _socket
51 check_all("BaseHTTPServer")
52 check_all("CGIHTTPServer")
53 check_all("ConfigParser")
54 check_all("Cookie")
55 check_all("MimeWriter")
56 check_all("SimpleHTTPServer")
57 check_all("SocketServer")
58 check_all("StringIO")
59 check_all("UserString")
60 check_all("aifc")
61 check_all("atexit")
62 check_all("audiodev")
63 check_all("base64")
64 check_all("bdb")
65 check_all("binhex")
66 check_all("calendar")
67 check_all("cgi")
68 check_all("cmd")
69 check_all("code")
70 check_all("codecs")
71 check_all("codeop")
72 check_all("colorsys")
73 check_all("commands")
74 check_all("compileall")
75 check_all("copy")
76 check_all("copy_reg")
77 check_all("dbhash")
78 check_all("dircache")
79 check_all("dis")
80 check_all("doctest")
81 check_all("dospath")
82 check_all("filecmp")
83 check_all("fileinput")
84 check_all("fnmatch")
85 check_all("fpformat")
86 check_all("ftplib")
87 check_all("getopt")
88 check_all("getpass")
89 check_all("gettext")
90 check_all("glob")
91 check_all("gopherlib")
92 check_all("gzip")
93 check_all("htmllib")
94 check_all("httplib")
95 check_all("ihooks")
96 check_all("imaplib")
97 check_all("imghdr")
98 check_all("imputil")
99 check_all("keyword")
100 check_all("linecache")
101 check_all("locale")
102 check_all("macpath")
103 check_all("macurl2path")
104 check_all("mailbox")
105 check_all("mhlib")
106 check_all("mimetools")
107 check_all("mimetypes")
108 check_all("mimify")
109 check_all("multifile")
110 check_all("netrc")
111 check_all("nntplib")
112 check_all("ntpath")
113 check_all("os")
114 check_all("pdb")
115 check_all("pickle")
116 check_all("pipes")
117 check_all("popen2")
118 check_all("poplib")
119 check_all("posixpath")
120 check_all("pprint")
121 check_all("pre") # deprecated
122 check_all("profile")
123 check_all("pstats")
124 check_all("pty")
125 check_all("py_compile")
126 check_all("pyclbr")
127 check_all("quopri")
128 check_all("random")
129 check_all("re")
130 check_all("reconvert")
131 check_all("regsub")
132 check_all("repr")
133 check_all("rexec")
134 check_all("rfc822")
135 check_all("robotparser")
136 check_all("sched")
137 check_all("sgmllib")
138 check_all("shelve")
139 check_all("shlex")
140 check_all("shutil")
141 check_all("smtpd")
142 check_all("smtplib")
143 check_all("sndhdr")
144 check_all("socket")
145 check_all("sre")
146 check_all("stat_cache")
147 check_all("tabnanny")
148 check_all("telnetlib")
149 check_all("tempfile")
150 check_all("toaiff")
151 check_all("tokenize")
152 check_all("traceback")
153 check_all("tty")
154 check_all("urllib")
155 check_all("urlparse")
156 check_all("uu")
157 check_all("warnings")
158 check_all("wave")
159 check_all("weakref")
160 check_all("webbrowser")
161 check_all("xdrlib")
162 check_all("zipfile")
164 # rlcompleter needs special consideration; it import readline which
165 # initializes GNU readline which calls setlocale(LC_CTYPE, "")... :-(
166 try:
167 check_all("rlcompleter")
168 finally:
169 try:
170 import locale
171 except ImportError:
172 pass
173 else:
174 locale.setlocale(locale.LC_CTYPE, 'C')