~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-09-23 06:50:13 UTC
  • mfrom: (2027.4.6 inventory-takes-file-3631)
  • Revision ID: pqm@pqm.ubuntu.com-20060923065013-b8483dd421706cbe
(jam) allow 'bzr inventory filename' (bug #3631)

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
 
19
import signal
18
20
import sys
19
21
 
20
22
import bzrlib
 
23
from bzrlib import (
 
24
    osutils,
 
25
    )
21
26
from bzrlib.errors import ParamikoNotPresent
22
27
from bzrlib.tests import (
23
28
                          TestCase,
172
177
                                      retcode=3)[1]
173
178
        self.assertContainsRe(err, 'No known merge type magic merge')
174
179
 
 
180
    def test_run_bzr_subprocess_env(self):
 
181
        """run_bzr_subprocess can set environment variables in the child only.
 
182
 
 
183
        These changes should not change the running process, only the child.
 
184
        """
 
185
        # The test suite should unset this variable
 
186
        self.assertEqual(None, os.environ.get('BZR_EMAIL'))
 
187
        out, err = self.run_bzr_subprocess('whoami', env_changes={
 
188
                                            'BZR_EMAIL':'Joe Foo <joe@foo.com>'
 
189
                                          }, universal_newlines=True)
 
190
        self.assertEqual('', err)
 
191
        self.assertEqual('Joe Foo <joe@foo.com>\n', out)
 
192
        # And it should not be modified
 
193
        self.assertEqual(None, os.environ.get('BZR_EMAIL'))
 
194
 
 
195
        # Do it again with a different address, just to make sure
 
196
        # it is actually changing
 
197
        out, err = self.run_bzr_subprocess('whoami', env_changes={
 
198
                                            'BZR_EMAIL':'Barry <bar@foo.com>'
 
199
                                          }, universal_newlines=True)
 
200
        self.assertEqual('', err)
 
201
        self.assertEqual('Barry <bar@foo.com>\n', out)
 
202
        self.assertEqual(None, os.environ.get('BZR_EMAIL'))
 
203
 
 
204
    def test_run_bzr_subprocess_env_del(self):
 
205
        """run_bzr_subprocess can remove environment variables too."""
 
206
        # Create a random email, so we are sure this won't collide
 
207
        rand_bzr_email = 'John Doe <jdoe@%s.com>' % (osutils.rand_chars(20),)
 
208
        rand_email = 'Jane Doe <jdoe@%s.com>' % (osutils.rand_chars(20),)
 
209
        os.environ['BZR_EMAIL'] = rand_bzr_email
 
210
        os.environ['EMAIL'] = rand_email
 
211
        try:
 
212
            # By default, the child will inherit the current env setting
 
213
            out, err = self.run_bzr_subprocess('whoami', universal_newlines=True)
 
214
            self.assertEqual('', err)
 
215
            self.assertEqual(rand_bzr_email + '\n', out)
 
216
 
 
217
            # Now that BZR_EMAIL is not set, it should fall back to EMAIL
 
218
            out, err = self.run_bzr_subprocess('whoami',
 
219
                                               env_changes={'BZR_EMAIL':None},
 
220
                                               universal_newlines=True)
 
221
            self.assertEqual('', err)
 
222
            self.assertEqual(rand_email + '\n', out)
 
223
 
 
224
            # This switches back to the default email guessing logic
 
225
            # Which shouldn't match either of the above addresses
 
226
            out, err = self.run_bzr_subprocess('whoami',
 
227
                           env_changes={'BZR_EMAIL':None, 'EMAIL':None},
 
228
                           universal_newlines=True)
 
229
 
 
230
            self.assertEqual('', err)
 
231
            self.assertNotEqual(rand_bzr_email + '\n', out)
 
232
            self.assertNotEqual(rand_email + '\n', out)
 
233
        finally:
 
234
            # TestCase cleans up BZR_EMAIL, and EMAIL at startup
 
235
            del os.environ['BZR_EMAIL']
 
236
            del os.environ['EMAIL']
 
237
 
 
238
    def test_run_bzr_subprocess_env_del_missing(self):
 
239
        """run_bzr_subprocess won't fail if deleting a nonexistant env var"""
 
240
        self.failIf('NON_EXISTANT_ENV_VAR' in os.environ)
 
241
        out, err = self.run_bzr_subprocess('rocks',
 
242
                        env_changes={'NON_EXISTANT_ENV_VAR':None},
 
243
                        universal_newlines=True)
 
244
        self.assertEqual('it sure does!\n', out)
 
245
        self.assertEqual('', err)
 
246
 
 
247
    def test_start_and_stop_bzr_subprocess(self):
 
248
        """We can start and perform other test actions while that process is
 
249
        still alive.
 
250
        """
 
251
        process = self.start_bzr_subprocess(['--version'])
 
252
        result = self.finish_bzr_subprocess(process)
 
253
        self.assertContainsRe(result[0], 'is free software')
 
254
        self.assertEqual('', result[1])
 
255
 
 
256
    def test_start_and_stop_bzr_subprocess_with_error(self):
 
257
        """finish_bzr_subprocess allows specification of the desired exit code.
 
258
        """
 
259
        process = self.start_bzr_subprocess(['--versionn'])
 
260
        result = self.finish_bzr_subprocess(process, retcode=3)
 
261
        self.assertEqual('', result[0])
 
262
        self.assertContainsRe(result[1], 'unknown command')
 
263
 
 
264
    def test_start_and_stop_bzr_subprocess_ignoring_retcode(self):
 
265
        """finish_bzr_subprocess allows the exit code to be ignored."""
 
266
        process = self.start_bzr_subprocess(['--versionn'])
 
267
        result = self.finish_bzr_subprocess(process, retcode=None)
 
268
        self.assertEqual('', result[0])
 
269
        self.assertContainsRe(result[1], 'unknown command')
 
270
 
 
271
    def test_start_and_stop_bzr_subprocess_with_unexpected_retcode(self):
 
272
        """finish_bzr_subprocess raises self.failureException if the retcode is
 
273
        not the expected one.
 
274
        """
 
275
        process = self.start_bzr_subprocess(['--versionn'])
 
276
        self.assertRaises(self.failureException, self.finish_bzr_subprocess,
 
277
                          process, retcode=0)
 
278
        
 
279
    def test_start_and_stop_bzr_subprocess_send_signal(self):
 
280
        """finish_bzr_subprocess raises self.failureException if the retcode is
 
281
        not the expected one.
 
282
        """
 
283
        process = self.start_bzr_subprocess(['wait-until-signalled'],
 
284
                                            skip_if_plan_to_signal=True)
 
285
        self.assertEqual('running\n', process.stdout.readline())
 
286
        result = self.finish_bzr_subprocess(process, send_signal=signal.SIGINT,
 
287
                                            retcode=3)
 
288
        self.assertEqual('', result[0])
 
289
        self.assertEqual('bzr: interrupted\n', result[1])
 
290
        
175
291
 
176
292
class TestRunBzrError(ExternalBase):
177
293