Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
test.regrtest.saved_test_environment Class Reference

List of all members.

Public Member Functions

def __init__
def get_sys_argv
def restore_sys_argv
def get_cwd
def restore_cwd
def get_sys_stdout
def restore_sys_stdout
def get_sys_stderr
def restore_sys_stderr
def get_sys_stdin
def restore_sys_stdin
def get_os_environ
def restore_os_environ
def get_sys_path
def restore_sys_path
def get_sys_path_hooks
def restore_sys_path_hooks
def get___import__
def restore___import__
def get_warnings_filters
def restore_warnings_filters
def get_asyncore_socket_map
def restore_asyncore_socket_map
def get_logging__handlers
def restore_logging__handlers
def get_logging__handlerList
def restore_logging__handlerList
def get_sys_warnoptions
def restore_sys_warnoptions
def get_threading__dangling
def restore_threading__dangling
def get_multiprocessing_process__dangling
def restore_multiprocessing_process__dangling
def resource_info
def __enter__
def __exit__

Public Attributes

 testname
 verbose
 quiet
 saved_values

Static Public Attributes

 changed = False
tuple resources

Detailed Description

Save bits of the test environment and restore them at block exit.

    with saved_test_environment(testname, verbose, quiet):
        #stuff

Unless quiet is True, a warning is printed to stderr if any of
the saved items was changed by the test.  The attribute 'changed'
is initially False, but is set to True if a change is detected.

If verbose is more than 1, the before and after state of changed
items is also printed.

Definition at line 855 of file regrtest.py.


Constructor & Destructor Documentation

def test.regrtest.saved_test_environment.__init__ (   self,
  testname,
  verbose = 0,
  quiet = False 
)

Definition at line 871 of file regrtest.py.

00871 
00872     def __init__(self, testname, verbose=0, quiet=False):
00873         self.testname = testname
00874         self.verbose = verbose
00875         self.quiet = quiet

Here is the caller graph for this function:


Member Function Documentation

Definition at line 1011 of file regrtest.py.

01011 
01012     def __enter__(self):
01013         self.saved_values = dict((name, get()) for name, get, restore
01014                                                    in self.resource_info())
01015         return self

def test.regrtest.saved_test_environment.__exit__ (   self,
  exc_type,
  exc_val,
  exc_tb 
)

Definition at line 1016 of file regrtest.py.

01016 
01017     def __exit__(self, exc_type, exc_val, exc_tb):
01018         saved_values = self.saved_values
01019         del self.saved_values
01020         for name, get, restore in self.resource_info():
01021             current = get()
01022             original = saved_values.pop(name)
01023             # Check for changes to the resource's value
01024             if current != original:
01025                 self.changed = True
01026                 restore(original)
01027                 if not self.quiet:
01028                     print("Warning -- {} was modified by {}".format(
01029                                                  name, self.testname),
01030                                                  file=sys.stderr)
01031                     if self.verbose > 1:
01032                         print("  Before: {}\n  After:  {} ".format(
01033                                                   original, current),
01034                                                   file=sys.stderr)
01035         return False
01036 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 938 of file regrtest.py.

00938 
00939     def get___import__(self):
        return builtins.__import__

Definition at line 949 of file regrtest.py.

00949 
00950     def get_asyncore_socket_map(self):
00951         asyncore = sys.modules.get('asyncore')
00952         # XXX Making a copy keeps objects alive until __exit__ gets called.
        return asyncore and asyncore.socket_map.copy() or {}

Definition at line 899 of file regrtest.py.

00899 
00900     def get_cwd(self):
        return os.getcwd()

Definition at line 966 of file regrtest.py.

00966 
00967     def get_logging__handlerList(self):
00968         # _handlerList is a list of weakrefs to handlers
        return id(logging._handlerList), logging._handlerList, logging._handlerList[:]

Definition at line 959 of file regrtest.py.

00959 
00960     def get_logging__handlers(self):
00961         # _handlers is a WeakValueDictionary
        return id(logging._handlers), logging._handlers, logging._handlers.copy()

Definition at line 993 of file regrtest.py.

00993 
00994     def get_multiprocessing_process__dangling(self):
00995         if not multiprocessing:
00996             return None
00997         # This copies the weakrefs without making any strong reference
        return multiprocessing.process._dangling.copy()

Definition at line 919 of file regrtest.py.

00919 
00920     def get_os_environ(self):
        return id(os.environ), os.environ, dict(os.environ)

Definition at line 893 of file regrtest.py.

00893 
00894     def get_sys_argv(self):
        return id(sys.argv), sys.argv, sys.argv[:]

Definition at line 926 of file regrtest.py.

00926 
00927     def get_sys_path(self):
        return id(sys.path), sys.path, sys.path[:]

Definition at line 932 of file regrtest.py.

00932 
00933     def get_sys_path_hooks(self):
        return id(sys.path_hooks), sys.path_hooks, sys.path_hooks[:]

Definition at line 909 of file regrtest.py.

00909 
00910     def get_sys_stderr(self):
        return sys.stderr

Definition at line 914 of file regrtest.py.

00914 
00915     def get_sys_stdin(self):
        return sys.stdin

Definition at line 904 of file regrtest.py.

00904 
00905     def get_sys_stdout(self):
        return sys.stdout

Definition at line 973 of file regrtest.py.

