~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

Merge bzr.dev 4734 in preparation for NEWS updates.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1146
1146
            self.fail("Incorrect length: wanted %d, got %d for %r" % (
1147
1147
                length, len(obj_with_len), obj_with_len))
1148
1148
 
 
1149
    def assertLogsError(self, exception_class, func, *args, **kwargs):
 
1150
        """Assert that func(*args, **kwargs) quietly logs a specific exception.
 
1151
        """
 
1152
        from bzrlib import trace
 
1153
        captured = []
 
1154
        orig_log_exception_quietly = trace.log_exception_quietly
 
1155
        try:
 
1156
            def capture():
 
1157
                orig_log_exception_quietly()
 
1158
                captured.append(sys.exc_info())
 
1159
            trace.log_exception_quietly = capture
 
1160
            func(*args, **kwargs)
 
1161
        finally:
 
1162
            trace.log_exception_quietly = orig_log_exception_quietly
 
1163
        self.assertLength(1, captured)
 
1164
        err = captured[0][1]
 
1165
        self.assertIsInstance(err, exception_class)
 
1166
        return err
 
1167
 
1149
1168
    def assertPositive(self, val):
1150
1169
        """Assert that val is greater than 0."""
1151
1170
        self.assertTrue(val > 0, 'expected a positive value, but got %s' % val)