~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-08-25 19:58:55 UTC
  • mfrom: (1551.8.13 Aaron's mergeable stuff)
  • Revision ID: pqm@pqm.ubuntu.com-20060825195855-d79a4429a72ddf7e
Nicer output for gpg-signed commits

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
                          TestSuite,
35
35
                          TextTestRunner,
36
36
                          )
37
 
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
38
37
from bzrlib.tests.TestUtil import _load_module_by_name
39
38
import bzrlib.errors as errors
40
39
from bzrlib import symbol_versioning
41
 
from bzrlib.symbol_versioning import zero_ten, zero_eleven
42
40
from bzrlib.trace import note
43
 
from bzrlib.transport.memory import MemoryServer, MemoryTransport
44
41
from bzrlib.version import _get_bzr_source_tree
45
42
 
46
43
 
422
419
        self.assertEqual(tests[1].transport_server, server1)
423
420
        self.assertEqual(tests[1].transport_readonly_server, server2)
424
421
 
425
 
 
426
 
class TestTestCaseInTempDir(TestCaseInTempDir):
427
 
 
428
 
    def test_home_is_not_working(self):
429
 
        self.assertNotEqual(self.test_dir, self.test_home_dir)
430
 
        cwd = osutils.getcwd()
431
 
        self.assertEqual(self.test_dir, cwd)
432
 
        self.assertEqual(self.test_home_dir, os.environ['HOME'])
433
 
 
434
 
 
435
422
class TestTestCaseWithTransport(TestCaseWithTransport):
436
423
    """Tests for the convenience functions TestCaseWithTransport introduces."""
437
424
 
476
463
        self.assertRaises(AssertionError, self.assertIsDirectory, 'not_here', t)
477
464
 
478
465
 
479
 
class TestTestCaseTransports(TestCaseWithTransport):
480
 
 
481
 
    def setUp(self):
482
 
        super(TestTestCaseTransports, self).setUp()
483
 
        self.transport_server = MemoryServer
484
 
 
485
 
    def test_make_bzrdir_preserves_transport(self):
486
 
        t = self.get_transport()
487
 
        result_bzrdir = self.make_bzrdir('subdir')
488
 
        self.assertIsInstance(result_bzrdir.transport, 
489
 
                              MemoryTransport)
490
 
        # should not be on disk, should only be in memory
491
 
        self.failIfExists('subdir')
492
 
 
493
 
 
494
466
class TestChrootedTest(ChrootedTestCase):
495
467
 
496
468
    def test_root_is_root(self):
746
718
        output_string = output.getvalue()
747
719
        self.assertContainsRe(output_string, "--date [0-9.]+")
748
720
        if workingtree is not None:
749
 
            revision_id = workingtree.get_parent_ids()[0]
 
721
            revision_id = workingtree.last_revision()
750
722
            self.assertEndsWith(output_string.rstrip(), revision_id)
751
723
 
752
724
 
826
798
        self.assertIsInstance(self._benchcalls[1][1], bzrlib.lsprof.Stats)
827
799
 
828
800
 
829
 
@symbol_versioning.deprecated_function(zero_eleven)
830
 
def sample_deprecated_function():
831
 
    """A deprecated function to test applyDeprecated with."""
832
 
    return 2
833
 
 
834
 
 
835
 
def sample_undeprecated_function(a_param):
836
 
    """A undeprecated function to test applyDeprecated with."""
837
 
 
838
 
 
839
 
class ApplyDeprecatedHelper(object):
840
 
    """A helper class for ApplyDeprecated tests."""
841
 
 
842
 
    @symbol_versioning.deprecated_method(zero_eleven)
843
 
    def sample_deprecated_method(self, param_one):
844
 
        """A deprecated method for testing with."""
845
 
        return param_one
846
 
 
847
 
    def sample_normal_method(self):
848
 
        """A undeprecated method."""
849
 
 
850
 
    @symbol_versioning.deprecated_method(zero_ten)
851
 
    def sample_nested_deprecation(self):
852
 
        return sample_deprecated_function()
853
 
 
854
 
 
855
801
class TestExtraAssertions(TestCase):
856
802
    """Tests for new test assertions in bzrlib test suite"""
