Rev 5579: More use cases for overrideEnv, _cleanEnvironment *may* contain too much variables now. in file:///home/vila/src/bzr/bugs/690563-better-env-isolation/

Vincent Ladeuil v.ladeuil+lp at free.fr
Thu Dec 16 13:15:42 GMT 2010


At file:///home/vila/src/bzr/bugs/690563-better-env-isolation/

------------------------------------------------------------
revno: 5579
revision-id: v.ladeuil+lp at free.fr-20101216131542-607h4j3ww6i1vasu
parent: v.ladeuil+lp at free.fr-20101216121332-jkw1tj42izhxyt9z
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 690563-better-env-isolation
timestamp: Thu 2010-12-16 14:15:42 +0100
message:
  More use cases for overrideEnv, _cleanEnvironment *may* contain too much variables now.
-------------- next part --------------
=== modified file 'bzrlib/tests/blackbox/test_diff.py'
--- a/bzrlib/tests/blackbox/test_diff.py	2010-07-22 13:19:48 +0000
+++ b/bzrlib/tests/blackbox/test_diff.py	2010-12-16 13:15:42 +0000
@@ -386,8 +386,7 @@
         # subprocess.py that we had to workaround).
         # However, if 'diff' may not be available
         self.make_example_branch()
-        # this will be automatically restored by the base bzr test class
-        os.environ['BZR_PROGRESS_BAR'] = 'none'
+        self.overrideEnv('BZR_PROGRESS_BAR', 'none')
         out, err = self.run_bzr_subprocess('diff -r 1 --diff-options -ub',
                                            universal_newlines=True,
                                            retcode=None)

=== modified file 'bzrlib/tests/blackbox/test_non_ascii.py'
--- a/bzrlib/tests/blackbox/test_non_ascii.py	2010-12-09 04:26:53 +0000
+++ b/bzrlib/tests/blackbox/test_non_ascii.py	2010-12-16 13:15:42 +0000
@@ -42,7 +42,7 @@
 
         self.overrideAttr(osutils, '_cached_user_encoding', self.encoding)
         email = self.info['committer'] + ' <joe at foo.com>'
