/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 bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
from bzrlib.tests.TestUtil import _load_module_by_name
39
39
import bzrlib.errors as errors
40
40
from bzrlib import symbol_versioning
 
41
from bzrlib.symbol_versioning import zero_ten, zero_eleven
41
42
from bzrlib.trace import note
42
43
from bzrlib.transport.memory import MemoryServer, MemoryTransport
43
44
from bzrlib.version import _get_bzr_source_tree
421
422
        self.assertEqual(tests[1].transport_server, server1)
422
423
        self.assertEqual(tests[1].transport_readonly_server, server2)
423
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
 
424
435
class TestTestCaseWithTransport(TestCaseWithTransport):
425
436
    """Tests for the convenience functions TestCaseWithTransport introduces."""
426
437
 
735
746
        output_string = output.getvalue()
736
747
        self.assertContainsRe(output_string, "--date [0-9.]+")
737
748
        if workingtree is not None:
738
 
            revision_id = workingtree.last_revision()
 
749
            revision_id = workingtree.get_parent_ids()[0]
739
750
            self.assertEndsWith(output_string.rstrip(), revision_id)
740
751
 
741
752
 
815
826
        self.assertIsInstance(self._benchcalls[1][1], bzrlib.lsprof.Stats)
816
827
 
817
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
 
818
855
class TestExtraAssertions(TestCase):
819
856
    """Tests for new test assertions in bzrlib test suite"""
820
857
 
828
865
        self.assertEndsWith('foo', 'oo')
829
866
        self.assertRaises(AssertionError, self.assertEndsWith, 'o', 'oo')
830
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
 
831
897
    def test_callDeprecated(self):
832
898
        def testfunc(be_deprecated, result=None):
833
899
            if be_deprecated is True:
838
904
        self.assertIs(None, result)
839
905
        result = self.callDeprecated([], testfunc, False, 'result')
840
906
        self.assertEqual('result', result)
841
 
        self.callDeprecated(['i am deprecated'], testfunc, 
842
 
                              be_deprecated=True)
 
907
        self.callDeprecated(['i am deprecated'], testfunc, be_deprecated=True)
843
908
        self.callDeprecated([], testfunc, be_deprecated=False)
844
909
 
845
910