def raise_keyb_from_match(): if sys.version_info > (2, 5): matcher = Raises(MatchesException(Exception)) else: # On Python 2.4 KeyboardInterrupt is a StandardError subclass # but should propogate from less generic exception matchers matcher = Raises(MatchesException(EnvironmentError)) matcher.match(self.raiser)
def test_KeyboardInterrupt_propogates(self): # The default 'it raised' propogates KeyboardInterrupt. match_keyb = Raises(MatchesException(KeyboardInterrupt)) def raise_keyb_from_match(): matcher = Raises() matcher.match(self.raiser) self.assertThat(raise_keyb_from_match, match_keyb)
def test_KeyboardInterrupt_match_Exception_propogates(self): # If the raised exception isn't matched, and it is not a subclass of # Exception, it is propogated. match_keyb = Raises(MatchesException(KeyboardInterrupt)) def raise_keyb_from_match(): matcher = Raises(MatchesException(Exception)) matcher.match(self.raiser) self.assertThat(raise_keyb_from_match, match_keyb)
class TestRaisesInterface(TestCase, TestMatchersInterface): matches_matcher = Raises() def boom(): raise Exception('foo') matches_matches = [boom] matches_mismatches = [lambda:None] # Tricky to get function objects to render constantly, and the interfaces # helper uses assertEqual rather than (for instance) DocTestMatches. str_examples = [] describe_examples = []
def test_KeyboardInterrupt_match_Exception_propogates(self): # If the raised exception isn't matched, and it is not a subclass of # Exception, it is propogated. match_keyb = Raises(MatchesException(KeyboardInterrupt)) def raise_keyb_from_match(): if sys.version_info > (2, 5): matcher = Raises(MatchesException(Exception)) else: # On Python 2.4 KeyboardInterrupt is a StandardError subclass # but should propogate from less generic exception matchers matcher = Raises(MatchesException(EnvironmentError)) matcher.match(self.raiser) self.assertThat(raise_keyb_from_match, match_keyb)
def raise_keyb_from_match(): matcher = Raises(MatchesException(Exception)) matcher.match(self.raiser)
def raise_keyb_from_match(): matcher = Raises() matcher.match(self.raiser)
def test_KeyboardInterrupt_matched(self): # When KeyboardInterrupt is matched, it is swallowed. matcher = Raises(MatchesException(KeyboardInterrupt)) self.assertThat(self.raiser, matcher)