MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / env_modify

Function env_modify

test/common.py:164–181  ·  view source on GitHub ↗

A context manager that updates os.environ.

(updates)

Source from the content-addressed store, hash-verified

162
163@contextlib.contextmanager
164def env_modify(updates):
165 """A context manager that updates os.environ."""
166 # This could also be done with mock.patch.dict() but taking a dependency
167 # on the mock library is probably not worth the benefit.
168 old_env = os.environ.copy()
169 print("env_modify: " + str(updates))
170 # Setting a value to None means clear the environment variable
171 clears = [key for key, value in updates.items() if value is None]
172 updates = {key: value for key, value in updates.items() if value is not None}
173 os.environ.update(updates)
174 for key in clears:
175 if key in os.environ:
176 del os.environ[key]
177 try:
178 yield
179 finally:
180 os.environ.clear()
181 os.environ.update(old_env)
182
183
184def ensure_dir(dirname):

Callers 15

test_firstrunMethod · 0.90
test_emccMethod · 0.90
test_wacky_envMethod · 0.90
test_with_fakeMethod · 0.90
test_llvm_add_versionMethod · 0.90
test_empty_configMethod · 0.90
test_missing_configMethod · 0.90

Calls 4

updateMethod · 0.80
printFunction · 0.50
copyMethod · 0.45
clearMethod · 0.45

Tested by 15

test_firstrunMethod · 0.72
test_emccMethod · 0.72
test_wacky_envMethod · 0.72
test_with_fakeMethod · 0.72
test_llvm_add_versionMethod · 0.72
test_empty_configMethod · 0.72
test_missing_configMethod · 0.72