def ensure_context_manager():
     before()
     with modified_environ(**kwargs):
         during()
     after()
Ejemplo n.º 2
0
import os
from pollute import modified_environ


assert 'HELLO' not in os.environ
assert 'PATH' in os.environ

with modified_environ(added={'HELLO': 'WORLD'}, absent=['PATH']):
    assert os.environ['HELLO'] == 'WORLD'
    assert 'PATH' not in os.environ

assert 'HELLO' not in os.environ
assert 'PATH' in os.environ
Ejemplo n.º 3
0
import os
from pollute import modified_environ

assert 'HELLO' not in os.environ
assert 'PATH' in os.environ

with modified_environ(added={'HELLO': 'WORLD'}, absent=['PATH']):
    assert os.environ['HELLO'] == 'WORLD'
    assert 'PATH' not in os.environ

assert 'HELLO' not in os.environ
assert 'PATH' in os.environ
Ejemplo n.º 4
0
def environment(added=None, absent=()):
    """Context manager that modifies the environments variables.
    Path objects as values are replaced with strings.
    """
    added = stringify_dict(added or {})
    return pollute.modified_environ(added, absent)
 def ensure_context_manager():
     before()
     with modified_environ(**kwargs):
         during()
     after()