~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: John Arbash Meinel
  • Date: 2006-08-28 16:00:08 UTC
  • mto: (1955.2.7 locale-35392)
  • mto: This revision was merged to the branch mainline in revision 1974.
  • Revision ID: john@arbash-meinel.com-20060828160008-030ae3ee0524bd43
run_bzr_subprocess() can take an env_changes parameter

This lets us set explicit environment variables in the spawned bzr instance

Show diffs side-by-side

added added

removed removed

Lines of Context:
843
843
        profiled or debugged so easily.
844
844
 
845
845
        :param retcode: The status code that is expected.  Defaults to 0.  If
846
 
        None is supplied, the status code is not checked.
 
846
            None is supplied, the status code is not checked.
 
847
        :param env_changes: A dictionary which lists changes to environment
 
848
            variables. A value of None will unset the env variable.
 
849
            The values must be strings. The change will only occur in the
 
850
            child, so you don't need to fix the environment after running.
847
851
        """
 
852
        env_changes = kwargs.get('env_changes', None)
 
853
        preexec_func = None
 
854
        if env_changes:
 
855
            def cleanup_environment():
 
856
                for env_var, value in env_changes.iteritems():
 
857
                    if value is None:
 
858
                        del os.environ[env_var]
 
859
                    else:
 
860
                        os.environ[env_var] = value
 
861
            preexec_func = cleanup_environment
 
862
 
848
863
        bzr_path = os.path.dirname(os.path.dirname(bzrlib.__file__))+'/bzr'
849
864
        args = list(args)
850
 
        process = Popen([sys.executable, bzr_path]+args, stdout=PIPE, 
851
 
                         stderr=PIPE)
 
865
        process = Popen([sys.executable, bzr_path]+args,
 
866
                         stdout=PIPE, stderr=PIPE,
 
867
                         preexec_fn=preexec_func)
852
868
        out = process.stdout.read()
853
869
        err = process.stderr.read()
854
870
        retcode = process.wait()