/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/blackbox/test_selftest.py

  • Committer: Aaron Bentley
  • Date: 2007-02-06 14:52:16 UTC
  • mfrom: (2266 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2268.
  • Revision ID: abentley@panoramicfeedback.com-20070206145216-fcpi8o3ufvuzwbp9
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 by Canonical Ltd
 
1
# Copyright (C) 2005 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License version 2 as published by
5
 
# the Free Software Foundation.
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
6
7
#
7
8
# This program is distributed in the hope that it will be useful,
8
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
27
28
from bzrlib.tests import (
28
29
                          TestCase,
29
30
                          TestCaseInTempDir,
 
31
                          TestCaseWithMemoryTransport,
30
32
                          TestCaseWithTransport,
31
33
                          TestSkipped,
32
34
                          )
65
67
        except ParamikoNotPresent:
66
68
            raise TestSkipped("Paramiko not present")
67
69
        old_transport = bzrlib.tests.default_transport
68
 
        old_root = TestCaseInTempDir.TEST_ROOT
69
 
        TestCaseInTempDir.TEST_ROOT = None
 
70
        old_root = TestCaseWithMemoryTransport.TEST_ROOT
 
71
        TestCaseWithMemoryTransport.TEST_ROOT = None
70
72
        try:
71
73
            TestOptions.current_test = "test_transport_set_to_sftp"
72
74
            stdout = self.capture('selftest --transport=sftp test_transport_set_to_sftp')
81
83
        finally:
82
84
            bzrlib.tests.default_transport = old_transport
83
85
            TestOptions.current_test = None
84
 
            TestCaseInTempDir.TEST_ROOT = old_root
 
86
            TestCaseWithMemoryTransport.TEST_ROOT = old_root
85
87
 
86
88
 
87
89
class TestRunBzr(ExternalBase):
165
167
        """bzr selftest --benchmark should not run the default test suite."""
166
168
        # We test this by passing a regression test name to --benchmark, which
167
169
        # should result in 0 rests run.
168
 
        old_root = TestCaseInTempDir.TEST_ROOT
 
170
        old_root = TestCaseWithMemoryTransport.TEST_ROOT
169
171
        try:
170
 
            TestCaseInTempDir.TEST_ROOT = None
 
172
            TestCaseWithMemoryTransport.TEST_ROOT = None
171
173
            out, err = self.run_bzr('selftest', '--benchmark', 'workingtree_implementations')
172
174
        finally:
173
 
            TestCaseInTempDir.TEST_ROOT = old_root
 
175
            TestCaseWithMemoryTransport.TEST_ROOT = old_root
174
176
        self.assertContainsRe(out, 'Ran 0 tests.*\n\nOK')
175
177
        self.assertEqual(
176
 
            'running tests...\ntests passed\n',
 
178
            'tests passed\n',
177
179
            err)
178
180
        benchfile = open(".perf_history", "rt")
179
181
        try:
359
361
        self.assertEqual(cwd, osutils.getcwd())
360
362
 
361
363
 
 
364
class _DontSpawnProcess(Exception):
 
365
    """A simple exception which just allows us to skip unnecessary steps"""
 
366
 
 
367
 
 
368
class TestRunBzrSubprocessCommands(TestCaseWithTransport):
 
369
 
 
370
    def _popen(self, *args, **kwargs):
 
371
        """Record the command that is run, so that we can ensure it is correct"""
 
372
        self._popen_args = args
 
373
        self._popen_kwargs = kwargs
 
374
        raise _DontSpawnProcess()
 
375
 
 
376
    def test_run_bzr_subprocess_no_plugins(self):
 
377
        self.assertRaises(_DontSpawnProcess, self.run_bzr_subprocess)
 
378
        command = self._popen_args[0]
 
379
        self.assertEqual(sys.executable, command[0])
 
380
        self.assertEqual(self.get_bzr_path(), command[1])
 
381
        self.assertEqual(['--no-plugins'], command[2:])
 
382
 
 
383
    def test_allow_plugins(self):
 
384
        self.assertRaises(_DontSpawnProcess,
 
385
                          self.run_bzr_subprocess, allow_plugins=True)
 
386
        command = self._popen_args[0]
 
387
        self.assertEqual([], command[2:])
 
388
 
 
389
 
362
390
class TestBzrSubprocess(TestCaseWithTransport):
363
391
 
364
392
    def test_start_and_stop_bzr_subprocess(self):
411
439
        self.make_branch_and_tree('one')
412
440
 
413
441
        process = self.start_bzr_subprocess(['root'], working_dir='one')
414
 
        result = self.finish_bzr_subprocess(process)
 
442
        result = self.finish_bzr_subprocess(process, universal_newlines=True)
415
443
        self.assertEndsWith(result[0], 'one\n')
416
444
        self.assertEqual('', result[1])
417
 
        
 
445
 
418
446
 
419
447
class TestRunBzrError(ExternalBase):
420
448
 
422
450
        out, err = self.run_bzr_error(['^$'], 'rocks', retcode=0)
423
451
        self.assertEqual(out, 'it sure does!\n')
424
452
 
425
 
        out, err = self.run_bzr_error(["'foobarbaz' is not a versioned file"],
 
453
        out, err = self.run_bzr_error(["bzr: ERROR: foobarbaz is not versioned"],
426
454
                                      'file-id', 'foobarbaz')
 
455
 
 
456
 
 
457
class TestSelftestCleanOutput(TestCaseInTempDir):
 
458
 
 
459
    def test_clean_output(self):
 
460
        # check that 'bzr selftest --clean-output' works correct
 
461
        dirs = ('test0000.tmp', 'test0001.tmp', 'bzrlib', 'tests')
 
462
        files = ('bzr', 'setup.py', 'test9999.tmp')
 
463
        for i in dirs:
 
464
            os.mkdir(i)
 
465
        for i in files:
 
466
            f = file(i, 'wb')
 
467
            f.write('content of ')
 
468
            f.write(i)
 
469
            f.close()
 
470
 
 
471
        root = os.getcwdu()
 
472
        before = os.listdir(root)
 
473
        before.sort()
 
474
        self.assertEquals(['bzr','bzrlib','setup.py',
 
475
                           'test0000.tmp','test0001.tmp',
 
476
                           'test9999.tmp','tests'],
 
477
                           before)
 
478
 
 
479
        out,err = self.run_bzr_captured(['selftest','--clean-output'],
 
480
                                        working_dir=root)
 
481
 
 
482
        self.assertEquals(['delete directory: test0000.tmp',
 
483
                          'delete directory: test0001.tmp'],
 
484
                          sorted(out.splitlines()))
 
485
        self.assertEquals('', err)
 
486
 
 
487
        after = os.listdir(root)
 
488
        after.sort()
 
489
        self.assertEquals(['bzr','bzrlib','setup.py',
 
490
                           'test9999.tmp','tests'],
 
491
                           after)