def testPackageFailure(self): """Test packages failed.""" # Supposed to be CPVs, but not actually necessary at the moment. packages = ['a', 'b'] # Should have a non-zero return code when packages fail. result = test.BuildTargetUnitTestResult(1, packages) self.assertFalse(result.success) # Make sure failed packages alone are enough. result = test.BuildTargetUnitTestResult(0, packages) self.assertFalse(result.success)
def testPackageBuildFailure(self): """Test handling of raised BuildPackageFailure.""" tempdir = osutils.TempDir(base_dir=self.tempdir) self.PatchObject(osutils, 'TempDir', return_value=tempdir) pkgs = ['cat/pkg', 'foo/bar'] expected = [('cat', 'pkg'), ('foo', 'bar')] result = test_service.BuildTargetUnitTestResult(1, None) result.failed_cpvs = [ portage_util.SplitCPV(p, strict=False) for p in pkgs ] self.PatchObject(test_service, 'BuildTargetUnitTest', return_value=result) input_msg = self._GetInput(board='board', result_path=self.tempdir) output_msg = self._GetOutput() rc = test_controller.BuildTargetUnitTest(input_msg, output_msg, self.api_config) self.assertEqual( controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE, rc) self.assertTrue(output_msg.failed_packages) failed = [] for pi in output_msg.failed_packages: failed.append((pi.category, pi.package_name)) self.assertCountEqual(expected, failed)
def testBuildTargetUnitTest(self): """Test BuildTargetUnitTest successful call.""" input_msg = self._GetInput(board='board', result_path=self.tempdir) result = test_service.BuildTargetUnitTestResult(0, None) self.PatchObject(test_service, 'BuildTargetUnitTest', return_value=result) tarball_result = os.path.join(input_msg.result_path, 'unit_tests.tar') self.PatchObject(test_service, 'BuildTargetUnitTestTarball', return_value=tarball_result) response = self._GetOutput() test_controller.BuildTargetUnitTest(input_msg, response, self.api_config) self.assertEqual(response.tarball_path, os.path.join(input_msg.result_path, 'unit_tests.tar'))
def testOtherBuildScriptFailure(self): """Test build script failure due to non-package emerge error.""" tempdir = osutils.TempDir(base_dir=self.tempdir) self.PatchObject(osutils, 'TempDir', return_value=tempdir) result = test_service.BuildTargetUnitTestResult(1, None) self.PatchObject(test_service, 'BuildTargetUnitTest', return_value=result) pkgs = ['foo/bar', 'cat/pkg'] blacklist = [portage_util.SplitCPV(p, strict=False) for p in pkgs] input_msg = self._GetInput(board='board', result_path=self.tempdir, empty_sysroot=True, blacklist=blacklist) output_msg = self._GetOutput() rc = test_controller.BuildTargetUnitTest(input_msg, output_msg, self.api_config) self.assertEqual(controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY, rc) self.assertFalse(output_msg.failed_packages)
def testBuildTargetUnitTest(self): """Test BuildTargetUnitTest successful call.""" pkgs = ['foo/bar', 'cat/pkg'] packages = [package_info.SplitCPV(p, strict=False) for p in pkgs] input_msg = self._GetInput(board='board', result_path=self.tempdir, packages=packages) result = test_service.BuildTargetUnitTestResult(0, None) self.PatchObject(test_service, 'BuildTargetUnitTest', return_value=result) tarball_result = os.path.join(input_msg.result_path, 'unit_tests.tar') self.PatchObject(test_service, 'BuildTargetUnitTestTarball', return_value=tarball_result) response = self._GetOutput() test_controller.BuildTargetUnitTest(input_msg, response, self.api_config) self.assertEqual(response.tarball_path, os.path.join(input_msg.result_path, 'unit_tests.tar'))
def testScriptFailure(self): """Test non-package failure.""" # Should have a non-zero return code when packages fail. result = test.BuildTargetUnitTestResult(1, None) self.assertFalse(result.success)
def testSuccess(self): """Test success case.""" result = test.BuildTargetUnitTestResult(0, None) self.assertTrue(result.success)