/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/__init__.py

Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
868
868
                excName = str(excClass)
869
869
            raise self.failureException, "%s not raised" % excName
870
870
 
 
871
    def assertRaises(self, excClass, func, *args, **kwargs):
 
872
        """Assert that a callable raises a particular exception.
 
873
 
 
874
        :param excClass: As for the except statement, this may be either an
 
875
        exception class, or a tuple of classes.
 
876
 
 
877
        Returns the exception so that you can examine it.
 
878
        """
 
879
        try:
 
880
            func(*args, **kwargs)
 
881
        except excClass, e:
 
882
            return e
 
883
        else:
 
884
            if getattr(excClass,'__name__', None) is not None:
 
885
                excName = excClass.__name__
 
886
            else:
 
887
                # probably a tuple
 
888
                excName = str(excClass)
 
889
            raise self.failureException, "%s not raised" % excName
 
890
 
871
891
    def assertIs(self, left, right, message=None):
872
892
        if not (left is right):
873
893
            if message is not None:
900
920
            self.fail("%r is an instance of %s rather than %s" % (
901
921
                obj, obj.__class__, kls))
902
922
 
 
923
    def expectFailure(self, reason, assertion, *args, **kwargs):
 
924
        """Invoke a test, expecting it to fail for the given reason.
 
925
 
 
926
        This is for assertions that ought to succeed, but currently fail.
 
927
        (The failure is *expected* but not *wanted*.)  Please be very precise
 
928
        about the failure you're expecting.  If a new bug is introduced,
 
929
        AssertionError should be raised, not KnownFailure.
 
930
 
 
931
        Frequently, expectFailure should be followed by an opposite assertion.
 
932
        See example below.
 
933
 
 
934
        Intended to be used with a callable that raises AssertionError as the
 
935
        'assertion' parameter.  args and kwargs are passed to the 'assertion'.
 
936
 
 
937
        Raises KnownFailure if the test fails.  Raises AssertionError if the
 
938
        test succeeds.
 
939
 
 
940
        example usage::
 
941
 
 
942
          self.expectFailure('Math is broken', self.assertNotEqual, 54,
 
943
                             dynamic_val)
 
944
          self.assertEqual(42, dynamic_val)
 
945
 
 
946
          This means that a dynamic_val of 54 will cause the test to raise
 
947
          a KnownFailure.  Once math is fixed and the expectFailure is removed,
 
948
          only a dynamic_val of 42 will allow the test to pass.  Anything other
 
949
          than 54 or 42 will cause an AssertionError.
 
950
        """
 
951
        try:
 
952
            assertion(*args, **kwargs)
 
953
        except AssertionError:
 
954
            raise KnownFailure(reason)
 
955
        else:
 
956
            self.fail('Unexpected success.  Should have failed: %s' % reason)
 
957
 
903
958
    def _capture_warnings(self, a_callable, *args, **kwargs):
904
959
        """A helper for callDeprecated and applyDeprecated.
905
960