/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: John Arbash Meinel
  • Date: 2006-09-05 14:11:57 UTC
  • mto: This revision was merged to the branch mainline in revision 1990.
  • Revision ID: john@arbash-meinel.com-20060905141157-09649d57bb9cf247
Switch to directly setting the env, and cleaning it up. So that it works on all platforms

Show diffs side-by-side

added added

removed removed

Lines of Context:
837
837
            child, so you don't need to fix the environment after running.
838
838
        """
839
839
        env_changes = kwargs.get('env_changes', {})
 
840
 
 
841
        old_env = {}
 
842
 
840
843
        def cleanup_environment():
841
844
            for env_var, value in env_changes.iteritems():
842
 
                old_val = osutils.set_or_unset_env(env_var, value)
 
845
                old_env[env_var] = osutils.set_or_unset_env(env_var, value)
 
846
 
 
847
        def restore_environment():
 
848
            for env_var, value in old_env.iteritems():
 
849
                osutils.set_or_unset_env(env_var, value)
843
850
 
844
851
        bzr_path = os.path.dirname(os.path.dirname(bzrlib.__file__))+'/bzr'
845
852
        args = list(args)
846
 
        process = Popen([sys.executable, bzr_path]+args,
847
 
                         stdout=PIPE, stderr=PIPE,
848
 
                         preexec_fn=cleanup_environment)
 
853
 
 
854
        try:
 
855
            # win32 subprocess doesn't support preexec_fn
 
856
            # so we will avoid using it on all platforms, just to
 
857
            # make sure the code path is used, and we don't break on win32
 
858
            cleanup_environment()
 
859
            process = Popen([sys.executable, bzr_path]+args,
 
860
                             stdout=PIPE, stderr=PIPE)
 
861
        finally:
 
862
            restore_environment()
 
863
            
849
864
        out = process.stdout.read()
850
865
        err = process.stderr.read()
851
866
        retcode = process.wait()