def test_raises_key_error_when_dict_item_does_not_match_attribute(self): sut = Structure(spams=200) def attempt(): sut["beans"] expect(attempt).to(raise_ex(KeyError))
def test_returns_true_on_exception_object_exact_match(self): e = Spam("I'll have your SPAM and your little dog too") def attempt(): raise e expect(attempt).to(raise_ex(e))
def test_re_raises_unspecified_response_exception(self): client = HttpClient() client.set_exceptional_response_callback(exception_class=HttpNotFound, callback=lambda *a, **k: None) raised = HttpUnauthorized() self.context.inject(inspect_response, func_that_raises(raised)) expect(partial(client.post, "http://mail.net")).to(raise_ex(raised))
def test_raises_attribute_error(self): sut = Structure(apples=2, oranges=3) def attempt(): sut.bananas expect(attempt).to(raise_ex(AttributeError))
def test_rejects_parent_class_of_existing_key(self): client = HttpClient() client.set_exceptional_response_callback(exception_class=SonOfSpam, callback=EndlessFake()) expect( partial(client.set_exceptional_response_callback, exception_class=Spam, callback=EndlessFake())).to(raise_ex(TypeError))
def test_raises_other_exception_on_write_attempt(self): class FakeException(Exception): pass self.context.inject(open, func_that_raises(FakeException("intentional"))) self.create_fake_archive() expect(BrowserStackTunnel).to(raise_ex(FakeException))
def test_re_raises_exception_if_callback_returns_none(self): original = HttpImATeapot() self.context.inject(inspect_response, func_that_raises(original)) client = HttpClient() client.set_exceptional_response_callback(exception_class=HttpImATeapot, callback=lambda *a, **k: None) expect(partial(client.delete, "http://nothing.new")).to(raise_ex(original))
def test_detects_busy_signal(self): def busy(*args, **kwargs): raise WebDriverException( "All parallel tests are currently in use, " "including the queued tests. Please wait to " "finish or upgrade your plan to add more sessions.") self.webdriver_spy.Remote = busy expect(Browser).to(raise_ex(AllBrowsersBusy))
def test_lets_exception_raised_by_callback_pass_through(self): exception_class = Spam raised = exception_class() callback = func_that_raises(raised) client = HttpClient() client.set_exceptional_response_callback(exception_class=HttpNotFound, callback=callback) self.context.inject(inspect_response, func_that_raises(HttpNotFound)) expect(partial(client.put, "https://up.with.it")).to(raise_ex(raised))
def test_ignores_missing_suite_element(self): self.add_file( "TestSpam.xml", """ <?xml version="1.0" encoding="UTF-8" ?> <spam/> """, ) expect(self.exercise_sut).not_to(raise_ex(AttributeError))
def test_complains_about_environment_directive_with_unknown_level(self): module_name = "alt.barney.big.purple.dino_saur" self.context.set_env(**{ "%s_LOG_LEVEL" % module_name.replace(".", "_").upper(): "BIGGLES" }) def attempt(): logger_for_module(module_name) expect(attempt).to(raise_ex(AttributeError))
def test_complains_if_action_not_specified(self): fake = FakeHttpClient() url = "http://something" fake.get_responses[url] = FakeResponse(""" <html><body><form method="pUt"/></body></html> """) def attempt(): HtmlForm(http_client=fake, url=url, xpath="//form") expect(attempt).to(raise_ex(exceptions.FormElementLacksAction))
def test_re_raises_another_exception_of_different_class(self): expected = Spam("expected") unexpected = Eggs("unexpected") def attempt(): raise unexpected try: expect(attempt).to(raise_ex(expected)) assert False, "No exception was raised" except type(unexpected) as actual: expect(actual).to(equal(unexpected))
def test_re_raises_another_exception_of_same_class(self): expected = Spam('expected') unexpected = Spam('unexpected') def attempt(): raise unexpected try: expect(attempt).to(raise_ex(expected)) assert False, 'No exception was raised' except Spam as actual: expect(actual).to(equal(unexpected))
def test_complains_when_cannot_parse_line(self): reporters_filename = "/here/is/something/silly" self.set_filename(reporters_filename) module_name = "fake_module" self.fake_importer.add_module(module_name, EmptyFake()) self.fake_files.create( reporters_filename, """ Stop being silly """, ) expect(activate_reporters).to(raise_ex(InvalidConfiguration))
def test_raises_unspecfied_exception(self): raised = Eggs("intentional") def attempt(): raise raised caught = None try: expect(attempt).to(raise_ex(Spam)) except Exception as e: caught = e expect(caught).to(equal(raised))
def test_complains_if_form_not_found(self): fake = FakeHttpClient() url = "http://something" fake.get_responses[url] = FakeResponse(""" <html><body><form id="wrong" action="spam" method="POST"/> </body></html> """) def attempt(): HtmlForm(http_client=fake, url=url, xpath="//form[@name='right']") expect(attempt).to(raise_ex(exceptions.FormNotFound))
def test_ignores_absent_errors_attribute(self): self.add_file( "TestSpam.xml", """ <?xml version="1.0" encoding="UTF-8" ?> <testsuites> <testsuite name="yogurt" failures="0"> <testcase name="spam"/> </testsuite> </testsuites> """, ) expect(self.exercise_sut).not_to(raise_ex(KeyError))
def test_re_raises_after_timeout(self): exception_class = SpamException def func(): raise exception_class("intentional") def do_it(): call_with_exception_tolerance(func=func, tolerate=SpamException, timeout=0.001, throttle=0) expect(do_it).to(raise_ex(exception_class))
def test_ignores_comment_line(self): reporters_filename = "/here/is/something/silly" self.set_filename(reporters_filename) module_name = "fake_module" self.fake_importer.add_module(module_name, EmptyFake()) self.fake_files.create( reporters_filename, """ # This should be ignored %s.FakeClass # This should be ignored too """ % module_name, ) expect(activate_reporters).not_to(raise_ex(Exception))
def test_returns_false_if_no_exception_is_raised(self): expect(lambda: None).not_to(raise_ex(Spam))
def test_ignores_non_xml_files(self): self.add_file("yadda.notxml", "3rwdsfqrwefcdasrq3f") expect(self.exercise_sut).not_to(raise_ex(ParseError))
def test_extension_check_is_case_insensitive(self): self.add_file("yadda.xMl", "3rwdsfqrwefcdasrq3f") expect(self.exercise_sut).to(raise_ex(ParseError))
def test_returned_func_raises_expected_exception(self): expected = RuntimeError("Shuzbut") expect(func_that_raises(expected)).to(raise_ex(expected))
def test_returns_true_if_specified_exception_is_raised(self): def attempt(): raise Spam('intentional') expect(attempt).to(raise_ex(Spam))
def test_attribute_error_on_unknown_method(self): def attempt(): HttpClient().this_method_does_not_exist expect(attempt).to(raise_ex(AttributeError))
def test_returns_true_if_subclass_exception_is_raised(self): def attempt(): raise SonOfSpam("intentional") expect(attempt).to(raise_ex(Spam))
def test_returns_false_if_object__specified_and_nothing_raised(self): expect(lambda: None).not_to(raise_ex(Exception("unexpected")))
def test_returns_false_if_msg_pat_specified_and_does_not_match(self): def attempt(): raise Spam("Nobody injests the Spinach Imposition") expect(attempt).not_to(raise_ex(Spam, "^Spinach"))
def test_returns_true_if_msg_pat_specified_and_matches(self): def attempt(): raise Spam("Spinach is king") expect(attempt).to(raise_ex(Spam, "^Spinach"))