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