~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_selftest.py

  • Committer: John Arbash Meinel
  • Date: 2006-08-31 17:16:08 UTC
  • mfrom: (1977 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1978.
  • Revision ID: john@arbash-meinel.com-20060831171608-867aec563de12363
[merge] bzr.dev 1977

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
"""UI tests for the test framework."""
17
17
 
 
18
import os
18
19
import sys
19
20
 
20
21
import bzrlib
 
22
from bzrlib import (
 
23
    osutils,
 
24
    )
21
25
from bzrlib.errors import ParamikoNotPresent
22
26
from bzrlib.tests import (
23
27
                          TestCase,
172
176
                                      retcode=3)[1]
173
177
        self.assertContainsRe(err, 'No known merge type magic merge')
174
178
 
 
179
    def test_run_bzr_subprocess_env(self):
 
180
        """run_bzr_subprocess can set environment variables in the child only.
 
181
 
 
182
        These changes should not change the running process, only the child.
 
183
        """
 
184
        # The test suite should unset this variable
 
185
        self.assertEqual(None, os.environ.get('BZR_EMAIL'))
 
186
        out, err = self.run_bzr_subprocess('whoami', env_changes={
 
187
                                            'BZR_EMAIL':'Joe Foo <joe@foo.com>'
 
188
                                          })
 
189
        self.assertEqual('', err)
 
190
        self.assertEqual('Joe Foo <joe@foo.com>\n', out)
 
191
        # And it should not be modified
 
192
        self.assertEqual(None, os.environ.get('BZR_EMAIL'))
 
193
 
 
194
        # Do it again with a different address, just to make sure
 
195
        # it is actually changing
 
196
        out, err = self.run_bzr_subprocess('whoami', env_changes={
 
197
                                            'BZR_EMAIL':'Barry <bar@foo.com>'
 
198
                                          })
 
199
        self.assertEqual('', err)
 
200
        self.assertEqual('Barry <bar@foo.com>\n', out)
 
201
        self.assertEqual(None, os.environ.get('BZR_EMAIL'))
 
202
 
 
203
    def test_run_bzr_subprocess_env_del(self):
 
204
        """run_bzr_subprocess can remove environment variables too."""
 
205
        # Create a random email, so we are sure this won't collide
 
206
        rand_bzr_email = 'John Doe <jdoe@%s.com>' % (osutils.rand_chars(20),)
 
207
        rand_email = 'Jane Doe <jdoe@%s.com>' % (osutils.rand_chars(20),)
 
208
        os.environ['BZR_EMAIL'] = rand_bzr_email
 
209
        os.environ['EMAIL'] = rand_email
 
210
        try:
 
211
            # By default, the child will inherit the current env setting
 
212
            out, err = self.run_bzr_subprocess('whoami')
 
213
            self.assertEqual('', err)
 
214
            self.assertEqual(rand_bzr_email + '\n', out)
 
215
 
 
216
            # Now that BZR_EMAIL is not set, it should fall back to EMAIL
 
217
            out, err = self.run_bzr_subprocess('whoami',
 
218
                                               env_changes={'BZR_EMAIL':None})
 
219
            self.assertEqual('', err)
 
220
            self.assertEqual(rand_email + '\n', out)
 
221
 
 
222
            # This switches back to the default email guessing logic
 
223
            # Which shouldn't match either of the above addresses
 
224
            out, err = self.run_bzr_subprocess('whoami',
 
225
                           env_changes={'BZR_EMAIL':None, 'EMAIL':None})
 
226
 
 
227
            self.assertEqual('', err)
 
228
            self.assertNotEqual(rand_bzr_email + '\n', out)
 
229
            self.assertNotEqual(rand_email + '\n', out)
 
230
        finally:
 
231
            # TestCase cleans up BZR_EMAIL, and EMAIL at startup
 
232
            del os.environ['BZR_EMAIL']
 
233
            del os.environ['EMAIL']
175
234
 
176
235
class TestRunBzrError(ExternalBase):
177
236