def test_raises_an_exception_if_not_found(self): "Hierarchical Configuration - Raises an exception if not found" fake_config = pmock.Mock() fake_config.expects(pmock.once()).get(pmock.eq("output_folder")).will( pmock.raise_exception(Exception("Uknown key..."))) other_config = pmock.Mock() other_config.expects(pmock.once()).get(pmock.eq("output_folder")).will( pmock.raise_exception(Exception("Uknown key..."))) configuration = HierarchicalConfiguration([fake_config, other_config]) try: configuration.get("output_folder") self.fail("Should have thrown exception") except KeyError, e: self.assertEquals("'output_folder'", str(e))
def test_cant_take_two_configuration_second_is_called_if_necessary(self): "Hierarchical Configuration - Can take two childs configuration, second child is called if necessary" fake_config = pmock.Mock() fake_config.expects(pmock.once()).get(pmock.eq("output_folder")).will( pmock.raise_exception(Exception("Uknown key..."))) other_config = pmock.Mock() other_config.expects(pmock.once()).get(pmock.eq("output_folder")).will( pmock.return_value("polop")) configuration = HierarchicalConfiguration([fake_config, other_config]) self.assertEquals("polop", configuration.get("output_folder"))
def test_method_will_raise_exception(self): self.mock = pmock.Mock() custom_err = RuntimeError() self.mock.expects(pmock.once()).method("dog").will( pmock.raise_exception(custom_err)) try: self.mock.proxy().dog() self.fail() except RuntimeError, err: self.assert_(err is custom_err) self.mock.verify()
def testOneBrowserLaunchFailureDoesNotAffectOtherBrowserTesting(self): self.test_webserver.expects(pmock.once()).startServing() self.test_webserver.expects(pmock.once()) \ .startTest(pmock.eq(TestRunner.TIMEOUT)) self.test_webserver.expects(pmock.once()) \ .startTest(pmock.eq(TestRunner.TIMEOUT)) failing_browser_launcher = pmock.Mock() failing_browser_launcher.stubs().type() \ .will(pmock.return_value("launcher1")) failing_browser_launcher.expects(pmock.once()) \ .launch(pmock.eq(TestRunner.TEST_URL)) \ .will(pmock.raise_exception(RuntimeError("browser lauch failed"))) failing_browser_launcher.expects(pmock.once()).killAllInstances() self.test_webserver.expects(pmock.once()) \ .testResults() \ .after("launch", failing_browser_launcher) second_browser_launcher = pmock.Mock() second_browser_launcher.stubs().type() \ .will(pmock.return_value("launcher2")) second_browser_launcher.expects(pmock.once()) \ .launch(pmock.eq(TestRunner.TEST_URL)) second_browser_launcher.expects(pmock.once()).killAllInstances() self.test_webserver.expects(pmock.once()) \ .testResults() \ .after("launch", second_browser_launcher) self.test_webserver.expects(pmock.once()).shutdown() TestRunner([failing_browser_launcher, second_browser_launcher], self.test_webserver).runTests() failing_browser_launcher.verify() second_browser_launcher.verify()