Ejemplo n.º 1
0
 def assertRaisesAny(self, exc_classes, callable_obj, *args, **kwargs):
     checkers = [
         matchers.MatchesException(exc_class) for exc_class in exc_classes
     ]
     matcher = matchers.Raises(matchers.MatchesAny(*checkers))
     callable_obj = testcase.Nullary(callable_obj, *args, **kwargs)
     self.assertThat(callable_obj, matcher)
Ejemplo n.º 2
0
    def assertRaisesRegexp(self, exc_class, pattern, callable_obj, *args,
                           **kwargs):
        # TODO(harlowja): submit a pull/review request to testtools to add
        # this method to there codebase instead of having it exist in ours
        # since it really doesn't belong here.

        class ReRaiseOtherTypes(object):
            def match(self, matchee):
                if not issubclass(matchee[0], exc_class):
                    compat.reraise(*matchee)

        class CaptureMatchee(object):
            def match(self, matchee):
                self.matchee = matchee[1]

        capture = CaptureMatchee()
        matcher = matchers.Raises(
            matchers.MatchesAll(ReRaiseOtherTypes(),
                                matchers.MatchesException(exc_class, pattern),
                                capture))
        our_callable = testcase.Nullary(callable_obj, *args, **kwargs)
        self.assertThat(our_callable, matcher)
        return capture.matchee