def testRunTestsLaunchesTestForEachBrowser(self): browser_launchers = [pmock.Mock(), pmock.Mock()] self.test_webserver.expects(pmock.once()).startServing() expected_results = {} launcher_id = 0 for browser_launcher in browser_launchers: browser_launcher.stubs().type() \ .will(pmock.return_value(str(launcher_id))) expected_results[browser_launcher.type()] = "TIMED-OUT" launcher_id += 1 for browser_launcher in browser_launchers: self.test_webserver.expects(pmock.once()) \ .startTest(pmock.eq(TestRunner.TIMEOUT)) \ .will(pmock.return_value(expected_results[browser_launcher.type()])) browser_launcher.expects(pmock.once()) \ .launch(pmock.eq(TestRunner.TEST_URL)) self.test_webserver.expects(pmock.once()).testResults() \ .will(pmock.return_value(expected_results[browser_launcher.type()])) browser_launcher.expects(pmock.once()).killAllInstances() self.test_webserver.expects(pmock.once()).shutdown() aggregated_results = TestRunner(browser_launchers, self.test_webserver).runTests() self.assertEqual(expected_results, aggregated_results) for browser_launcher in browser_launchers: browser_launcher.verify()
def test_cant_take_two_configuration_first_is_default(self): "Hierarchical Configuration - Can take two childs configuration, first child value is returned if exist" fake_config = pmock.Mock() fake_config.expects(pmock.once()).get(pmock.eq("output_folder")).will( pmock.return_value("polop")) other_config = pmock.Mock() configuration = HierarchicalConfiguration([fake_config, other_config]) self.assertEquals("polop", configuration.get("output_folder"))
def setUp(self): self.__create_output_dir self.gears_binaries = "testdata/windows/installers" self.testrunner_mock = pmock.Mock() self.suites_report_mock = pmock.Mock() self.installers = [pmock.Mock(), pmock.Mock()] self.bootstrap = Bootstrap(self.gears_binaries, self.installers, self.testrunner_mock, self.suites_report_mock)
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 testBrowserTypeMustBeUnique(self): browser_launcher1 = pmock.Mock() browser_launcher2 = pmock.Mock() duplicated_type = "same type value" browser_launcher1.stubs().type().will(pmock.return_value(duplicated_type)) browser_launcher2.stubs().type().will(pmock.return_value(duplicated_type)) self.assertRaises(ValueError, TestRunner, [browser_launcher1, browser_launcher2], self.test_webserver)
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 __connectionStub(self): connection = pmock.Mock() connection.stubs().fileno() connection.stubs().setblocking(pmock.eq(0)) connection.stubs().getpeername() connection.stubs().close() return connection
def testCanCompile(self): "JavaFileCompiler - can compile files" executor = pmock.Mock() config = pmock.Mock() classpath = pmock.Mock() config.expects(pmock.once()).get(pmock.eq("javac_command")).will( pmock.return_value("myJavac")) classpath.expects(pmock.once()).getClasspath().will( pmock.return_value("myclasspath")) executor.expects(pmock.once()).run( pmock.eq( "myJavac -cp myclasspath polop/MyClass.java a/pif.java")).will( pmock.return_value(0)) result = JavaFileCompiler(config, classpath, executor).compile( ["polop/MyClass.java", "a/pif.java"]) self.assertEquals(["polop/MyClass.class", "a/pif.class"], result)
def __mockHeaders(self, pmock): headers_mock = pmock.Mock() headers_mock.stubs().getheader(pmock.eq('content-type')) \ .will(pmock.return_value('application/x-www-form-urlencoded')) headers_mock.stubs().getheader(pmock.eq('content-length')) \ .will(pmock.return_value(312)) self.request_handler.headers = headers_mock
def test_cant_take_one_configuration(self): "Hierarchical Configuration - Can take one child configuration" fake_config = pmock.Mock() fake_config.expects(pmock.once()).get(pmock.eq("output_folder")).will( pmock.return_value("polop")) configuration = HierarchicalConfiguration([fake_config]) self.assertEquals("polop", configuration.get("output_folder"))
def testCanLaunchAndReturnFailure(self): "JavaTestLauncher - can launch a file and return a non zero code in case of failure" executor = pmock.Mock() config = pmock.Mock() classpath = pmock.Mock() config.expects(pmock.once()).get(pmock.eq("java_command")).will( pmock.return_value("")) config.expects(pmock.once()).get(pmock.eq("output_folder")).will( pmock.return_value("")) classpath.expects(pmock.once()).getClasspath().will( pmock.return_value("")) classpath.expects(pmock.once()).addDirectory(pmock.eq("")) classpath.expects(pmock.once()).removeDirectory(pmock.eq("")) executor.expects(pmock.once()).method("run").will( pmock.return_value(1)) result = JavaTestLauncher(config, classpath, executor, "").launch("") self.assertEquals(1, result)
def testRaisesExceptionInCaseCompilationFails(self): "JavaFileCompiler - raises exception in case compilation fails" executor = pmock.Mock() config = pmock.Mock() classpath = pmock.Mock() config.expects(pmock.once()).method("get").will(pmock.return_value("")) classpath.expects(pmock.once()).getClasspath().will( pmock.return_value("myclasspath")) executor.expects(pmock.once()).method("run").will( pmock.return_value(1)) try: result = JavaFileCompiler(config, classpath, executor).compile(["polop/MyClass.java"]) self.fail("Should have raised an exception") except Exception, e: self.assertEquals( "Sorry, an exception occured in the compilation process", str(e))
def testCanLaunchAndStopAServer(self): "XmlRpcServer - can be launched and stopped" config = pmock.Mock() config.expects(pmock.once()).get(pmock.eq("server_port")).will( pmock.return_value("8000")) server = XmlRpcServer(config, [__file__]) self.assertNotAvailable() server.launch() self.assertAvailable() server.stop() self.assertNotAvailable()
def testCanLaunchAndReturnOK(self): "JavaTestLauncher - can launch a file and returns OK if executor returns OK" executor = pmock.Mock() config = pmock.Mock() classpath = pmock.Mock() config.expects(pmock.once()).get(pmock.eq("java_command")).will( pmock.return_value("myJava")) config.expects(pmock.once()).get(pmock.eq("output_folder")).will( pmock.return_value("myOutput")) classpath.expects(pmock.once()).getClasspath().will( pmock.return_value("myclasspath")) classpath.expects(pmock.once()).addDirectory(pmock.eq(".")) classpath.expects(pmock.once()).removeDirectory(pmock.eq(".")) executor.expects(pmock.once()).run( pmock. eq("myJava -Dconcordion.output.dir=myOutput -cp myclasspath junit.textui.TestRunner polop.MyClass" ), pmock.eq(True)).will(pmock.return_value(0)) result = JavaTestLauncher(config, classpath, executor, ".").launch("polop/MyClass.class") self.assertEquals(0, result)
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()
def testAddsAndRemovesDirectoriesFromClasspath(self): "JavaTestLauncher - when launching a file it adds the directory to the classpath and removes it after" mock = pmock.Mock() mock.expects(pmock.once()).get(pmock.eq("java_command")).will( pmock.return_value("myJava")) mock.expects(pmock.once()).get(pmock.eq("output_folder")).will( pmock.return_value("myOutput")) mock.expects(pmock.once()).addDirectory(pmock.eq(".")).id("add") mock.expects(pmock.once()).getClasspath().will( pmock.return_value("myclasspath;.")).after("add").id("getPath") mock.expects(pmock.once()).run(pmock.eq("myJava -Dconcordion.output.dir=myOutput -cp myclasspath;. junit.textui.TestRunner polop.MyClass"), pmock.eq(True)) \ .will(pmock.return_value(0)).id("exec").after("getPath") mock.expects(pmock.once()).removeDirectory(pmock.eq(".")).after("exec") JavaTestLauncher(mock, mock, mock, ".").launch("polop/MyClass.class")
def setUp(self): self.server_mock = pmock.Mock() self.server_mock.server_root_dir = "rootdirectory_for_server" self.request_handler = RequestHandler(self.__connectionStub(), pmock.Mock(), self.server_mock)
def __mockRfile(self, post_data, pmock): rfile_mock = pmock.Mock() rfile_mock.stubs().read(pmock.eq(312)).will(pmock.return_value(post_data)) return rfile_mock
def setUp(self): self.test_url = TestRunner.TEST_URL self.test_webserver = pmock.Mock() self.browser_launcher = pmock.Mock() self.browser_launcher.stubs().type().will(pmock.return_value("launcher")) self.browser_launcher.stubs().killAllInstances()