/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

  • Committer: John Arbash Meinel
  • Date: 2006-09-15 00:44:57 UTC
  • mfrom: (2009 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2050.
  • Revision ID: john@arbash-meinel.com-20060915004457-902cec0526a39337
[merge] bzr.dev 2009

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
37
38
from bzrlib.tests.TestUtil import _load_module_by_name
38
39
import bzrlib.errors as errors
39
40
from bzrlib import symbol_versioning
 
41
from bzrlib.symbol_versioning import zero_ten, zero_eleven
40
42
from bzrlib.trace import note
 
43
from bzrlib.transport.memory import MemoryServer, MemoryTransport
41
44
from bzrlib.version import _get_bzr_source_tree
42
45
 
43
46
 
419
422
        self.assertEqual(tests[1].transport_server, server1)
420
423
        self.assertEqual(tests[1].transport_readonly_server, server2)
421
424
 
 
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
 
422
435
class TestTestCaseWithTransport(TestCaseWithTransport):
423
436
    """Tests for the convenience functions TestCaseWithTransport introduces."""
424
437
 
463
476
        self.assertRaises(AssertionError, self.assertIsDirectory, 'not_here', t)
464
477
 
465
478
 
 
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
 
466
494
class TestChrootedTest(ChrootedTestCase):
467
495
 
468
496
    def test_root_is_root(self):
718
746
        output_string = output.getvalue()
719
747
        self.assertContainsRe(output_string, "--date [0-9.]+")
720
748
        if workingtree is not None:
721
 
            revision_id = workingtree.last_revision()
 
749
            revision_id = workingtree.get_parent_ids()[0]
722
750
            self.assertEndsWith(output_string.rstrip(), revision_id)
723
751
 
724
752
 
798
826
        self.assertIsInstance(self._benchcalls[1][1], bzrlib.lsprof.Stats)
799
827
 
800
828
 
 
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
 
801
855
class TestExtraAssertions(TestCase):
802
856
    """Tests for new test assertions in bzrlib test suite"""
803
857
 
811
865
        self.assertEndsWith('foo', 'oo')
812
866
        self.assertRaises(AssertionError, self.assertEndsWith, 'o', 'oo')
813
867
 
 
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
 
814
897
    def test_callDeprecated(self):
815
898
        def testfunc(be_deprecated, result=None):
816
899
            if be_deprecated is True:
821
904
        self.assertIs(None, result)
822
905
        result = self.callDeprecated([], testfunc, False, 'result')
823
906
        self.assertEqual('result', result)
824
 
        self.callDeprecated(['i am deprecated'], testfunc, 
825
 
                              be_deprecated=True)
 
907
        self.callDeprecated(['i am deprecated'], testfunc, be_deprecated=True)
826
908
        self.callDeprecated([], testfunc, be_deprecated=False)
827
909
 
828
910
 
839
921
                              bzrlib.bzrdir.BzrDirFormat6)
840
922
 
841
923
 
 
924
class TestSFTPMakeBranchAndTree(TestCaseWithSFTPServer):
 
925
 
 
926
    def test_make_tree_for_sftp_branch(self):
 
927
        """Transports backed by local directories create local trees."""
 
928
 
 
929
        tree = self.make_branch_and_tree('t1')
 
930
        base = tree.bzrdir.root_transport.base
 
931
        self.failIf(base.startswith('sftp'),
 
932
                'base %r is on sftp but should be local' % base)
 
933
        self.assertEquals(tree.bzrdir.root_transport,
 
934
                tree.branch.bzrdir.root_transport)
 
935
        self.assertEquals(tree.bzrdir.root_transport,
 
936
                tree.branch.repository.bzrdir.root_transport)
 
937
 
 
938
 
842
939
class TestSelftest(TestCase):
843
940
    """Tests of bzrlib.tests.selftest."""
844
941