def test_zero_values(self): results1 = {"test.one": {"name": "test.one", "output": "test.one", "status": "OK", "time": 1}} results2 = {"test.one": {"name": "test.one", "output": "test.one", "status": "FAIL", "time": 0}} # This must NOT raise ZeroDivisionError diff_ = diff.Diff(results1, results2, 0) self.assertEqual(2, len(diff_.diffs)) diff_ = diff.Diff(results2, results1, 0) self.assertEqual(2, len(diff_.diffs))
def compare(self, verification1=None, verification2=None, output_file=None, output_csv=None, output_html=None, output_json=None, threshold=0): """Compare two verification results. :param verification1: UUID of the first verification :param verification2: UUID of the second verification :param output_file: Path to a file to save results :param output_csv: Display results in CSV format :param output_html: Display results in HTML format :param output_json: Display results in JSON format (Default) :param threshold: Timing difference threshold percentage """ try: res_1 = api.Verification.get( verification1).get_results()["test_cases"] res_2 = api.Verification.get( verification2).get_results()["test_cases"] _diff = diff.Diff(res_1, res_2, 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: --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 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 test_main(self): results1 = {"test.NONE": {"name": "test.NONE", "output": "test.NONE", "status": "SKIPPED", "time": 0.000}, "test.zerofive": {"name": "test.zerofive", "output": "test.zerofive", "status": "FAILED", "time": 0.05}, "test.one": {"name": "test.one", "output": "test.one", "status": "OK", "time": 0.111}, "test.two": {"name": "test.two", "output": "test.two", "status": "OK", "time": 0.222}, "test.three": {"name": "test.three", "output": "test.three", "status": "FAILED", "time": 0.333}, "test.four": {"name": "test.four", "output": "test.four", "status": "OK", "time": 0.444}, "test.five": {"name": "test.five", "output": "test.five", "status": "OK", "time": 0.555} } results2 = {"test.one": {"name": "test.one", "output": "test.one", "status": "FAIL", "time": 0.1111}, "test.two": {"name": "test.two", "output": "test.two", "status": "OK", "time": 0.222}, "test.three": {"name": "test.three", "output": "test.three", "status": "OK", "time": 0.3333}, "test.four": {"name": "test.four", "output": "test.four", "status": "FAIL", "time": 0.4444}, "test.five": {"name": "test.five", "output": "test.five", "status": "OK", "time": 0.555}, "test.six": {"name": "test.six", "output": "test.six", "status": "OK", "time": 0.666}, "test.seven": {"name": "test.seven", "output": "test.seven", "status": "OK", "time": 0.777} } diff_ = diff.Diff(results1, results2, 0) assert len(diff_.diffs) == 10 assert len([test for test in diff_.diffs if test["type"] == "removed_test"]) == 2 assert len([test for test in diff_.diffs if test["type"] == "new_test"]) == 2 assert len([test for test in diff_.diffs if test["type"] == "value_changed"]) == 6 assert diff_.to_csv() != "" assert diff_.to_html() != "" assert diff_.to_json() != ""