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

Merge from TestCaseWithMemoryTransport.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import unittest
23
23
import warnings
24
24
 
25
 
from bzrlib import osutils
 
25
from bzrlib import osutils, memorytree
26
26
import bzrlib
27
27
from bzrlib.progress import _BaseProgressBar
28
28
from bzrlib.tests import (
29
29
                          ChrootedTestCase,
30
30
                          TestCase,
31
31
                          TestCaseInTempDir,
 
32
                          TestCaseWithMemoryTransport,
32
33
                          TestCaseWithTransport,
33
34
                          TestSkipped,
34
35
                          TestSuite,
35
36
                          TextTestRunner,
36
37
                          )
 
38
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
37
39
from bzrlib.tests.TestUtil import _load_module_by_name
38
40
import bzrlib.errors as errors
39
41
from bzrlib import symbol_versioning
40
42
from bzrlib.symbol_versioning import zero_ten, zero_eleven
41
43
from bzrlib.trace import note
 
44
from bzrlib.transport.memory import MemoryServer, MemoryTransport
42
45
from bzrlib.version import _get_bzr_source_tree
43
46
 
44
47
 
430
433
        self.assertEqual(self.test_home_dir, os.environ['HOME'])
431
434
 
432
435
 
 
436
class TestTestCaseWithMemoryTransport(TestCaseWithMemoryTransport):
 
437
 
 
438
    def test_home_is_non_existant_dir_under_root(self):
 
439
        """The test_home_dir for TestCaseWithMemoryTransport is missing.
 
440
 
 
441
        This is because TestCaseWithMemoryTransport is for tests that do not
 
442
        need any disk resources: they should be hooked into bzrlib in such a 
 
443
        way that no global settings are being changed by the test (only a 
 
444
        few tests should need to do that), and having a missing dir as home is
 
445
        an effective way to ensure that this is the case.
 
446
        """
 
447
        self.assertEqual(self.TEST_ROOT + "/MemoryTransportMissingHomeDir",
 
448
            self.test_home_dir)
 
449
        self.assertEqual(self.test_home_dir, os.environ['HOME'])
 
450
        
 
451
    def test_cwd_is_TEST_ROOT(self):
 
452
        self.assertEqual(self.test_dir, self.TEST_ROOT)
 
453
        cwd = osutils.getcwd()
 
454
        self.assertEqual(self.test_dir, cwd)
 
455
 
 
456
    def test_make_branch_and_memory_tree(self):
 
457
        """In TestCaseWithMemoryTransport we should not make the branch on disk.
 
458
 
 
459
        This is hard to comprehensively robustly test, so we settle for making
 
460
        a branch and checking no directory was created at its relpath.
 
461
        """
 
462
        tree = self.make_branch_and_memory_tree('dir')
 
463
        self.failIfExists('dir')
 
464
        self.assertIsInstance(tree, memorytree.MemoryTree)
 
465
 
 
466
 
433
467
class TestTestCaseWithTransport(TestCaseWithTransport):
434
468
    """Tests for the convenience functions TestCaseWithTransport introduces."""
435
469
 
474
508
        self.assertRaises(AssertionError, self.assertIsDirectory, 'not_here', t)
475
509
 
476
510
 
 
511
class TestTestCaseTransports(TestCaseWithTransport):
 
512
 
 
513
    def setUp(self):
 
514
        super(TestTestCaseTransports, self).setUp()
 
515
        self.transport_server = MemoryServer
 
516
 
 
517
    def test_make_bzrdir_preserves_transport(self):
 
518
        t = self.get_transport()
 
519
        result_bzrdir = self.make_bzrdir('subdir')
 
520
        self.assertIsInstance(result_bzrdir.transport, 
 
521
                              MemoryTransport)
 
522
        # should not be on disk, should only be in memory
 
523
        self.failIfExists('subdir')
 
524
 
 
525
 
477
526
class TestChrootedTest(ChrootedTestCase):
478
527
 
479
528
    def test_root_is_root(self):
729
778
        output_string = output.getvalue()
730
779
        self.assertContainsRe(output_string, "--date [0-9.]+")
731
780
        if workingtree is not None:
732
 
            revision_id = workingtree.last_revision()
 
781
            revision_id = workingtree.get_parent_ids()[0]
733
782
            self.assertEndsWith(output_string.rstrip(), revision_id)
734
783
 
735
784
 
910
959
        self.assertIsInstance(tree, bzrlib.memorytree.MemoryTree)
911
960
 
912
961
 
 
962
class TestSFTPMakeBranchAndTree(TestCaseWithSFTPServer):
 
963
 
 
964
    def test_make_tree_for_sftp_branch(self):
 
965
        """Transports backed by local directories create local trees."""
 
966
 
 
967
        tree = self.make_branch_and_tree('t1')
 
968
        base = tree.bzrdir.root_transport.base
 
969
        self.failIf(base.startswith('sftp'),
 
970
                'base %r is on sftp but should be local' % base)
 
971
        self.assertEquals(tree.bzrdir.root_transport,
 
972
                tree.branch.bzrdir.root_transport)
 
973
        self.assertEquals(tree.bzrdir.root_transport,
 
974
                tree.branch.repository.bzrdir.root_transport)
 
975
 
 
976
 
913
977
class TestSelftest(TestCase):
914
978
    """Tests of bzrlib.tests.selftest."""
915
979