PageRenderTime 172ms CodeModel.GetById 20ms app.highlight 39ms RepoModel.GetById 11ms app.codeStats 0ms

/Lib/test/test___all__.py

http://unladen-swallow.googlecode.com/
Python | 184 lines | 168 code | 10 blank | 6 comment | 7 complexity | e1f164644a9516f371eb48d56b4b6cf9 MD5 | raw file
  1import unittest
  2from test.test_support import run_unittest
  3import sys
  4import warnings
  5
  6
  7
  8class AllTest(unittest.TestCase):
  9
 10    def check_all(self, modname):
 11        names = {}
 12        with warnings.catch_warnings():
 13            warnings.filterwarnings("ignore", ".* (module|package)",
 14                                    DeprecationWarning)
 15            try:
 16                exec "import %s" % modname in names
 17            except ImportError:
 18                # Silent fail here seems the best route since some modules
 19                # may not be available in all environments.
 20                return
 21        self.failUnless(hasattr(sys.modules[modname], "__all__"),
 22                        "%s has no __all__ attribute" % modname)
 23        names = {}
 24        exec "from %s import *" % modname in names
 25        if "__builtins__" in names:
 26            del names["__builtins__"]
 27        keys = set(names)
 28        all = set(sys.modules[modname].__all__)
 29        self.assertEqual(keys, all)
 30
 31    def test_all(self):
 32        if not sys.platform.startswith('java'):
 33            # In case _socket fails to build, make this test fail more gracefully
 34            # than an AttributeError somewhere deep in CGIHTTPServer.
 35            import _socket
 36
 37        self.check_all("BaseHTTPServer")
 38        self.check_all("Bastion")
 39        self.check_all("CGIHTTPServer")
 40        self.check_all("ConfigParser")
 41        self.check_all("Cookie")
 42        self.check_all("MimeWriter")
 43        self.check_all("Queue")
 44        self.check_all("SimpleHTTPServer")
 45        self.check_all("SocketServer")
 46        self.check_all("StringIO")
 47        self.check_all("UserString")
 48        self.check_all("aifc")
 49        self.check_all("atexit")
 50        self.check_all("audiodev")
 51        self.check_all("base64")
 52        self.check_all("bdb")
 53        self.check_all("binhex")
 54        self.check_all("calendar")
 55        self.check_all("cgi")
 56        self.check_all("cmd")
 57        self.check_all("code")
 58        self.check_all("codecs")
 59        self.check_all("codeop")
 60        self.check_all("colorsys")
 61        self.check_all("commands")
 62        self.check_all("compileall")
 63        self.check_all("copy")
 64        self.check_all("copy_reg")
 65        self.check_all("csv")
 66        self.check_all("dbhash")
 67        self.check_all("decimal")
 68        self.check_all("difflib")
 69        self.check_all("dircache")
 70        self.check_all("dis")
 71        self.check_all("doctest")
 72        self.check_all("dummy_thread")
 73        self.check_all("dummy_threading")
 74        self.check_all("filecmp")
 75        self.check_all("fileinput")
 76        self.check_all("fnmatch")
 77        self.check_all("fpformat")
 78        self.check_all("ftplib")
 79        self.check_all("getopt")
 80        self.check_all("getpass")
 81        self.check_all("gettext")
 82        self.check_all("glob")
 83        self.check_all("gzip")
 84        self.check_all("heapq")
 85        self.check_all("htmllib")
 86        self.check_all("httplib")
 87        self.check_all("ihooks")
 88        self.check_all("imaplib")
 89        self.check_all("imghdr")
 90        self.check_all("imputil")
 91        self.check_all("keyword")
 92        self.check_all("linecache")
 93        self.check_all("locale")
 94        self.check_all("logging")
 95        self.check_all("macpath")
 96        self.check_all("macurl2path")
 97        self.check_all("mailbox")
 98        self.check_all("mailcap")
 99        self.check_all("mhlib")
100        self.check_all("mimetools")
101        self.check_all("mimetypes")
102        self.check_all("mimify")
103        self.check_all("multifile")
104        self.check_all("netrc")
105        self.check_all("nntplib")
106        self.check_all("ntpath")
107        self.check_all("opcode")
108        self.check_all("optparse")
109        self.check_all("os")
110        self.check_all("os2emxpath")
111        self.check_all("pdb")
112        self.check_all("pickle")
113        self.check_all("pickletools")
114        self.check_all("pipes")
115        self.check_all("popen2")
116        self.check_all("poplib")
117        self.check_all("posixpath")
118        self.check_all("pprint")
119        self.check_all("profile")
120        self.check_all("pstats")
121        self.check_all("pty")
122        self.check_all("py_compile")
123        self.check_all("pyclbr")
124        self.check_all("quopri")
125        self.check_all("random")
126        self.check_all("re")
127        self.check_all("repr")
128        self.check_all("rexec")
129        self.check_all("rfc822")
130        self.check_all("rlcompleter")
131        self.check_all("robotparser")
132        self.check_all("sched")
133        self.check_all("sets")
134        self.check_all("sgmllib")
135        self.check_all("shelve")
136        self.check_all("shlex")
137        self.check_all("shutil")
138        self.check_all("smtpd")
139        self.check_all("smtplib")
140        self.check_all("sndhdr")
141        self.check_all("socket")
142        self.check_all("_strptime")
143        self.check_all("symtable")
144        self.check_all("tabnanny")
145        self.check_all("tarfile")
146        self.check_all("telnetlib")
147        self.check_all("tempfile")
148        self.check_all("test.test_support")
149        self.check_all("textwrap")
150        self.check_all("threading")
151        self.check_all("timeit")
152        self.check_all("toaiff")
153        self.check_all("tokenize")
154        self.check_all("traceback")
155        self.check_all("tty")
156        self.check_all("unittest")
157        self.check_all("urllib")
158        self.check_all("urlparse")
159        self.check_all("uu")
160        self.check_all("warnings")
161        self.check_all("wave")
162        self.check_all("weakref")
163        self.check_all("webbrowser")
164        self.check_all("xdrlib")
165        self.check_all("zipfile")
166
167        # rlcompleter needs special consideration; it import readline which
168        # initializes GNU readline which calls setlocale(LC_CTYPE, "")... :-(
169        try:
170            self.check_all("rlcompleter")
171        finally:
172            try:
173                import locale
174            except ImportError:
175                pass
176            else:
177                locale.setlocale(locale.LC_CTYPE, 'C')
178
179
180def test_main():
181    run_unittest(AllTest)
182
183if __name__ == "__main__":
184    test_main()