/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: Aaron Bentley
  • Date: 2006-09-09 18:52:57 UTC
  • mfrom: (1996 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1997.
  • Revision ID: aaron.bentley@utoronto.ca-20060909185257-ce0ee03ee5125ff1
Merge bzr.dev

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
 
42
from bzrlib.version import _get_bzr_source_tree
41
43
 
42
44
 
43
45
class SelftestTests(TestCase):
418
420
        self.assertEqual(tests[1].transport_server, server1)
419
421
        self.assertEqual(tests[1].transport_readonly_server, server2)
420
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
 
421
433
class TestTestCaseWithTransport(TestCaseWithTransport):
422
434
    """Tests for the convenience functions TestCaseWithTransport introduces."""
423
435
 
587
599
        output_string = output.getvalue()
588
600
        # if you are wondering about the regexp please read the comment in
589
601
        # test_bench_history (bzrlib.tests.test_selftest.TestRunner)
590
 
        self.assertContainsRe(output_string, "--date [0-9.]+ \S")
 
602
        # XXX: what comment?  -- Andrew Bennetts
 
603
        self.assertContainsRe(output_string, "--date [0-9.]+")
591
604
 
592
605
    def test_benchhistory_records_test_times(self):
593
606
        result_stream = StringIO()
705
718
        self.assertTrue(result.wasSuccessful())
706
719
 
707
720
    def test_bench_history(self):
708
 
        import bzrlib.branch
709
 
        try:
710
 
            branch = bzrlib.branch.Branch.open_containing(__file__)[0]
711
 
        except errors.NotBranchError:
712
 
            raise TestSkipped(
713
 
                'Test must be run in a bzr.dev tree, not an installed copy.')
 
721
        # tests that the running the benchmark produces a history file
 
722
        # containing a timestamp and the revision id of the bzrlib source which
 
723
        # was tested.
 
724
        workingtree = _get_bzr_source_tree()
714
725
        test = TestRunner('dummy_test')
715
726
        output = StringIO()
716
727
        runner = TextTestRunner(stream=self._log_file, bench_history=output)
717
728
        result = self.run_test_runner(runner, test)
718
729
        output_string = output.getvalue()
719
 
        self.assertContainsRe(output_string, "--date [0-9.]+ \S")
720
 
        revision_id = branch.last_revision()
721
 
        self.assertEndsWith(output_string.rstrip(), revision_id)
 
730
        self.assertContainsRe(output_string, "--date [0-9.]+")
 
731
        if workingtree is not None:
 
732
            revision_id = workingtree.get_parent_ids()[0]
 
733
            self.assertEndsWith(output_string.rstrip(), revision_id)
722
734
 
723
735
 
724
736
class TestTestCase(TestCase):
797
809
        self.assertIsInstance(self._benchcalls[1][1], bzrlib.lsprof.Stats)
798
810
 
799
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
 
800
838
class TestExtraAssertions(TestCase):
801
839
    """Tests for new test assertions in bzrlib test suite"""
802
840
 
810
848
        self.assertEndsWith('foo', 'oo')
811
849
        self.assertRaises(AssertionError, self.assertEndsWith, 'o', 'oo')
812
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
 
813
880
    def test_callDeprecated(self):
814
881
        def testfunc(be_deprecated, result=None):
815
882
            if be_deprecated is True:
820
887
        self.assertIs(None, result)
821
888
        result = self.callDeprecated([], testfunc, False, 'result')
822
889
        self.assertEqual('result', result)
823
 
        self.callDeprecated(['i am deprecated'], testfunc, 
824
 
                              be_deprecated=True)
 
890
        self.callDeprecated(['i am deprecated'], testfunc, be_deprecated=True)
825
891
        self.callDeprecated([], testfunc, be_deprecated=False)
826
892
 
827
893