Walter Dörwald | b1ded1e | 2003-04-15 11:10:33 +0000 | [diff] [blame] | 1 | import unittest |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 2 | from test.support import run_unittest, catch_warning |
Skip Montanaro | e99d5ea | 2001-01-20 19:54:20 +0000 | [diff] [blame] | 3 | import sys |
Christian Heimes | 75ca4ea | 2008-05-06 23:48:04 +0000 | [diff] [blame] | 4 | import warnings |
Tim Peters | b05cd49 | 2002-04-11 20:04:12 +0000 | [diff] [blame] | 5 | |
Skip Montanaro | e99d5ea | 2001-01-20 19:54:20 +0000 | [diff] [blame] | 6 | |
Walter Dörwald | b1ded1e | 2003-04-15 11:10:33 +0000 | [diff] [blame] | 7 | class AllTest(unittest.TestCase): |
| 8 | |
| 9 | def check_all(self, modname): |
| 10 | names = {} |
Christian Heimes | 75ca4ea | 2008-05-06 23:48:04 +0000 | [diff] [blame] | 11 | with catch_warning(): |
Alexandre Vassalotti | a79e33e | 2008-05-15 22:51:26 +0000 | [diff] [blame] | 12 | warnings.filterwarnings("ignore", ".* (module|package)", |
| 13 | DeprecationWarning) |
Christian Heimes | 75ca4ea | 2008-05-06 23:48:04 +0000 | [diff] [blame] | 14 | try: |
| 15 | exec("import %s" % modname, names) |
| 16 | except ImportError: |
| 17 | # Silent fail here seems the best route since some modules |
| 18 | # may not be available in all environments. |
| 19 | return |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 20 | self.failUnless(hasattr(sys.modules[modname], "__all__"), |
| 21 | "%s has no __all__ attribute" % modname) |
Walter Dörwald | b1ded1e | 2003-04-15 11:10:33 +0000 | [diff] [blame] | 22 | names = {} |
Georg Brandl | 7cae87c | 2006-09-06 06:51:57 +0000 | [diff] [blame] | 23 | exec("from %s import *" % modname, names) |
Guido van Rossum | e2b70bc | 2006-08-18 22:13:04 +0000 | [diff] [blame] | 24 | if "__builtins__" in names: |
Walter Dörwald | b1ded1e | 2003-04-15 11:10:33 +0000 | [diff] [blame] | 25 | del names["__builtins__"] |
Raymond Hettinger | a690a99 | 2003-11-16 16:17:49 +0000 | [diff] [blame] | 26 | keys = set(names) |
| 27 | all = set(sys.modules[modname].__all__) |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 28 | self.assertEqual(keys, all) |
Skip Montanaro | e99d5ea | 2001-01-20 19:54:20 +0000 | [diff] [blame] | 29 | |
Walter Dörwald | b1ded1e | 2003-04-15 11:10:33 +0000 | [diff] [blame] | 30 | def test_all(self): |
| 31 | if not sys.platform.startswith('java'): |
| 32 | # In case _socket fails to build, make this test fail more gracefully |
| 33 | # than an AttributeError somewhere deep in CGIHTTPServer. |
| 34 | import _socket |
Tim Peters | ab9ba27 | 2001-08-09 21:40:30 +0000 | [diff] [blame] | 35 | |
Georg Brandl | 2442015 | 2008-05-26 16:32:26 +0000 | [diff] [blame^] | 36 | self.check_all("http.server") |
Alexandre Vassalotti | 1d1eaa4 | 2008-05-14 22:59:42 +0000 | [diff] [blame] | 37 | self.check_all("configparser") |
Georg Brandl | 2442015 | 2008-05-26 16:32:26 +0000 | [diff] [blame^] | 38 | self.check_all("http.cookies") |
| 39 | self.check_all("queue") |
Alexandre Vassalotti | ce26195 | 2008-05-12 02:31:37 +0000 | [diff] [blame] | 40 | self.check_all("socketserver") |
Walter Dörwald | b1ded1e | 2003-04-15 11:10:33 +0000 | [diff] [blame] | 41 | self.check_all("aifc") |
Walter Dörwald | b1ded1e | 2003-04-15 11:10:33 +0000 | [diff] [blame] | 42 | self.check_all("base64") |
| 43 | self.check_all("bdb") |
| 44 | self.check_all("binhex") |
| 45 | self.check_all("calendar") |
Brett Cannon | 23a4a7b | 2008-05-12 00:56:28 +0000 | [diff] [blame] | 46 | self.check_all("collections") |
Walter Dörwald | b1ded1e | 2003-04-15 11:10:33 +0000 | [diff] [blame] | 47 | self.check_all("cgi") |
| 48 | self.check_all("cmd") |
| 49 | self.check_all("code") |
| 50 | self.check_all("codecs") |
| 51 | self.check_all("codeop") |
| 52 | self.check_all("colorsys") |
| 53 | self.check_all("commands") |
| 54 | self.check_all("compileall") |
| 55 | self.check_all("copy") |
Alexandre Vassalotti | f7fa63d | 2008-05-11 08:55:36 +0000 | [diff] [blame] | 56 | self.check_all("copyreg") |
Raymond Hettinger | b7b4ce2 | 2003-05-10 05:37:13 +0000 | [diff] [blame] | 57 | self.check_all("csv") |
Georg Brandl | 0a7ac7d | 2008-05-26 10:29:35 +0000 | [diff] [blame] | 58 | self.check_all("dbm.bsd") |
Raymond Hettinger | 75cc1cb | 2004-07-01 11:15:39 +0000 | [diff] [blame] | 59 | self.check_all("decimal") |
Walter Dörwald | b1ded1e | 2003-04-15 11:10:33 +0000 | [diff] [blame] | 60 | self.check_all("difflib") |
| 61 | self.check_all("dircache") |
| 62 | self.check_all("dis") |
| 63 | self.check_all("doctest") |
Georg Brandl | 2067bfd | 2008-05-25 13:05:15 +0000 | [diff] [blame] | 64 | self.check_all("_dummy_thread") |
Walter Dörwald | b1ded1e | 2003-04-15 11:10:33 +0000 | [diff] [blame] | 65 | self.check_all("dummy_threading") |
| 66 | self.check_all("filecmp") |
| 67 | self.check_all("fileinput") |
| 68 | self.check_all("fnmatch") |
| 69 | self.check_all("fpformat") |
| 70 | self.check_all("ftplib") |
| 71 | self.check_all("getopt") |
| 72 | self.check_all("getpass") |
| 73 | self.check_all("gettext") |
| 74 | self.check_all("glob") |
Walter Dörwald | b1ded1e | 2003-04-15 11:10:33 +0000 | [diff] [blame] | 75 | self.check_all("gzip") |
Raymond Hettinger | 59efe36 | 2004-06-13 05:46:14 +0000 | [diff] [blame] | 76 | self.check_all("heapq") |
Walter Dörwald | b1ded1e | 2003-04-15 11:10:33 +0000 | [diff] [blame] | 77 | self.check_all("htmllib") |
Georg Brandl | 2442015 | 2008-05-26 16:32:26 +0000 | [diff] [blame^] | 78 | self.check_all("http.client") |
Walter Dörwald | b1ded1e | 2003-04-15 11:10:33 +0000 | [diff] [blame] | 79 | self.check_all("ihooks") |
| 80 | self.check_all("imaplib") |
| 81 | self.check_all("imghdr") |
Walter Dörwald | b1ded1e | 2003-04-15 11:10:33 +0000 | [diff] [blame] | 82 | self.check_all("keyword") |
| 83 | self.check_all("linecache") |
| 84 | self.check_all("locale") |
| 85 | self.check_all("macpath") |
| 86 | self.check_all("macurl2path") |
| 87 | self.check_all("mailbox") |
| 88 | self.check_all("mailcap") |
| 89 | self.check_all("mhlib") |
| 90 | self.check_all("mimetools") |
| 91 | self.check_all("mimetypes") |
Walter Dörwald | b1ded1e | 2003-04-15 11:10:33 +0000 | [diff] [blame] | 92 | self.check_all("multifile") |
| 93 | self.check_all("netrc") |
| 94 | self.check_all("nntplib") |
| 95 | self.check_all("ntpath") |
| 96 | self.check_all("opcode") |
Raymond Hettinger | b7b4ce2 | 2003-05-10 05:37:13 +0000 | [diff] [blame] | 97 | self.check_all("optparse") |
Walter Dörwald | b1ded1e | 2003-04-15 11:10:33 +0000 | [diff] [blame] | 98 | self.check_all("os") |
| 99 | self.check_all("os2emxpath") |
| 100 | self.check_all("pdb") |
| 101 | self.check_all("pickle") |
Tim Peters | 90cf212 | 2004-11-06 23:45:48 +0000 | [diff] [blame] | 102 | self.check_all("pickletools") |
Walter Dörwald | b1ded1e | 2003-04-15 11:10:33 +0000 | [diff] [blame] | 103 | self.check_all("pipes") |
Walter Dörwald | b1ded1e | 2003-04-15 11:10:33 +0000 | [diff] [blame] | 104 | self.check_all("poplib") |
| 105 | self.check_all("posixpath") |
| 106 | self.check_all("pprint") |
Walter Dörwald | b1ded1e | 2003-04-15 11:10:33 +0000 | [diff] [blame] | 107 | self.check_all("profile") |
| 108 | self.check_all("pstats") |
| 109 | self.check_all("pty") |
| 110 | self.check_all("py_compile") |
| 111 | self.check_all("pyclbr") |
| 112 | self.check_all("quopri") |
| 113 | self.check_all("random") |
| 114 | self.check_all("re") |
Alexandre Vassalotti | 1f2ba4b | 2008-05-16 07:12:44 +0000 | [diff] [blame] | 115 | self.check_all("reprlib") |
Walter Dörwald | b1ded1e | 2003-04-15 11:10:33 +0000 | [diff] [blame] | 116 | self.check_all("rfc822") |
Raymond Hettinger | 2e973c0 | 2003-05-02 09:36:07 +0000 | [diff] [blame] | 117 | self.check_all("rlcompleter") |
Walter Dörwald | b1ded1e | 2003-04-15 11:10:33 +0000 | [diff] [blame] | 118 | self.check_all("robotparser") |
| 119 | self.check_all("sched") |
Walter Dörwald | b1ded1e | 2003-04-15 11:10:33 +0000 | [diff] [blame] | 120 | self.check_all("sgmllib") |
| 121 | self.check_all("shelve") |
| 122 | self.check_all("shlex") |
| 123 | self.check_all("shutil") |
| 124 | self.check_all("smtpd") |
| 125 | self.check_all("smtplib") |
| 126 | self.check_all("sndhdr") |
| 127 | self.check_all("socket") |
Raymond Hettinger | 2e973c0 | 2003-05-02 09:36:07 +0000 | [diff] [blame] | 128 | self.check_all("_strptime") |
Walter Dörwald | b1ded1e | 2003-04-15 11:10:33 +0000 | [diff] [blame] | 129 | self.check_all("symtable") |
| 130 | self.check_all("tabnanny") |
| 131 | self.check_all("tarfile") |
| 132 | self.check_all("telnetlib") |
| 133 | self.check_all("tempfile") |
Benjamin Peterson | 744c2cd | 2008-05-26 16:26:37 +0000 | [diff] [blame] | 134 | self.check_all("test.support") |
Walter Dörwald | b1ded1e | 2003-04-15 11:10:33 +0000 | [diff] [blame] | 135 | self.check_all("textwrap") |
| 136 | self.check_all("threading") |
Raymond Hettinger | 2e973c0 | 2003-05-02 09:36:07 +0000 | [diff] [blame] | 137 | self.check_all("timeit") |
Walter Dörwald | b1ded1e | 2003-04-15 11:10:33 +0000 | [diff] [blame] | 138 | self.check_all("tokenize") |
| 139 | self.check_all("traceback") |
| 140 | self.check_all("tty") |
Raymond Hettinger | 2d72b5d | 2003-09-16 04:37:39 +0000 | [diff] [blame] | 141 | self.check_all("unittest") |
Walter Dörwald | b1ded1e | 2003-04-15 11:10:33 +0000 | [diff] [blame] | 142 | self.check_all("urllib") |
| 143 | self.check_all("urlparse") |
| 144 | self.check_all("uu") |
| 145 | self.check_all("warnings") |
| 146 | self.check_all("wave") |
| 147 | self.check_all("weakref") |
| 148 | self.check_all("webbrowser") |
| 149 | self.check_all("xdrlib") |
| 150 | self.check_all("zipfile") |
Guido van Rossum | 06e2a5e | 2002-10-09 18:17:06 +0000 | [diff] [blame] | 151 | |
Walter Dörwald | b1ded1e | 2003-04-15 11:10:33 +0000 | [diff] [blame] | 152 | # rlcompleter needs special consideration; it import readline which |
| 153 | # initializes GNU readline which calls setlocale(LC_CTYPE, "")... :-( |
| 154 | try: |
| 155 | self.check_all("rlcompleter") |
| 156 | finally: |
| 157 | try: |
| 158 | import locale |
| 159 | except ImportError: |
| 160 | pass |
| 161 | else: |
| 162 | locale.setlocale(locale.LC_CTYPE, 'C') |
| 163 | |
| 164 | |
| 165 | def test_main(): |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 166 | run_unittest(AllTest) |
Walter Dörwald | b1ded1e | 2003-04-15 11:10:33 +0000 | [diff] [blame] | 167 | |
| 168 | if __name__ == "__main__": |
| 169 | test_main() |