def test_run(self, mock_parser, mock_skip, mock_version, mock_instance): testcase = TestcaseContainer.find_testcases("examples.test_cmdline", "./examples", self.tc_meta_schema)[0] # Initialize mocks parser = mock.MagicMock() instance = mock.MagicMock() instance.run = mock.MagicMock() instance.run.return_value = 0 instance.get_result = mock.MagicMock() instance.get_result.return_value = Result() mock_instance.return_value = instance mock_skip.return_value = None mock_version.return_value = None parser.parse_known_args = mock.MagicMock() parser.parse_known_args.return_value = (mock.MagicMock(), []) mock_parser.return_value = parser # Mocked a succesful run testcase.run() # Skip returns 1, tc should be skipped mock_skip.return_value = 1 mock_version.return_value = None self.assertEqual(testcase.status, TestStatus.FINISHED) testcase.run() # Version mismatch mock_skip.return_value = None mock_version.return_value = 1 self.assertEqual(testcase.status, TestStatus.FINISHED) testcase.run() # Unknown arguments mock_version.return_value = None parser.parse_known_args.return_value = (self.args_tc, [1]) res = testcase.run() self.assertEqual(testcase.status, TestStatus.FINISHED) self.assertEqual(res.get_verdict(), 'inconclusive') result = Result() result.retcode = 1012 instance.get_result.return_value = result instance.run.return_value = 1012 parser.parse_known_args.return_value = (mock.MagicMock(), []) testcase.run()
def append_result(self, tc_file=None): """ Append a new fully constructed Result to the internal ResultList. :param tc_file: Test case file path :return: Nothing """ result = Result() result.set_tc_metadata(self._configuration.config) tc_rev = get_git_info(self._configuration.get_tc_abspath(tc_file), verbose=self._args.verbose) if self._logger: self._logger.debug(tc_rev) result.set_tc_git_info(tc_rev) result.component = self._configuration.get_test_component() result.feature = self._configuration.get_features_under_test() result.skip_reason = self._configuration.skip_reason() if self._configuration.skip() else '' result.fail_reason = self._failreason result.logpath = os.path.abspath(LogManager.get_base_dir()) result.logfiles = LogManager.get_logfiles() result.retcode = self.retcode result.set_dutinformation(self._resources.dutinformations) # pylint: disable=unused-variable for platform, serialnumber in zip(self._resources.get_platforms(), self._resources.get_serialnumbers()): # Zipping done to keep platforms and serial numbers aligned in case some sn:s are # missing result.dut_vendor.append('') result.dut_resource_id.append(serialnumber) result.dut_count = self._resources.get_dut_count() result.duts = self._resources.resource_configuration.get_dut_configuration() if self._resources.resource_configuration.count_hardware() > 0: result.dut_type = 'hw' elif self._resources.resource_configuration.count_process() > 0: result.dut_type = 'process' else: result.dut_type = None self._result_list.append(result)