00973 
00974     def get_sys_warnoptions(self):
        return id(sys.warnoptions), sys.warnoptions, sys.warnoptions[:]

Definition at line 981 of file regrtest.py.

00981 
00982     def get_threading__dangling(self):
00983         if not threading:
00984             return None
00985         # This copies the weakrefs without making any strong reference
        return threading._dangling.copy()

Definition at line 943 of file regrtest.py.

00943 
00944     def get_warnings_filters(self):
        return id(warnings.filters), warnings.filters, warnings.filters[:]

Definition at line 1004 of file regrtest.py.

01004 
01005     def resource_info(self):
01006         for name in self.resources:
01007             method_suffix = name.replace('.', '_')
01008             get_name = 'get_' + method_suffix
01009             restore_name = 'restore_' + method_suffix
01010             yield name, getattr(self, get_name), getattr(self, restore_name)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 940 of file regrtest.py.

00940 
00941     def restore___import__(self, import_):
00942         builtins.__import__ = import_

Definition at line 953 of file regrtest.py.

00953 
00954     def restore_asyncore_socket_map(self, saved_map):
00955         asyncore = sys.modules.get('asyncore')
00956         if asyncore is not None:
00957             asyncore.close_all(ignore_all=True)
00958             asyncore.socket_map.update(saved_map)

Here is the call graph for this function:

def test.regrtest.saved_test_environment.restore_cwd (   self,
  saved_cwd 
)

Definition at line 901 of file regrtest.py.

00901 
00902     def restore_cwd(self, saved_cwd):
00903         os.chdir(saved_cwd)

Definition at line 969 of file regrtest.py.

00969 
00970     def restore_logging__handlerList(self, saved_handlerList):
00971         # Can't easily revert the logging state
00972         pass

Definition at line 962 of file regrtest.py.

00962 
00963     def restore_logging__handlers(self, saved_handlers):
00964         # Can't easily revert the logging state
00965         pass

Definition at line 998 of file regrtest.py.

00998 
00999     def restore_multiprocessing_process__dangling(self, saved):
01000         if not multiprocessing:
01001             return
01002         multiprocessing.process._dangling.clear()
01003         multiprocessing.process._dangling.update(saved)

def test.regrtest.saved_test_environment.restore_os_environ (   self,
  saved_environ 
)

Definition at line 921 of file regrtest.py.

00921 
00922     def restore_os_environ(self, saved_environ):
00923         os.environ = saved_environ[1]
00924         os.environ.clear()
00925         os.environ.update(saved_environ[2])

Definition at line 895 of file regrtest.py.

00895 
00896     def restore_sys_argv(self, saved_argv):
00897         sys.argv = saved_argv[1]
00898         sys.argv[:] = saved_argv[2]

Definition at line 928 of file regrtest.py.

00928 
00929     def restore_sys_path(self, saved_path):
00930         sys.path = saved_path[1]
00931         sys.path[:] = saved_path[2]

Definition at line 934 of file regrtest.py.

00934 
00935     def restore_sys_path_hooks(self, saved_hooks):
00936         sys.path_hooks = saved_hooks[1]
00937         sys.path_hooks[:] = saved_hooks[2]

def test.regrtest.saved_test_environment.restore_sys_stderr (   self,
  saved_stderr 
)

Definition at line 911 of file regrtest.py.

00911 
00912     def restore_sys_stderr(self, saved_stderr):
00913         sys.stderr = saved_stderr

def test.regrtest.saved_test_environment.restore_sys_stdin (   self,
  saved_stdin 
)

Definition at line 916 of file regrtest.py.

00916 
00917     def restore_sys_stdin(self, saved_stdin):
00918         sys.stdin = saved_stdin

def test.regrtest.saved_test_environment.restore_sys_stdout (   self,
  saved_stdout 
)

Definition at line 906 of file regrtest.py.

00906 
00907     def restore_sys_stdout(self, saved_stdout):
00908         sys.stdout = saved_stdout

Definition at line 975 of file regrtest.py.

00975 
00976     def restore_sys_warnoptions(self, saved_options):
00977         sys.warnoptions = saved_options[1]
00978         sys.warnoptions[:] = saved_options[2]

Definition at line 986 of file regrtest.py.

00986 
00987     def restore_threading__dangling(self, saved):
00988         if not threading:
00989             return
00990         threading._dangling.clear()
00991         threading._dangling.update(saved)

Definition at line 945 of file regrtest.py.

00945 
00946     def restore_warnings_filters(self, saved_filters):
00947         warnings.filters = saved_filters[1]
00948         warnings.filters[:] = saved_filters[2]


Member Data Documentation

Definition at line 869 of file regrtest.py.

Definition at line 874 of file regrtest.py.

Initial value:
('sys.argv', 'cwd', 'sys.stdin', 'sys.stdout', 'sys.stderr',
                 'os.environ', 'sys.path', 'sys.path_hooks', '__import__',
                 'warnings.filters', 'asyncore.socket_map',
                 'logging._handlers', 'logging._handlerList',
                 'sys.warnoptions', 'threading._dangling',
                 'multiprocessing.process._dangling')

Definition at line 886 of file regrtest.py.

Definition at line 1012 of file regrtest.py.

Definition at line 872 of file regrtest.py.

Definition at line 873 of file regrtest.py.


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