857
803
 
865
811
        self.assertEndsWith('foo', 'oo')
866
812
        self.assertRaises(AssertionError, self.assertEndsWith, 'o', 'oo')
867
813
 
868
 
    def test_applyDeprecated_not_deprecated(self):
869
 
        sample_object = ApplyDeprecatedHelper()
870
 
        # calling an undeprecated callable raises an assertion
871
 
        self.assertRaises(AssertionError, self.applyDeprecated, zero_eleven,
872
 
            sample_object.sample_normal_method)
873
 
        self.assertRaises(AssertionError, self.applyDeprecated, zero_eleven,
874
 
            sample_undeprecated_function, "a param value")
875
 
        # calling a deprecated callable (function or method) with the wrong
876
 
        # expected deprecation fails.
877
 
        self.assertRaises(AssertionError, self.applyDeprecated, zero_ten,
878
 
            sample_object.sample_deprecated_method, "a param value")
879
 
        self.assertRaises(AssertionError, self.applyDeprecated, zero_ten,
880
 
            sample_deprecated_function)
881
 
        # calling a deprecated callable (function or method) with the right
882
 
        # expected deprecation returns the functions result.
883
 
        self.assertEqual("a param value", self.applyDeprecated(zero_eleven,
884
 
            sample_object.sample_deprecated_method, "a param value"))
885
 
        self.assertEqual(2, self.applyDeprecated(zero_eleven,
886
 
            sample_deprecated_function))
887
 
        # calling a nested deprecation with the wrong deprecation version
888
 
        # fails even if a deeper nested function was deprecated with the 
889
 
        # supplied version.
890
 
        self.assertRaises(AssertionError, self.applyDeprecated,
891
 
            zero_eleven, sample_object.sample_nested_deprecation)
892
 
        # calling a nested deprecation with the right deprecation value
893
 
        # returns the calls result.
894
 
        self.assertEqual(2, self.applyDeprecated(zero_ten,
895
 
            sample_object.sample_nested_deprecation))
896
 
 
897
814
    def test_callDeprecated(self):
898
815
        def testfunc(be_deprecated, result=None):
899
816
            if be_deprecated is True:
904
821
        self.assertIs(None, result)
905
822
        result = self.callDeprecated([], testfunc, False, 'result')
906
823
        self.assertEqual('result', result)
907
 
        self.callDeprecated(['i am deprecated'], testfunc, be_deprecated=True)
 
824
        self.callDeprecated(['i am deprecated'], testfunc, 
 
825
                              be_deprecated=True)
908
826
        self.callDeprecated([], testfunc, be_deprecated=False)
909
827
 
910
828
 
920
838
        self.assertIsInstance(bzrlib.bzrdir.BzrDir.open('b')._format,
921
839
                              bzrlib.bzrdir.BzrDirFormat6)
922
840
 
923
 
    def test_make_branch_and_mutable_tree(self):
924
 
        # we should be able to get a new branch and a mutable tree from
925
 
        # TestCaseWithTransport
926
 
        tree = self.make_branch_and_memory_tree('a')
927
 
        self.assertIsInstance(tree, bzrlib.memorytree.MemoryTree)
928
 
 
929
 
 
930
 
class TestSFTPMakeBranchAndTree(TestCaseWithSFTPServer):
931
 
 
932
 
    def test_make_tree_for_sftp_branch(self):
933
 
        """Transports backed by local directories create local trees."""
934
 
 
935
 
        tree = self.make_branch_and_tree('t1')
936
 
        base = tree.bzrdir.root_transport.base
937
 
        self.failIf(base.startswith('sftp'),
938
 
                'base %r is on sftp but should be local' % base)
939
 
        self.assertEquals(tree.bzrdir.root_transport,
940
 
                tree.branch.bzrdir.root_transport)
941
 
        self.assertEquals(tree.bzrdir.root_transport,
942
 
                tree.branch.repository.bzrdir.root_transport)
943
 
 
944
841
 
945
842
class TestSelftest(TestCase):
946
843
    """Tests of bzrlib.tests.selftest."""