MCPcopy Index your code
hub / github.com/RustPython/RustPython / saved_test_environment

Class saved_test_environment

Lib/test/libregrtest/save_env.py:32–361  ·  view source on GitHub ↗

Save bits of the test environment and restore them at block exit. with saved_test_environment(test_name, 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 support.environment_altered a

Source from the content-addressed store, hash-verified

30# the following context manager handles this task.
31
32class saved_test_environment:
33 """Save bits of the test environment and restore them at block exit.
34
35 with saved_test_environment(test_name, verbose, quiet):
36 #stuff
37
38 Unless quiet is True, a warning is printed to stderr if any of
39 the saved items was changed by the test. The support.environment_altered
40 attribute is set to True if a change is detected.
41
42 If verbose is more than 1, the before and after state of changed
43 items is also printed.
44 """
45
46 def __init__(self, test_name, verbose, quiet, *, pgo):
47 self.test_name = test_name
48 self.verbose = verbose
49 self.quiet = quiet
50 self.pgo = pgo
51
52 # To add things to save and restore, add a name XXX to the resources list
53 # and add corresponding get_XXX/restore_XXX functions. get_XXX should
54 # return the value to be saved and compared against a second call to the
55 # get function when test execution completes. restore_XXX should accept
56 # the saved value and restore the resource using it. It will be called if
57 # and only if a change in the value is detected.
58 #
59 # Note: XXX will have any '.' replaced with '_' characters when determining
60 # the corresponding method names.
61
62 resources = ('sys.argv', 'cwd', 'sys.stdin', 'sys.stdout', 'sys.stderr',
63 'os.environ', 'sys.path', 'sys.path_hooks', '__import__',
64 'warnings.filters', 'asyncore.socket_map',
65 'logging._handlers', 'logging._handlerList', 'sys.gettrace',
66 'sys.warnoptions',
67 # multiprocessing.process._cleanup() may release ref
68 # to a thread, so check processes first.
69 'multiprocessing.process._dangling', 'threading._dangling',
70 'sysconfig._CONFIG_VARS', 'sysconfig._INSTALL_SCHEMES',
71 'files', 'locale', 'warnings.showwarning',
72 'shutil_archive_formats', 'shutil_unpack_formats',
73 'asyncio.events._event_loop_policy',
74 'urllib.requests._url_tempfiles', 'urllib.requests._opener',
75 'stty_echo',
76 )
77
78 def get_module(self, name):
79 # function for restore() methods
80 return sys.modules[name]
81
82 def try_get_module(self, name):
83 # function for get() methods
84 try:
85 return self.get_module(name)
86 except KeyError:
87 raise SkipTestEnvironment
88
89 def get_urllib_requests__url_tempfiles(self):

Callers 1

_runtest_env_changed_excFunction · 0.85

Calls 3

getattrFunction · 0.85
dirFunction · 0.85
startswithMethod · 0.45

Tested by

no test coverage detected