@contextmanager
def check_environ(unset=True):
 with mock.patch.dict(os.environ):
  old_fds = os.environ.get('LISTEN_FDS', None)
  old_pid = os.environ.get('LISTEN_PID', None)
  (yield)
  if unset:
   assert ('LISTEN_FDS' not in os.environ), 'LISTEN_FDS should have been unset'
   assert ('LISTEN_PID' not in os.environ), 'LISTEN_PID should have been unset'
  else:
   new_fds = os.environ.get('LISTEN_FDS', None)
   new_pid = os.environ.get('LISTEN_PID', None)
   assert (new_fds == old_fds), 'LISTEN_FDS should not have been changed'
   assert (new_pid == old_pid), 'LISTEN_PID should not have been changed'

@ contextmanager def check_environ ( unset = True ) : with mock . patch . dict ( os . environ ) : old_fds = os . environ . get ( 'LISTEN_FDS' , None ) old_pid = os . environ . get ( 'LISTEN_PID' , None ) ( yield ) if unset : assert ( 'LISTEN_FDS' not in os . environ ) , 'LISTEN_FDS should have been unset' assert ( 'LISTEN_PID' not in os . environ ) , 'LISTEN_PID should have been unset' else : new_fds = os . environ . get ( 'LISTEN_FDS' , None ) new_pid = os . environ . get ( 'LISTEN_PID' , None ) assert ( new_fds == old_fds ) , 'LISTEN_FDS should not have been changed' assert ( new_pid == old_pid ) , 'LISTEN_PID should not have been changed'
ensure that os .