Guido van Rossum | d0f5e70 | 2001-01-22 23:37:04 +0000 | [diff] [blame] | 1 | from test_support import verify, verbose |
Skip Montanaro | e99d5ea | 2001-01-20 19:54:20 +0000 | [diff] [blame] | 2 | import sys |
| 3 | |
Guido van Rossum | d0f5e70 | 2001-01-22 23:37:04 +0000 | [diff] [blame] | 4 | def check_all(modname): |
Skip Montanaro | 0de6580 | 2001-02-15 22:15:14 +0000 | [diff] [blame^] | 5 | import warnings |
| 6 | warnings.filterwarnings("ignore", "", DeprecationWarning, modname) |
| 7 | |
Guido van Rossum | d0f5e70 | 2001-01-22 23:37:04 +0000 | [diff] [blame] | 8 | names = {} |
Skip Montanaro | 03d9014 | 2001-01-25 15:29:22 +0000 | [diff] [blame] | 9 | try: |
| 10 | exec "import %s" % modname in names |
| 11 | except ImportError: |
Tim Peters | 76c066b | 2001-02-12 03:27:31 +0000 | [diff] [blame] | 12 | # Silent fail here seems the best route since some modules |
| 13 | # may not be available in all environments. |
| 14 | # Since an ImportError may leave a partial module object in |
| 15 | # sys.modules, get rid of that first. Here's what happens if |
| 16 | # you don't: importing pty fails on Windows because pty tries to |
| 17 | # import FCNTL, which doesn't exist. That raises an ImportError, |
| 18 | # caught here. It also leaves a partial pty module in sys.modules. |
| 19 | # So when test_pty is called later, the import of pty succeeds, |
| 20 | # but shouldn't. As a result, test_pty crashes with an |
| 21 | # AtttributeError instead of an ImportError, and regrtest interprets |
| 22 | # the latter as a test failure (ImportError is treated as "test |
| 23 | # skipped" -- which is what test_pty should say on Windows). |
| 24 | try: |
| 25 | del sys.modules[modname] |
| 26 | except KeyError: |
| 27 | pass |
Skip Montanaro | 03d9014 | 2001-01-25 15:29:22 +0000 | [diff] [blame] | 28 | return |
Guido van Rossum | d0f5e70 | 2001-01-22 23:37:04 +0000 | [diff] [blame] | 29 | verify(hasattr(sys.modules[modname], "__all__"), |
| 30 | "%s has no __all__ attribute" % modname) |
| 31 | names = {} |
| 32 | exec "from %s import *" % modname in names |
Skip Montanaro | cc012e9 | 2001-02-07 22:46:55 +0000 | [diff] [blame] | 33 | if names.has_key("__builtins__"): |
| 34 | del names["__builtins__"] |
Guido van Rossum | d0f5e70 | 2001-01-22 23:37:04 +0000 | [diff] [blame] | 35 | keys = names.keys() |
| 36 | keys.sort() |
| 37 | all = list(sys.modules[modname].__all__) # in case it's a tuple |
Skip Montanaro | e99d5ea | 2001-01-20 19:54:20 +0000 | [diff] [blame] | 38 | all.sort() |
Guido van Rossum | d0f5e70 | 2001-01-22 23:37:04 +0000 | [diff] [blame] | 39 | verify(keys==all, "%s != %s" % (keys, all)) |
Skip Montanaro | e99d5ea | 2001-01-20 19:54:20 +0000 | [diff] [blame] | 40 | |
| 41 | check_all("BaseHTTPServer") |
| 42 | check_all("Bastion") |
| 43 | check_all("CGIHTTPServer") |
| 44 | check_all("ConfigParser") |
| 45 | check_all("Cookie") |
| 46 | check_all("MimeWriter") |
| 47 | check_all("Queue") |
| 48 | check_all("SimpleHTTPServer") |
| 49 | check_all("SocketServer") |
| 50 | check_all("StringIO") |
| 51 | check_all("UserDict") |
| 52 | check_all("UserList") |
| 53 | check_all("UserString") |
| 54 | check_all("aifc") |
| 55 | check_all("anydbm") |
| 56 | check_all("atexit") |
| 57 | check_all("audiodev") |
| 58 | check_all("base64") |
| 59 | check_all("bdb") |
| 60 | check_all("binhex") |
| 61 | check_all("bisect") |
| 62 | check_all("calendar") |
| 63 | check_all("cgi") |
| 64 | check_all("chunk") |
| 65 | check_all("cmd") |
| 66 | check_all("code") |
| 67 | check_all("codecs") |
| 68 | check_all("codeop") |
| 69 | check_all("colorsys") |
| 70 | check_all("commands") |
| 71 | check_all("compileall") |
| 72 | check_all("copy") |
| 73 | check_all("copy_reg") |
Skip Montanaro | 03d9014 | 2001-01-25 15:29:22 +0000 | [diff] [blame] | 74 | check_all("dbhash") |
Skip Montanaro | e99d5ea | 2001-01-20 19:54:20 +0000 | [diff] [blame] | 75 | check_all("dircache") |
| 76 | check_all("dis") |
Skip Montanaro | eccd02a | 2001-01-20 23:34:12 +0000 | [diff] [blame] | 77 | check_all("doctest") |
| 78 | check_all("dospath") |
| 79 | check_all("dumbdbm") |
| 80 | check_all("filecmp") |
| 81 | check_all("fileinput") |
| 82 | check_all("fnmatch") |
| 83 | check_all("fpformat") |
| 84 | check_all("ftplib") |
| 85 | check_all("getopt") |
| 86 | check_all("getpass") |
Skip Montanaro | 2dd4276 | 2001-01-23 15:35:05 +0000 | [diff] [blame] | 87 | check_all("gettext") |
Skip Montanaro | eccd02a | 2001-01-20 23:34:12 +0000 | [diff] [blame] | 88 | check_all("glob") |
Barry Warsaw | 24f3aca | 2001-01-24 04:13:02 +0000 | [diff] [blame] | 89 | check_all("gopherlib") |
Skip Montanaro | 2dd4276 | 2001-01-23 15:35:05 +0000 | [diff] [blame] | 90 | check_all("gzip") |
| 91 | check_all("htmlentitydefs") |
| 92 | check_all("htmllib") |
| 93 | check_all("httplib") |
| 94 | check_all("ihooks") |
| 95 | check_all("imaplib") |
Skip Montanaro | 17ab123 | 2001-01-24 06:27:27 +0000 | [diff] [blame] | 96 | check_all("imghdr") |
| 97 | check_all("imputil") |
| 98 | check_all("keyword") |
| 99 | check_all("linecache") |
| 100 | check_all("locale") |
| 101 | check_all("macpath") |
| 102 | check_all("macurl2path") |
| 103 | check_all("mailbox") |
| 104 | check_all("mhlib") |
Skip Montanaro | 03d9014 | 2001-01-25 15:29:22 +0000 | [diff] [blame] | 105 | check_all("mimetools") |
| 106 | check_all("mimetypes") |
| 107 | check_all("mimify") |
Skip Montanaro | 269b83b | 2001-02-06 01:07:02 +0000 | [diff] [blame] | 108 | check_all("multifile") |
| 109 | check_all("mutex") |
| 110 | check_all("netrc") |
| 111 | check_all("nntplib") |
| 112 | check_all("ntpath") |
| 113 | check_all("nturl2path") |
| 114 | check_all("os") |
Skip Montanaro | 352674d | 2001-02-07 23:14:30 +0000 | [diff] [blame] | 115 | check_all("pdb") |
| 116 | check_all("pickle") |
| 117 | check_all("pipes") |
| 118 | check_all("popen2") |
Skip Montanaro | c62c81e | 2001-02-12 02:00:42 +0000 | [diff] [blame] | 119 | check_all("poplib") |
| 120 | check_all("posixfile") |
| 121 | check_all("posixpath") |
| 122 | check_all("pprint") |
| 123 | check_all("pre") |
| 124 | check_all("profile") |
| 125 | check_all("pstats") |
| 126 | check_all("pty") |
| 127 | check_all("py_compile") |
| 128 | check_all("pyclbr") |
| 129 | check_all("quopri") |
Skip Montanaro | 0de6580 | 2001-02-15 22:15:14 +0000 | [diff] [blame^] | 130 | check_all("random") |
| 131 | check_all("re") |
| 132 | check_all("reconvert") |
| 133 | check_all("regex_syntax") |
| 134 | check_all("regsub") |
| 135 | check_all("repr") |
| 136 | check_all("rexec") |
| 137 | check_all("rfc822") |
| 138 | check_all("rlcompleter") |
Skip Montanaro | e99d5ea | 2001-01-20 19:54:20 +0000 | [diff] [blame] | 139 | check_all("robotparser") |
Skip Montanaro | 0de6580 | 2001-02-15 22:15:14 +0000 | [diff] [blame^] | 140 | check_all("sched") |
| 141 | check_all("sgmllib") |
| 142 | check_all("shelve") |
| 143 | check_all("shlex") |
| 144 | check_all("shutil") |
| 145 | check_all("smtpd") |
| 146 | check_all("smtplib") |
| 147 | check_all("sndhdr") |
| 148 | check_all("socket") |
| 149 | check_all("sre") |
| 150 | check_all("sre_compile") |
| 151 | check_all("sre_constants") |
| 152 | check_all("sre_parse") |
| 153 | check_all("stat") |
| 154 | check_all("stat_cache") |
| 155 | check_all("statvfs") |
| 156 | check_all("string") |