/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

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
from bzrlib.tests.TestUtil import _load_module_by_name
38
38
import bzrlib.errors as errors
39
39
from bzrlib import symbol_versioning
 
40
from bzrlib.symbol_versioning import zero_ten, zero_eleven
40
41
from bzrlib.trace import note
41
42
from bzrlib.version import _get_bzr_source_tree
42
43
 
419
420
        self.assertEqual(tests[1].transport_server, server1)
420
421
        self.assertEqual(tests[1].transport_readonly_server, server2)
421
422
 
 
423
 
 
424
class TestTestCaseInTempDir(TestCaseInTempDir):
 
425
 
 
426
    def test_home_is_not_working(self):
 
427
        self.assertNotEqual(self.test_dir, self.test_home_dir)
 
428
        cwd = osutils.getcwd()
 
429
        self.assertEqual(self.test_dir, cwd)
 
430
        self.assertEqual(self.test_home_dir, os.environ['HOME'])
 
431
 
 
432
 
422
433
class TestTestCaseWithTransport(TestCaseWithTransport):
423
434
    """Tests for the convenience functions TestCaseWithTransport introduces."""
424
435
 
718
729
        output_string = output.getvalue()
719
730
        self.assertContainsRe(output_string, "--date [0-9.]+")
720
731
        if workingtree is not None:
721
 
            revision_id = workingtree.last_revision()
 
732
            revision_id = workingtree.get_parent_ids()[0]
722
733
            self.assertEndsWith(output_string.rstrip(), revision_id)
723
734
 
724
735
 
798
809
        self.assertIsInstance(self._benchcalls[1][1], bzrlib.lsprof.Stats)
799
810
 
800
811
 
 
812
@symbol_versioning.deprecated_function(zero_eleven)
 
813
def sample_deprecated_function():
 
814
    """A deprecated function to test applyDeprecated with."""
 
815
    return 2
 
816
 
 
817
 
 
818
def sample_undeprecated_function(a_param):
 
819
    """A undeprecated function to test applyDeprecated with."""
 
820
 
 
821
 
 
822
class ApplyDeprecatedHelper(object):
 
823
    """A helper class for ApplyDeprecated tests."""
 
824
 
 
825
    @symbol_versioning.deprecated_method(zero_eleven)
 
826
    def sample_deprecated_method(self, param_one):
 
827
        """A deprecated method for testing with."""
 
828
        return param_one
 
829
 
 
830
    def sample_normal_method(self):
 
831
        """A undeprecated method."""
 
832
 
 
833
    @symbol_versioning.deprecated_method(zero_ten)
 
834
    def sample_nested_deprecation(self):
 
835
        return sample_deprecated_function()
 
836
 
 
837
 
801
838
class TestExtraAssertions(TestCase):
802
839
    """Tests for new test assertions in bzrlib test suite"""
803
840
 
811
848
        self.assertEndsWith('foo', 'oo')
812
849
        self.assertRaises(AssertionError, self.assertEndsWith, 'o', 'oo')
813
850
 
 
851
    def test_applyDeprecated_not_deprecated(self):
 
852
        sample_object = ApplyDeprecatedHelper()
 
853
        # calling an undeprecated callable raises an assertion
 
854
        self.assertRaises(AssertionError, self.applyDeprecated, zero_eleven,
 
855
            sample_object.sample_normal_method)
 
856
        self.assertRaises(AssertionError, self.applyDeprecated, zero_eleven,
 
857
            sample_undeprecated_function, "a param value")
 
858
        # calling a deprecated callable (function or method) with the wrong
 
859
        # expected deprecation fails.
 
860
        self.assertRaises(AssertionError, self.applyDeprecated, zero_ten,
 
861
            sample_object.sample_deprecated_method, "a param value")
 
862
        self.assertRaises(AssertionError, self.applyDeprecated, zero_ten,
 
863
            sample_deprecated_function)
 
864
        # calling a deprecated callable (function or method) with the right
 
865
        # expected deprecation returns the functions result.
 
866
        self.assertEqual("a param value", self.applyDeprecated(zero_eleven,
 
867
            sample_object.sample_deprecated_method, "a param value"))
 
868
        self.assertEqual(2, self.applyDeprecated(zero_eleven,
 
869
            sample_deprecated_function))
 
870
        # calling a nested deprecation with the wrong deprecation version
 
871
        # fails even if a deeper nested function was deprecated with the 
 
872
        # supplied version.
 
873
        self.assertRaises(AssertionError, self.applyDeprecated,
 
874
            zero_eleven, sample_object.sample_nested_deprecation)
 
875
        # calling a nested deprecation with the right deprecation value
 
876
        # returns the calls result.
 
877
        self.assertEqual(2, self.applyDeprecated(zero_ten,
 
878
            sample_object.sample_nested_deprecation))
 
879
 
814
880
    def test_callDeprecated(self):
815
881
        def testfunc(be_deprecated, result=None):
816
882
            if be_deprecated is True:
821
887
        self.assertIs(None, result)
822
888
        result = self.callDeprecated([], testfunc, False, 'result')
823
889
        self.assertEqual('result', result)
824
 
        self.callDeprecated(['i am deprecated'], testfunc, 
825
 
                              be_deprecated=True)
 
890
        self.callDeprecated(['i am deprecated'], testfunc, be_deprecated=True)
826
891
        self.callDeprecated([], testfunc, be_deprecated=False)
827
892
 
828
893