Best Python code snippet using toolium_python
lastline_connector.py
Source:lastline_connector.py
...157 target = entry.get('overview', {}).get('process', {}).get('executable', {}).get('filename', '').split('\\')[-1]158 except Exception as e:159 self.debug_print("Handled File Exception: ", e)160 return 'file', 'Unknown'161 def _update_report_summary(self, report, action_result, task_id):162 action_result.add_data({RESULT_REPORT_KEY: report})163 result_url = self._results_url_template.format(task_id)164 analysis_type, target = self._get_target(report)165 action_result.update_summary({TASK_ID_KEY: task_id,166 RESULTS_URL_KEY: result_url, SUMMARY_TYPE_KEY: analysis_type, TARGET_KEY: target})167 if 'score' in report:168 action_result.update_summary({'score': report['score']})169 return phantom.APP_SUCCESS170 def _poll_task_parse_report(self, task_id, action_result, report=None, task_start_time=None):171 if report is None:172 # first poll for the task status173 ret_val, report = self._poll_task_status(task_id, action_result, task_start_time)174 if phantom.is_fail(ret_val):175 return action_result.get_status()176 if not report:177 return action_result.set_status(phantom.APP_ERROR, LASTLINE_POLL_TIMEOUT.format(task_id))178 ret_val = self._update_report_summary(report, action_result, task_id)179 if phantom.is_fail(ret_val):180 return action_result.get_status()181 return action_result.set_status(phantom.APP_SUCCESS)182 def _get_detonation_result(self, param):183 action_result = self.add_action_result(ActionResult(param))184 task_id = param[TASK_ID_KEY]185 action_result.update_summary({TASK_ID_KEY: task_id, RESULTS_URL_KEY: self._results_url_template.format(task_id)})186 return self._poll_task_parse_report(task_id, action_result)187 def _get_task_id(self, response, action_result):188 task_id = None189 # Now get the data key, should be always present in a success result190 data = response.get('data')191 if not data:192 return action_result.set_status(phantom.APP_ERROR, "Data key not found in response. API failed"), None, None...
visual_test.py
Source:visual_test.py
...210 def _add_result_to_report(self, result, report_name, image_file, baseline_file, message=''):211 self.results[result] += 1212 row = self._get_html_row(result, report_name, image_file, baseline_file, message)213 self._add_data_to_report_before_tag(row, '</tbody>')214 self._update_report_summary()215 def _add_data_to_report_before_tag(self, data, tag):216 with open(os.path.join(self.output_directory, self.report_name), "r+") as f:217 report = f.read()218 index = report.find(tag)219 report = report[:index] + data + report[index:]220 f.seek(0)221 f.write(report)222 def _update_report_summary(self):223 """Update asserts counter in report"""224 new_results = 'Visual asserts</b>: {} ({} failed)'.format(sum(self.results.values()), self.results['diff'])225 with open(os.path.join(self.output_directory, self.report_name), "r+") as f:226 report = f.read()227 report = re.sub(r'Visual asserts</b>: [0-9]* \([0-9]* failed\)', new_results, report)228 f.seek(0)229 f.write(report)230 def _add_summary_to_report(self):231 summary = '<p><b>Execution date</b>: {}</p>'.format(datetime.datetime.now().strftime('%d/%m/%Y %H:%M:%S'))232 summary += '<p><b>Baseline name</b>: {}</p>'.format(path.basename(self.baseline_directory))233 summary += '<p><b>Visual asserts</b>: {} ({} failed)</p>'.format(sum(self.results.values()),234 self.results['diff'])235 self._add_data_to_report_before_tag(summary, '</div>')236 def _get_html_row(self, result, report_name, image_file, baseline_file, message=''):...
generate_report.py
Source:generate_report.py
...285 report_content = file_read.read()286 file_read.close()287 content_new = report_content288 content_new = \289 self._update_report_summary(content_new, detail_info)290 try:291 with open(os.path.abspath(out_report_file_path), "w") \292 as output_fd:293 output_fd.write(content_new)294 except IOError as err_msg:295 print("Error5 for open %s failed, with msg %s" %296 (out_report_file_path, err_msg))297 except IOError as err_msg:298 print("Error6 for open %s failed, with msg %s" %299 (report_tmpl_file_path, err_msg))300 def _get_detail_info(self, benchmark_info):301 detail_info = []302 self.max_index = 1000303 for item_key, item_value in benchmark_info.items():304 if self._is_filtered_id(item_key):305 continue306 item_info = {"item": item_key,307 "id": self._get_index_id(item_key),308 "content": item_value.decode("UTF-8")309 if isinstance(item_value, bytes) else item_value}310 detail_info.append(item_info)311 detail_info = sorted(detail_info, key=lambda s: s["id"])312 dest_detail_info = []313 index = 1314 for item in detail_info:315 item["id"] = index316 dest_detail_info.append(item)317 index += 1318 return dest_detail_info319 def _update_report_summary(self, content_new, detail_info):320 pos = content_new.find(BenchmarkReport.REPORT_SUMMARY)321 if pos >= 0:322 content_new = \323 content_new[0:pos] + \324 str(detail_info) + \325 content_new[pos +326 len(BenchmarkReport.REPORT_SUMMARY):327 len(content_new)]328 return content_new329if __name__ == '__main__':330 print("****************** Benchmark Report Starting ******************")331 BenchmarkReport().generate_benchmark(sys.argv)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!