173
177
self.assertContainsRe(err, 'No known merge type magic merge')
179
def test_run_bzr_subprocess_env(self):
180
"""run_bzr_subprocess can set environment variables in the child only.
182
These changes should not change the running process, only the child.
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>'
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'))
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>'
199
self.assertEqual('', err)
200
self.assertEqual('Barry <bar@foo.com>\n', out)
201
self.assertEqual(None, os.environ.get('BZR_EMAIL'))
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
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)
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)
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})
227
self.assertEqual('', err)
228
self.assertNotEqual(rand_bzr_email + '\n', out)
229
self.assertNotEqual(rand_email + '\n', out)
231
# TestCase cleans up BZR_EMAIL, and EMAIL at startup
232
del os.environ['BZR_EMAIL']
233
del os.environ['EMAIL']
176
235
class TestRunBzrError(ExternalBase):