Пример #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)
Пример #2
0
 def test_next_stream_corruption_error(self):
     repo = self.useFixture(FileRepositoryFixture()).repo
     open(os.path.join(repo.base, 'next-stream'), 'wb').close()
     self.assertThat(
         repo.count,
         matchers.Raises(
             matchers.MatchesException(
                 ValueError("Corrupt next-stream file: ''"))))
Пример #3
0
    def test_invalid_backend_fails_initialization(self):
        raises_valueerror = matchers.Raises(
            matchers.MatchesException(ValueError, r'.*FakeBackend.*'))

        options = {
            'url': 'needed to get to the focus of this test (the backend)',
            'memcached_backend': 'FakeBackend',
        }
        self.assertThat(lambda: memcached.MemcachedBackend(options),
                        raises_valueerror)
Пример #4
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