-        os.environ['BZR_EMAIL'] = email.encode(osutils.get_user_encoding())
+        self.overrideEnv('BZR_EMAIL', email.encode(osutils.get_user_encoding()))
         self.create_base()
 
     def run_bzr_decode(self, args, encoding=None, fail=False, retcode=None,

=== modified file 'bzrlib/tests/blackbox/test_too_much.py'
--- a/bzrlib/tests/blackbox/test_too_much.py	2010-06-11 07:32:12 +0000
+++ b/bzrlib/tests/blackbox/test_too_much.py	2010-12-16 13:15:42 +0000
@@ -315,37 +315,28 @@
         cmd_name = 'test-command'
         if sys.platform == 'win32':
             cmd_name += '.bat'
-        oldpath = os.environ.get('BZRPATH', None)
-        try:
-            if 'BZRPATH' in os.environ:
-                del os.environ['BZRPATH']
-
-            f = file(cmd_name, 'wb')
-            if sys.platform == 'win32':
-                f.write('@echo off\n')
-            else:
-                f.write('#!/bin/sh\n')
-            # f.write('echo Hello from test-command')
-            f.close()
-            os.chmod(cmd_name, 0755)
-
-            # It should not find the command in the local
-            # directory by default, since it is not in my path
-            self.run_bzr(cmd_name, retcode=3)
-
-            # Now put it into my path
-            os.environ['BZRPATH'] = '.'
-
-            self.run_bzr(cmd_name)
-
-            # Make sure empty path elements are ignored
-            os.environ['BZRPATH'] = os.pathsep
-
-            self.run_bzr(cmd_name, retcode=3)
-
-        finally:
-            if oldpath:
-                os.environ['BZRPATH'] = oldpath
+        self.overrideEnv('BZRPATH', None)
+
+        f = file(cmd_name, 'wb')
+        if sys.platform == 'win32':
+            f.write('@echo off\n')
+        else:
+            f.write('#!/bin/sh\n')
+        # f.write('echo Hello from test-command')
+        f.close()
+        os.chmod(cmd_name, 0755)
+
+        # It should not find the command in the local
+        # directory by default, since it is not in my path
+        self.run_bzr(cmd_name, retcode=3)
+
+        # Now put it into my path
+        self.overrideEnv('BZRPATH', '.')
+        self.run_bzr(cmd_name)
+
+        # Make sure empty path elements are ignored
+        self.overrideEnv('BZRPATH', os.pathsep)
+        self.run_bzr(cmd_name, retcode=3)
 
 
 def listdir_sorted(dir):

=== modified file 'bzrlib/tests/blackbox/test_whoami.py'
--- a/bzrlib/tests/blackbox/test_whoami.py	2010-06-23 08:19:28 +0000
+++ b/bzrlib/tests/blackbox/test_whoami.py	2010-12-16 13:15:42 +0000
@@ -52,7 +52,7 @@
 
         # Verify that the environment variable overrides the value
         # in the file
-        os.environ['BZR_EMAIL'] = 'Different ID <other at environ.ment>'
+        self.overrideEnv('BZR_EMAIL', 'Different ID <other at environ.ment>')
         whoami = self.run_bzr("whoami")[0]
         self.assertEquals('Different ID <other at environ.ment>\n', whoami)
         whoami_email = self.run_bzr("whoami --email")[0]

=== modified file 'bzrlib/tests/per_controldir/test_controldir.py'
--- a/bzrlib/tests/per_controldir/test_controldir.py	2010-11-26 17:59:08 +0000
+++ b/bzrlib/tests/per_controldir/test_controldir.py	2010-12-16 13:15:42 +0000
@@ -257,7 +257,7 @@
 
     def test_clone_bzrdir_branch_and_repo_fixed_user_id(self):
         # Bug #430868 is about an email containing '.sig'
-        os.environ['BZR_EMAIL'] = 'murphy at host.sighup.org'
+        self.overrideEnv('BZR_EMAIL', 'murphy at host.sighup.org')
         tree = self.make_branch_and_tree('commit_tree')
         self.build_tree(['commit_tree/foo'])
         tree.add('foo')

=== modified file 'bzrlib/tests/per_repository/test_check.py'
--- a/bzrlib/tests/per_repository/test_check.py	2010-02-17 17:11:16 +0000
+++ b/bzrlib/tests/per_repository/test_check.py	2010-12-16 13:15:42 +0000
@@ -135,7 +135,7 @@
         repo.lock_write()
         self.addCleanup(repo.unlock)
         config = _mod_config.Config()
-        os.environ['BZR_EMAIL'] = 'foo at sample.com'
+        self.overrideEnv('BZR_EMAIL', 'foo at sample.com')
         builder = repo.get_commit_builder(None, [], config)
         list(builder.record_iter_changes(None, _mod_revision.NULL_REVISION, [
             ('TREE_ROOT', (None, ''), True, (False, True), (None, None),

=== modified file 'bzrlib/tests/per_repository/test_commit_builder.py'
--- a/bzrlib/tests/per_repository/test_commit_builder.py	2010-10-15 16:43:03 +0000
+++ b/bzrlib/tests/per_repository/test_commit_builder.py	2010-12-16 13:15:42 +0000
@@ -1317,7 +1317,7 @@
     def test_committer_no_username(self):
         # Ensure that when no username is available but a committer is
         # supplied, commit works.
-        del os.environ['EMAIL']
+        self.overrideEnv('EMAIL', None)
         tree = self.make_branch_and_tree(".")
         tree.lock_write()
         try:

=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2010-12-16 12:13:32 +0000
+++ b/bzrlib/tests/test_config.py	2010-12-16 13:15:42 +0000
@@ -402,8 +402,8 @@
 
     def setUp(self):
         super(TestConfigPath, self).setUp()
-        os.environ['HOME'] = '/home/bogus'
-        os.environ['XDG_CACHE_DIR'] = ''
+        self.overrideEnv('HOME', '/home/bogus')
+        self.overrideEnv('XDG_CACHE_DIR', '')
         if sys.platform == 'win32':
             self.overrideEnv(
                 'BZR_HOME', r'C:\Documents and Settings\bogus\Application Data')
@@ -1308,7 +1308,7 @@
         self.assertEqual('bzr', my_config.get_bzr_remote_path())
         my_config.set_user_option('bzr_remote_path', '/path-bzr')
         self.assertEqual('/path-bzr', my_config.get_bzr_remote_path())
-        os.environ['BZR_REMOTE_PATH'] = '/environ-bzr'
+        self.overrideEnv('BZR_REMOTE_PATH', '/environ-bzr')
         self.assertEqual('/environ-bzr', my_config.get_bzr_remote_path())
 
 
@@ -1360,7 +1360,7 @@
         self.assertEqual("John", my_config._get_user_id())
 
     def test_BZR_EMAIL_OVERRIDES(self):
-        os.environ['BZR_EMAIL'] = "Robert Collins <robertc at example.org>"
+        self.overrideEnv('BZR_EMAIL', "Robert Collins <robertc at example.org>")
         branch = FakeBranch()
         my_config = config.BranchConfig(branch)
         self.assertEqual("Robert Collins <robertc at example.org>",

=== modified file 'bzrlib/tests/test_crash.py'
--- a/bzrlib/tests/test_crash.py	2010-04-08 04:34:03 +0000
+++ b/bzrlib/tests/test_crash.py	2010-12-16 13:15:42 +0000
@@ -40,7 +40,7 @@
     def test_apport_report(self):
         crash_dir = osutils.joinpath((self.test_base_dir, 'crash'))
         os.mkdir(crash_dir)
-        os.environ['APPORT_CRASH_DIR'] = crash_dir
+        self.overrideEnv('APPORT_CRASH_DIR', crash_dir)
         self.assertEquals(crash_dir, config.crash_dir())
 
         stderr = StringIO()

=== modified file 'bzrlib/tests/test_diff.py'
--- a/bzrlib/tests/test_diff.py	2010-05-26 15:58:08 +0000
+++ b/bzrlib/tests/test_diff.py	2010-12-16 13:15:42 +0000
@@ -144,31 +144,22 @@
         self.check_patch(lines)
 
     def test_external_diff_binary_lang_c(self):
-        old_env = {}
         for lang in ('LANG', 'LC_ALL', 'LANGUAGE'):
-            old_env[lang] = osutils.set_or_unset_env(lang, 'C')
-        try:
-            lines = external_udiff_lines(['\x00foobar\n'], ['foo\x00bar\n'])
-            # Older versions of diffutils say "Binary files", newer
-            # versions just say "Files".
-            self.assertContainsRe(lines[0],
-                                  '(Binary f|F)iles old and new differ\n')
-            self.assertEquals(lines[1:], ['\n'])
-        finally:
-            for lang, old_val in old_env.iteritems():
-                osutils.set_or_unset_env(lang, old_val)
+            self.overrideEnv(lang, 'C')
+        lines = external_udiff_lines(['\x00foobar\n'], ['foo\x00bar\n'])
+        # Older versions of diffutils say "Binary files", newer
+        # versions just say "Files".
+        self.assertContainsRe(lines[0], '(Binary f|F)iles old and new differ\n')
+        self.assertEquals(lines[1:], ['\n'])
 
     def test_no_external_diff(self):
         """Check that NoDiff is raised when diff is not available"""
-        # Use os.environ['PATH'] to make sure no 'diff' command is available
-        orig_path = os.environ['PATH']
-        try:
-            os.environ['PATH'] = ''
-            self.assertRaises(errors.NoDiff, diff.external_diff,
-                              'old', ['boo\n'], 'new', ['goo\n'],
-                              StringIO(), diff_opts=['-u'])
-        finally:
-            os.environ['PATH'] = orig_path
+        # Make sure no 'diff' command is available
+        # XXX: Weird, using None instead of '' breaks the test -- vila 20101216
+        self.overrideEnv('PATH', '')
+        self.assertRaises(errors.NoDiff, diff.external_diff,
+                          'old', ['boo\n'], 'new', ['goo\n'],
+                          StringIO(), diff_opts=['-u'])
 
     def test_internal_diff_default(self):
         # Default internal diff encoding is utf8

=== modified file 'bzrlib/tests/test_msgeditor.py'
--- a/bzrlib/tests/test_msgeditor.py	2010-11-11 13:45:02 +0000
+++ b/bzrlib/tests/test_msgeditor.py	2010-12-16 13:15:42 +0000
@@ -157,7 +157,7 @@
             return './fed.sh'
 
     def test_run_editor(self):
-        os.environ['BZR_EDITOR'] = self.make_do_nothing_editor()
+        self.overrideEnv('BZR_EDITOR', self.make_do_nothing_editor())
         self.assertEqual(True, msgeditor._run_editor(''),
                          'Unable to run dummy fake editor')
 
@@ -191,11 +191,11 @@
 "%s" fed.py %%1
 """ % sys.executable)
             f.close()
-            os.environ['BZR_EDITOR'] = 'fed.bat'
+            self.overrideEnv('BZR_EDITOR', 'fed.bat')
         else:
             # [non-win32] make python script executable and set BZR_EDITOR
             os.chmod('fed.py', 0755)
-            os.environ['BZR_EDITOR'] = './fed.py'
+            self.overrideEnv('BZR_EDITOR', './fed.py')
 
     def test_edit_commit_message(self):
         working_tree = self.make_uncommitted_tree()
@@ -230,16 +230,17 @@
         working_tree = self.make_uncommitted_tree()
 
         if sys.platform == 'win32':
-            os.environ['BZR_EDITOR'] = 'cmd.exe /c del'
+            editor = 'cmd.exe /c del'
         else:
-            os.environ['BZR_EDITOR'] = 'rm'
+            editor = 'rm'
+        self.overrideEnv('BZR_EDITOR', editor)
 
         self.assertRaises((IOError, OSError), msgeditor.edit_commit_message, '')
 
     def test__get_editor(self):
-        os.environ['BZR_EDITOR'] = 'bzr_editor'
-        os.environ['VISUAL'] = 'visual'
-        os.environ['EDITOR'] = 'editor'
+        self.overrideEnv('BZR_EDITOR', 'bzr_editor')
+        self.overrideEnv('VISUAL', 'visual')
+        self.overrideEnv('EDITOR', 'editor')
 
         conf = config.GlobalConfig.from_string('editor = config_editor\n',
                                                save=True)
@@ -259,7 +260,7 @@
 
     def test__run_editor_EACCES(self):
         """If running a configured editor raises EACESS, the user is warned."""
-        os.environ['BZR_EDITOR'] = 'eacces.py'
+        self.overrideEnv('BZR_EDITOR', 'eacces.py')
         f = file('eacces.py', 'wb')
         f.write('# Not a real editor')
         f.close()
@@ -267,7 +268,7 @@
         os.chmod('eacces.py', 0)
         # Set $EDITOR so that _run_editor will terminate before trying real
         # editors.
-        os.environ['EDITOR'] = self.make_do_nothing_editor()
+        self.overrideEnv('EDITOR', self.make_do_nothing_editor())
         # Call _run_editor, capturing mutter.warning calls.
         warnings = []
         def warning(*args):

=== modified file 'bzrlib/tests/test_osutils.py'
--- a/bzrlib/tests/test_osutils.py	2010-12-10 00:12:42 +0000
+++ b/bzrlib/tests/test_osutils.py	2010-12-16 13:15:42 +0000
@@ -1899,17 +1899,17 @@
         self.assertIsInstance(concurrency, int)
 
     def test_local_concurrency_environment_variable(self):
-        os.environ['BZR_CONCURRENCY'] = '2'
+        self.overrideEnv('BZR_CONCURRENCY', '2')
         self.assertEqual(2, osutils.local_concurrency(use_cache=False))
-        os.environ['BZR_CONCURRENCY'] = '3'
+        self.overrideEnv('BZR_CONCURRENCY', '3')
         self.assertEqual(3, osutils.local_concurrency(use_cache=False))
-        os.environ['BZR_CONCURRENCY'] = 'foo'
+        self.overrideEnv('BZR_CONCURRENCY', 'foo')
         self.assertEqual(1, osutils.local_concurrency(use_cache=False))
 
     def test_option_concurrency(self):
-        os.environ['BZR_CONCURRENCY'] = '1'
+        self.overrideEnv('BZR_CONCURRENCY', '1')
         self.run_bzr('rocks --concurrency 42')
-        # Command line overrides envrionment variable
+        # Command line overrides environment variable
         self.assertEquals('42', os.environ['BZR_CONCURRENCY'])
         self.assertEquals(42, osutils.local_concurrency(use_cache=False))
 
@@ -1985,19 +1985,19 @@
     def test_defaults_to_BZR_COLUMNS(self):
         # BZR_COLUMNS is set by the test framework
         self.assertNotEqual('12', os.environ['BZR_COLUMNS'])
-        os.environ['BZR_COLUMNS'] = '12'
+        self.overrideEnv('BZR_COLUMNS', '12')
         self.assertEqual(12, osutils.terminal_width())
 
     def test_falls_back_to_COLUMNS(self):
-        del os.environ['BZR_COLUMNS']
+        self.overrideEnv('BZR_COLUMNS', None)
         self.assertNotEqual('42', os.environ['COLUMNS'])
         self.set_fake_tty()
-        os.environ['COLUMNS'] = '42'
+        self.overrideEnv('COLUMNS', '42')
         self.assertEqual(42, osutils.terminal_width())
 
     def test_tty_default_without_columns(self):
-        del os.environ['BZR_COLUMNS']
-        del os.environ['COLUMNS']
+        self.overrideEnv('BZR_COLUMNS', None)
+        self.overrideEnv('COLUMNS', None)
 
         def terminal_size(w, h):
             return 42, 42
@@ -2010,8 +2010,8 @@
         self.assertEqual(42, osutils.terminal_width())
 
     def test_non_tty_default_without_columns(self):
-        del os.environ['BZR_COLUMNS']
-        del os.environ['COLUMNS']
+        self.overrideEnv('BZR_COLUMNS', None)
+        self.overrideEnv('COLUMNS', None)
         self.replace_stdout(None)
         self.assertEqual(None, osutils.terminal_width())
 
@@ -2027,8 +2027,8 @@
         else:
             self.overrideAttr(termios, 'TIOCGWINSZ')
             del termios.TIOCGWINSZ
-        del os.environ['BZR_COLUMNS']
-        del os.environ['COLUMNS']
+        self.overrideEnv('BZR_COLUMNS', None)
+        self.overrideEnv('COLUMNS', None)
         # Whatever the result is, if we don't raise an exception, it's ok.
         osutils.terminal_width()
 

=== modified file 'bzrlib/tests/test_osutils_encodings.py'
--- a/bzrlib/tests/test_osutils_encodings.py	2010-06-29 16:21:13 +0000
+++ b/bzrlib/tests/test_osutils_encodings.py	2010-12-16 13:15:42 +0000
@@ -216,7 +216,7 @@
             raise locale.Error, 'unsupported locale'
 
         locale.getpreferredencoding = f
-        os.environ['LANG'] = 'BOGUS'
+        self.overrideEnv('LANG', 'BOGUS')
         self.assertEquals('ascii', osutils.get_user_encoding(use_cache=False))
         self.assertEquals('bzr: warning: unsupported locale\n'
                           '  Could not determine what text encoding to use.\n'

=== modified file 'bzrlib/tests/test_plugins.py'
--- a/bzrlib/tests/test_plugins.py	2010-06-11 08:02:42 +0000
+++ b/bzrlib/tests/test_plugins.py	2010-12-16 13:15:42 +0000
@@ -656,7 +656,7 @@
                     self.fail('No path to global plugins')
 
     def test_get_standard_plugins_path_env(self):
-        os.environ['BZR_PLUGIN_PATH'] = 'foo/'
+        self.overrideEnv('BZR_PLUGIN_PATH', 'foo/')
         path = plugin.get_standard_plugins_path()
         for directory in path:
             self.assertNotContainsRe(directory, r'\\/$')

=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py	2010-12-16 10:14:43 +0000
+++ b/bzrlib/tests/test_selftest.py	2010-12-16 13:15:42 +0000
@@ -3387,10 +3387,9 @@
         result = tests.ExtendedTestResult(StringIO(), 0, 1)
         post_mortem_calls = []
         self.overrideAttr(pdb, "post_mortem", post_mortem_calls.append)
-        self.addCleanup(osutils.set_or_unset_env, "BZR_TEST_PDB",
-            osutils.set_or_unset_env("BZR_TEST_PDB", None))
+        self.overrideEnv('BZR_TEST_PDB', None)
         result._post_mortem(1)
-        os.environ["BZR_TEST_PDB"] = "on"
+        self.overrideEnv('BZR_TEST_PDB', 'on')
         result._post_mortem(2)
         self.assertEqual([2], post_mortem_calls)
 
@@ -3416,6 +3415,7 @@
 class TestEnvironHandling(tests.TestCase):
 
     def test__captureVar_None_called_twice_leaks(self):
+        self.failIf('MYVAR' in os.environ)
         self._captureVar('MYVAR', '42')
         # We need an embedded test to observe the bug
         class Test(tests.TestCase):
@@ -3437,6 +3437,7 @@
         self.assertEquals(None, self._old_env.get('MYVAR'))
 
     def test_overrideEnv_None_called_twice_doesnt_leak(self):
+        self.failIf('MYVAR' in os.environ)
         self.overrideEnv('MYVAR', '42')
         # We use an embedded test to make sure we fix the _captureVar bug
         class Test(tests.TestCase):

=== modified file 'bzrlib/tests/test_trace.py'
--- a/bzrlib/tests/test_trace.py	2010-10-11 09:53:16 +0000
+++ b/bzrlib/tests/test_trace.py	2010-12-16 13:15:42 +0000
@@ -301,9 +301,7 @@
         # set up.
         self.overrideAttr(sys, 'stderr', StringIO())
         # Set the log file to something that cannot exist
-        # FIXME: A bit dangerous: we are not in an isolated dir here -- vilajam
-        # 20100125
-        os.environ['BZR_LOG'] = os.getcwd() + '/no-dir/bzr.log'
+        self.overrideEnv('BZR_LOG', os.getcwd() + '/no-dir/bzr.log')
         self.overrideAttr(trace, '_bzr_log_filename')
         logf = trace._open_bzr_log()
         self.assertIs(None, logf)

=== modified file 'bzrlib/tests/test_transport.py'
--- a/bzrlib/tests/test_transport.py	2010-10-08 07:17:16 +0000
+++ b/bzrlib/tests/test_transport.py	2010-12-16 13:15:42 +0000
@@ -967,7 +967,7 @@
             bzr_remote_path = sys.executable + ' ' + self.get_bzr_path()
         else:
             bzr_remote_path = self.get_bzr_path()
-        os.environ['BZR_REMOTE_PATH'] = bzr_remote_path
+        self.overrideEnv('BZR_REMOTE_PATH', bzr_remote_path)
 
         # Access the branch via a bzr+ssh URL.  The BZR_REMOTE_PATH environment
         # variable is used to tell bzr what command to run on the remote end.

=== modified file 'bzrlib/tests/test_ui.py'
--- a/bzrlib/tests/test_ui.py	2010-12-02 10:41:05 +0000
+++ b/bzrlib/tests/test_ui.py	2010-12-16 13:15:42 +0000
@@ -158,7 +158,7 @@
     def test_text_factory_prompts_and_clears(self):
         # a get_boolean call should clear the pb before prompting
         out = test_progress._TTYStringIO()
-        os.environ['TERM'] = 'xterm'
+        self.overrideEnv('TERM', 'xterm')
         factory = _mod_ui_text.TextUIFactory(
             stdin=tests.StringIOWrapper("yada\ny\n"),
             stdout=out, stderr=out)
@@ -226,7 +226,7 @@
             pb.finished()
 
     def test_quietness(self):
-        os.environ['BZR_PROGRESS_BAR'] = 'text'
+        self.overrideEnv('BZR_PROGRESS_BAR', 'text')
         ui_factory = _mod_ui_text.TextUIFactory(None,
             test_progress._TTYStringIO(),
             test_progress._TTYStringIO())
@@ -313,12 +313,8 @@
             # however, it can still be forced on
             (FileStringIO, 'dumb', 'text', _mod_ui_text.TextProgressView),
             ):
-            os.environ['TERM'] = term
-            if pb is None:
-                if 'BZR_PROGRESS_BAR' in os.environ:
-                    del os.environ['BZR_PROGRESS_BAR']
-            else:
-                os.environ['BZR_PROGRESS_BAR'] = pb
+            self.overrideEnv('TERM', term)
+            self.overrideEnv('BZR_PROGRESS_BAR', pb)
             stdin = file_class('')
             stderr = file_class()
             stdout = file_class()
@@ -335,10 +331,7 @@
         stderr = test_progress._NonTTYStringIO()
         stdout = test_progress._NonTTYStringIO()
         for term_type in ['dumb', None, 'xterm']:
-            if term_type is None:
-                del os.environ['TERM']
-            else:
-                os.environ['TERM'] = term_type
+            self.overrideEnv('TERM', term_type)
             uif = _mod_ui.make_ui_for_terminal(stdin, stdout, stderr)
             self.assertIsInstance(uif, _mod_ui_text.TextUIFactory,
                 'TERM=%r' % (term_type,))



More information about the bazaar-commits mailing list