def compare(self, uuid1=None, uuid2=None, output_file=None, output_csv=None, output_html=None, output_json=None, threshold=0): """Compare two verification results. :param uuid1: First Verification UUID :param uuid2: Second Verification UUID :param output_file: If specified, output will be saved to given file :param output_csv: Save results in csv format to the specified file :param output_html: Save results in html format to the specified file :param output_json: Save results in json format to the specified file (Default) :param threshold: Timing difference threshold percentage """ try: results1 = db.verification_result_get(uuid1)["data"]["test_cases"] results2 = db.verification_result_get(uuid2)["data"]["test_cases"] _diff = diff.Diff(results1, results2, threshold) except exceptions.NotFoundException as e: print(six.text_type(e)) return 1 result = "" if output_json + output_html + output_csv > 1: print("Please specify only one output format, either --json, " "--html or --csv.") return 1 elif output_html: result = _diff.to_html() elif output_csv: result = _diff.to_csv() else: result = _diff.to_json() if output_file: with open(output_file, "wb") as f: if output_csv: writer = csv.writer(f, dialect="excel") writer.writerows(result) else: f.write(result) else: print(result)
def results(self, verification_uuid=None, output_file=None, output_html=None, output_json=None): """Get raw results of the verification. :param verification_uuid: Verification UUID :param output_file: If specified, output will be saved to given file :param output_html: The output will be in HTML format :param output_json: The output will be in JSON format (Default) """ try: results = db.verification_result_get(verification_uuid)["data"] except exceptions.NotFoundException as e: print(six.text_type(e)) return 1 result = "" if output_json + output_html > 1: print("Please specify only one output format.") elif output_html: result = json2html.main(results) else: result = json.dumps(results, sort_keys=True, indent=4) if output_file: output_file = os.path.expanduser(output_file) with open(output_file, "wb") as f: f.write(result) else: print(result)
def results(self, verification_uuid, output_file=None, output_html=None, output_json=None, output_pprint=None): """Print raw results of verification. :param verification_uuid: Verification UUID :param output_file: If specified, output will be saved to given file :param output_html: Save results in html format to the specified file :param output_json: Save results in json format to the specified file (Default) :param output_pprint: Save results in pprint format to the specified file """ try: results = db.verification_result_get(verification_uuid)['data'] except exceptions.NotFoundException as e: print(six.text_type(e)) return 1 result = '' if len(filter(lambda x: bool(x), [output_json, output_pprint, output_html])) > 1: print("Please specify only on output format") return 1 elif output_pprint: result = pprint.pformat(results) elif output_html: result = json2html.main(results) else: result = json.dumps(results) if output_file: with open(output_file, 'wb') as f: f.write(result) else: print(result)
def show(self, verification_uuid=None, sort_by="name", detailed=False): """Display results table of the verification.""" try: sortby_index = ("name", "duration").index(sort_by) except ValueError: print("Sorry, but verification results can't be sorted " "by '%s'." % sort_by) return 1 try: verification = db.verification_get(verification_uuid) tests = db.verification_result_get(verification_uuid) except exceptions.NotFoundException as e: print(six.text_type(e)) return 1 print("Total results of verification:\n") total_fields = [ "UUID", "Deployment UUID", "Set name", "Tests", "Failures", "Created at", "Status" ] common_cliutils.print_list([verification], fields=total_fields) print("\nTests:\n") fields = ["name", "time", "status"] values = map(objects.Verification, six.itervalues(tests.data["test_cases"])) common_cliutils.print_list(values, fields, sortby_index=sortby_index) if detailed: for test in six.itervalues(tests.data["test_cases"]): if test["status"] == "FAIL": formatted_test = ( "=====================================================" "=================\n" "FAIL: %(name)s\n" "Time: %(time)s\n" "Type: %(type)s\n" "-----------------------------------------------------" "-----------------\n" "%(log)s\n") % { "name": test["name"], "time": test["time"], "type": test["failure"]["type"], "log": test["failure"]["log"] } print(formatted_test)
def show(self, verification_uuid, sort_by='name', detailed=False): try: sortby_index = ('name', 'duration').index(sort_by) except ValueError: print("Sorry, but verification results can't be sorted " "by '%s'." % sort_by) return 1 try: verification = db.verification_get(verification_uuid) tests = db.verification_result_get(verification_uuid) except exceptions.NotFoundException as e: print(six.text_type(e)) return 1 print("Total results of verification:\n") total_fields = [ 'UUID', 'Deployment UUID', 'Set name', 'Tests', 'Failures', 'Created at', 'Status' ] common_cliutils.print_list([verification], fields=total_fields) print("\nTests:\n") fields = ['name', 'time', 'status'] values = map(objects.Verification, six.itervalues(tests.data['test_cases'])) common_cliutils.print_list(values, fields, sortby_index=sortby_index) if detailed: for test in six.itervalues(tests.data['test_cases']): if test['status'] == 'FAIL': formatted_test = ( '=====================================================' '=================\n' 'FAIL: %(name)s\n' 'Time: %(time)s\n' 'Type: %(type)s\n' '-----------------------------------------------------' '-----------------\n' '%(log)s\n') % { 'name': test['name'], 'time': test['time'], 'type': test['failure']['type'], 'log': test['failure']['log'] } print(formatted_test)
def show(self, verification_uuid, sort_by='name', detailed=False): try: sortby_index = ('name', 'duration').index(sort_by) except ValueError: print("Sorry, but verification results can't be sorted " "by '%s'." % sort_by) return 1 try: verification = db.verification_get(verification_uuid) tests = db.verification_result_get(verification_uuid) except exceptions.NotFoundException as e: print(six.text_type(e)) return 1 print ("Total results of verification:\n") total_fields = ['UUID', 'Deployment UUID', 'Set name', 'Tests', 'Failures', 'Created at', 'Status'] common_cliutils.print_list([verification], fields=total_fields, sortby_index=total_fields.index( 'Created at')) print ("\nTests:\n") fields = ['name', 'time', 'status'] values = map(objects.Verification, six.itervalues(tests.data['test_cases'])) common_cliutils.print_list(values, fields, sortby_index=sortby_index) if detailed: for test in six.itervalues(tests.data['test_cases']): if test['status'] == 'FAIL': formatted_test = ( '=====================================================' '=================\n' 'FAIL: %(name)s\n' 'Time: %(time)s\n' 'Type: %(type)s\n' '-----------------------------------------------------' '-----------------\n' '%(log)s\n' ) % { 'name': test['name'], 'time': test['time'], 'type': test['failure']['type'], 'log': test['failure']['log']} print (formatted_test)
def show(self, verification_uuid=None, sort_by="name", detailed=False): """Display results table of the verification.""" try: sortby_index = ("name", "duration").index(sort_by) except ValueError: print("Sorry, but verification results can't be sorted " "by '%s'." % sort_by) return 1 try: verification = db.verification_get(verification_uuid) tests = db.verification_result_get(verification_uuid) except exceptions.NotFoundException as e: print(six.text_type(e)) return 1 print ("Total results of verification:\n") total_fields = ["UUID", "Deployment UUID", "Set name", "Tests", "Failures", "Created at", "Status"] common_cliutils.print_list([verification], fields=total_fields) print ("\nTests:\n") fields = ["name", "time", "status"] values = map(objects.Verification, six.itervalues(tests.data["test_cases"])) common_cliutils.print_list(values, fields, sortby_index=sortby_index) if detailed: for test in six.itervalues(tests.data["test_cases"]): if test["status"] == "FAIL": formatted_test = ( "=====================================================" "=================\n" "FAIL: %(name)s\n" "Time: %(time)s\n" "Type: %(type)s\n" "-----------------------------------------------------" "-----------------\n" "%(log)s\n" ) % { "name": test["name"], "time": test["time"], "type": test["failure"]["type"], "log": test["failure"]["log"]} print (formatted_test)
def results(self, verification_uuid, pretty=False): """Print raw results of verification. :param verification_uuid: Verification UUID :param pretty: Pretty print (pprint) or not (json) """ try: results = db.verification_result_get(verification_uuid)['data'] except exceptions.NotFoundException as e: print(six.text_type(e)) return 1 if not pretty or pretty == 'json': print(json.dumps(results)) elif pretty == 'pprint': print() pprint.pprint(results) print() else: print(_("Wrong value for --pretty=%s") % pretty)
def results(self, verification_uuid, pretty=False): """Print raw results of verification. :param verification_uuid: Verification UUID :param pretty: Pretty print (pprint) or not (json) """ try: results = db.verification_result_get(verification_uuid)['data'] except exceptions.NotFoundException as e: print(e.message) return 1 if not pretty or pretty == 'json': print(json.dumps(results)) elif pretty == 'pprint': print() pprint.pprint(results) print() else: print(_("Wrong value for --pretty=%s") % pretty)
def results(self, verification_uuid, output_file=None, output_html=None, output_json=None, output_pprint=None): """Print raw results of verification. :param verification_uuid: Verification UUID :param output_file: If specified, output will be saved to given file :param output_html: Save results in html format to the specified file :param output_json: Save results in json format to the specified file (Default) :param output_pprint: Save results in pprint format to the specified file """ try: results = db.verification_result_get(verification_uuid)['data'] except exceptions.NotFoundException as e: print(six.text_type(e)) return 1 result = '' if len( filter(lambda x: bool(x), [output_json, output_pprint, output_html])) > 1: print("Please specify only on output format") return 1 elif output_pprint: result = pprint.pformat(results) elif output_html: result = json2html.main(results) else: result = json.dumps(results) if output_file: with open(output_file, 'wb') as f: f.write(result) else: print(result)
def get_results(self): try: return db.verification_result_get(self.uuid) except exceptions.NotFoundException: return None