How to use get_bugs method in Kiwi

Best Python code snippet using Kiwi_python

Diagnosis_Results.py

Source:Diagnosis_Results.py Github

copy

Full Screen

...59 failed_comps = set(self.get_components_in_failed_tests())60 metrics["num_failed_comps"] = len(failed_comps)61 metrics["only_failed_comps"] = len(failed_comps - passed_comps)62 metrics["only_passed_comps"] = len(passed_comps - failed_comps)63 metrics["num_bugs"] = len(self.get_bugs())64 metrics["wasted"] = self.calc_wasted_components()65 metrics["top_k"] = self.calc_top_k()66 metrics["num_comps_in_diagnoses"] = len(self._get_comps_in_diagnoses())67 metrics["bugs_cover_ratio"] = self._get_bugs_cover_ratio()68 metrics["average_trace_size"] = self._get_average_trace_size()69 metrics["average_component_activity"] = self._get_average_component_activity()70 metrics["average_diagnosis_size"] = self._get_average_diagnosis_size()71 metrics["bugs_scores_average"], metrics["bugs_scores_std"], metrics["bugs_scores_entropy"] = self._get_bugs_scores()72 metrics["non_bugs_scores_average"], metrics["non_bugs_scores_std"], metrics["non_bugs_scores_entropy"] = self._get_non_bugs_scores()73 metrics.update(self.cardinality())74 # metrics["ochiai"] = self.calc_ochiai_values()75 return metrics7677 def _get_comps_in_diagnoses(self):78 return reduce(set.__or__, list(map(lambda x: set(x.diagnosis), self.diagnoses)), set())7980 def _get_bugs_cover_ratio(self):81 bugs = self.get_bugs()82 comps = self._get_comps_in_diagnoses()83 return len(set(comps) & set(bugs)) / (len(bugs) * 1.0)8485 def _get_bugs_scores(self):86 bugs = self.get_bugs()87 comps_prob = dict(self.get_components_probabilities())88 bugs_prob = list(map(lambda x: comps_prob.get(x, 0), bugs))89 return np.mean(bugs_prob), np.std(bugs_prob), entropy(bugs_prob)9091 def _get_average_trace_size(self):92 return np.mean(list(map(len, self.pool.values())))9394 def _get_average_diagnosis_size(self):95 return np.mean(list(map(lambda x: len(x.diagnosis), self.diagnoses)))9697 def _get_average_component_activity(self):98 return np.mean(list(Counter(reduce(list.__add__, self.pool.values(), [])).values()))99100 def _get_non_bugs_scores(self):101 bugs = self.get_bugs()102 comps_prob = dict(self.get_components_probabilities())103 non_bugs_prob = list(map(comps_prob.get, filter(lambda c: c not in bugs, comps_prob)))104 return np.mean(non_bugs_prob), np.std(non_bugs_prob), entropy(non_bugs_prob)105106 def _get_metrics_list(self):107 return sorted(self.metrics.items(), key=lambda m:m[0])108109 def get_metrics_values(self):110 return list(map(lambda m:m[1], self._get_metrics_list()))111112 def get_metrics_names(self):113 return list(map(lambda m:m[0], self._get_metrics_list()))114115 def __repr__(self):116 return repr(self.metrics)117118 @staticmethod119 def precision_recall_for_diagnosis(buggedComps, dg, pr, validComps):120 fp = len([i1 for i1 in dg if i1 in validComps])121 fn = len([i1 for i1 in buggedComps if i1 not in dg])122 tp = len([i1 for i1 in dg if i1 in buggedComps])123 tn = len([i1 for i1 in validComps if i1 not in dg])124 if ((tp + fp) == 0):125 precision = "undef"126 else:127 precision = (tp + 0.0) / float(tp + fp)128 a = precision129 precision = precision * float(pr)130 if ((tp + fn) == 0):131 recall = "undef"132 else:133 recall = (tp + 0.0) / float(tp + fn)134 recall = recall * float(pr)135 return precision, recall136137 def calc_precision_recall(self):138 recall_accum=0139 precision_accum=0140 validComps=[x for x in set(reduce(list.__add__, self.pool.values())) if x not in self.get_bugs()]141142 self.diagnoses.sort(key = lambda x: x.probability, reverse = True)143144 self.diagnoses = self.diagnoses[:5]145146 for d in self.diagnoses:147 dg=d.diagnosis148 pr=d.probability149 precision, recall = Diagnosis_Results.precision_recall_for_diagnosis(self.get_bugs(), dg, pr, validComps)150 if(recall!="undef"):151 recall_accum=recall_accum+recall152 if(precision!="undef"):153 precision_accum=precision_accum+precision154 return precision_accum,recall_accum155156 def get_tests(self):157 return self.pool.items()158159 def get_bugs(self):160 return self.bugs161162 def get_initial_tests_traces(self):163 return list(map(lambda test: (sorted(self.pool[test]), self.error[test]), self.initial_tests))164165 def _get_tests_by_error(self, error):166 by_error = list(filter(lambda test: self.error[test] == error, self.initial_tests))167 return dict(map(lambda test: (test, self.pool[test]), by_error))168169 def get_components(self):170 return set(reduce(list.__add__, self.pool.values()))171172 def _get_components_by_error(self, error):173 return set(reduce(list.__add__, self._get_tests_by_error(error).values(), []))174175 def get_components_in_failed_tests(self):176 return self._get_components_by_error(1)177178 def get_components_in_passed_tests(self):179 return self._get_components_by_error(0)180181 def get_components_probabilities(self):182 """183 calculate for each component c the sum of probabilities of the diagnoses that include c184 return dict of (component, probability)185 """186 compsProbs={}187 for d in self.diagnoses:188 p = d.get_prob()189 for comp in d.get_diag():190 compsProbs[comp] = compsProbs.get(comp,0) + p191 return sorted(compsProbs.items(), key=lambda x: x[1], reverse=True)192193 def calc_wasted_components(self):194 components = list(map(lambda x: x[0], self.get_components_probabilities()))195 if len(self.get_bugs()) == 0:196 return len(components)197 wasted = 0.0198 for b in self.get_bugs():199 if b not in components:200 return len(components)201 wasted += components.index(b)202 return wasted / len(self.get_bugs())203204 def calc_expense(self):205 components = list(map(lambda x: x[0], self.get_components_probabilities()))206 total_expense = None207 total_bugs_in_components = 0208 for bug in self.get_bugs():209 if bug in components:210 if total_expense:211 total_expense += ((components.index(bug)/len(components)) * 100)212 total_bugs_in_components += 1213 else:214 total_expense = (components.index(bug)/len(components)) * 100215 total_bugs_in_components += 1216 if total_expense:217 total_expense /= total_bugs_in_components218 if total_expense is None:219 return 100220 return total_expense221222 def calc_exam_score(self):223 components = list(map(lambda x: x[0], self.get_components_probabilities()))224225 for component in components:226 if component in self.get_bugs():227 return ((components.index(component)/len(components)) * 100)228229 return 100230231 def calc_top_k(self):232 components = list(map(lambda x: x[0], self.get_components_probabilities()))233 top_k = None234 for bug in self.get_bugs():235 if bug in components:236 if top_k:237 top_k = max(top_k, components.index(bug))238 else:239 top_k = components.index(bug)240 if top_k is None:241 return len(components)242 return top_k243244 def calc_entropy(self):245 return entropy(list(map(lambda diag: diag.probability, self.diagnoses)))246247 def calc_component_entropy(self):248 return entropy(list(map(lambda x: x[1], self.get_components_probabilities()))) ...

Full Screen

Full Screen

lbench

Source:lbench Github

copy

Full Screen

...61 put_bug(mock)62 if conc:63 wait(pool)64 print(f"Elapsed time: {time.time() - start}s")65def get_bugs(verbose=True) -> dict:66 resp = req.get(f"{BASE_URL}/get")67 j = json.loads(resp.content)68 for b in j["bugs"]:69 if verbose:70 print(f"ID: {b['id']}, Body: {b['body']}")71 return j["bugs"]72def clear_bugs():73 for b in get_bugs(False):74 print(f"Deleting bug #{b['id']}...")75 resp = req.delete(f"{BASE_URL}/delete?id={b['id']}")76if __name__ == "__main__":77 arg = docopt(__doc__)78 try:79 if arg["put"]:80 upload_bugs(int(arg["<num>"]), arg["--concurrent"])81 elif arg["get"]:82 get_bugs()83 elif arg["clear"]:84 clear_bugs()85 except Exception as e:...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Kiwi automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful