Back to index

python3.2  3.2.2
Public Member Functions
test.test___all__.AllTest Class Reference

List of all members.

Public Member Functions

def check_all
def walk_modules
def test_all

Detailed Description

Definition at line 14 of file test___all__.py.


Member Function Documentation

def test.test___all__.AllTest.check_all (   self,
  modname 
)

Definition at line 16 of file test___all__.py.

00016 
00017     def check_all(self, modname):
00018         names = {}
00019         with support.check_warnings(
00020             (".* (module|package)", DeprecationWarning),
00021             ("", ResourceWarning),
00022             quiet=True):
00023             try:
00024                 exec("import %s" % modname, names)
00025             except:
00026                 # Silent fail here seems the best route since some modules
00027                 # may not be available or not initialize properly in all
00028                 # environments.
00029                 raise FailedImport(modname)
00030         if not hasattr(sys.modules[modname], "__all__"):
00031             raise NoAll(modname)
00032         names = {}
00033         try:
00034             exec("from %s import *" % modname, names)
00035         except Exception as e:
00036             # Include the module name in the exception string
00037             self.fail("__all__ failure in {}: {}: {}".format(
00038                       modname, e.__class__.__name__, e))
00039         if "__builtins__" in names:
00040             del names["__builtins__"]
00041         keys = set(names)
00042         all = set(sys.modules[modname].__all__)
00043         self.assertEqual(keys, all)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 58 of file test___all__.py.

00058 
00059     def test_all(self):
00060         # Blacklisted modules and packages
00061         blacklist = set([
00062             # Will raise a SyntaxError when compiling the exec statement
00063             '__future__',
00064         ])
00065 
00066         if not sys.platform.startswith('java'):
00067             # In case _socket fails to build, make this test fail more gracefully
00068             # than an AttributeError somewhere deep in CGIHTTPServer.
00069             import _socket
00070 
00071         # rlcompleter needs special consideration; it import readline which
00072         # initializes GNU readline which calls setlocale(LC_CTYPE, "")... :-(
00073         try:
00074             import rlcompleter
00075             import locale
00076         except ImportError:
00077             pass
00078         else:
00079             locale.setlocale(locale.LC_CTYPE, 'C')
00080 
00081         ignored = []
00082         failed_imports = []
00083         lib_dir = os.path.dirname(os.path.dirname(__file__))
00084         for path, modname in self.walk_modules(lib_dir, ""):
00085             m = modname
00086             blacklisted = False
00087             while m:
00088                 if m in blacklist:
00089                     blacklisted = True
00090                     break
00091                 m = m.rpartition('.')[0]
00092             if blacklisted:
00093                 continue
00094             if support.verbose:
00095                 print(modname)
00096             try:
00097                 # This heuristic speeds up the process by removing, de facto,
00098                 # most test modules (and avoiding the auto-executing ones).
00099                 with open(path, "rb") as f:
00100                     if b"__all__" not in f.read():
00101                         raise NoAll(modname)
00102                     self.check_all(modname)
00103             except NoAll:
00104                 ignored.append(modname)
00105             except FailedImport:
00106                 failed_imports.append(modname)
00107 
00108         if support.verbose:
00109             print('Following modules have no __all__ and have been ignored:',
00110                   ignored)
00111             print('Following modules failed to be imported:', failed_imports)
00112 

Here is the call graph for this function:

def test.test___all__.AllTest.walk_modules (   self,
  basedir,
  modpath 
)

Definition at line 44 of file test___all__.py.

00044 
00045     def walk_modules(self, basedir, modpath):
00046         for fn in sorted(os.listdir(basedir)):
00047             path = os.path.join(basedir, fn)
00048             if os.path.isdir(path):
00049                 pkg_init = os.path.join(path, '__init__.py')
00050                 if os.path.exists(pkg_init):
00051                     yield pkg_init, modpath + fn
00052                     for p, m in self.walk_modules(path, modpath + fn + "."):
00053                         yield p, m
00054                 continue
00055             if not fn.endswith('.py') or fn == '__init__.py':
00056                 continue
00057             yield path, modpath + fn[:-3]

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following file: