| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import os | 5 import os |
| 6 import re | 6 import re |
| 7 | 7 |
| 8 from google.appengine.ext import testbed | 8 from google.appengine.ext import testbed |
| 9 | 9 |
| 10 import webapp2 | 10 import webapp2 |
| (...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 'first_failure': 122, | 775 'first_failure': 122, |
| 776 'last_pass': 121, | 776 'last_pass': 121, |
| 777 'suspected_cls_by_heuristic': [], | 777 'suspected_cls_by_heuristic': [], |
| 778 } | 778 } |
| 779 | 779 |
| 780 data = {} | 780 data = {} |
| 781 build_failure._PopulateHeuristicDataForCompileFailure( | 781 build_failure._PopulateHeuristicDataForCompileFailure( |
| 782 analysis, data) | 782 analysis, data) |
| 783 self.assertEqual(expected_data, data) | 783 self.assertEqual(expected_data, data) |
| 784 | 784 |
| 785 def _PercentFormat(self, float_number): |
| 786 return '%d%%' % (round(float_number * 100)) |
| 787 |
| 785 def testGetTryJobResultForCompileFailure(self): | 788 def testGetTryJobResultForCompileFailure(self): |
| 786 analysis = WfAnalysis.Create('m', 'b', 123) | 789 analysis = WfAnalysis.Create('m', 'b', 123) |
| 787 analysis.result = { | 790 analysis.result = { |
| 788 'failures': [ | 791 'failures': [ |
| 789 { | 792 { |
| 790 'step_name': 'compile', | 793 'step_name': 'compile', |
| 791 'first_failure': 122, | 794 'first_failure': 122, |
| 792 'last_pass': 121, | 795 'last_pass': 121, |
| 793 'suspected_cls': [], | 796 'suspected_cls': [], |
| 794 }, | 797 }, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 'failed': False, | 851 'failed': False, |
| 849 } | 852 } |
| 850 | 853 |
| 851 expected_suspected_cls = [ | 854 expected_suspected_cls = [ |
| 852 { | 855 { |
| 853 'repo_name': 'chromium', | 856 'repo_name': 'chromium', |
| 854 'revision': 'rev', | 857 'revision': 'rev', |
| 855 'commit_position': 122, | 858 'commit_position': 122, |
| 856 'url': None, | 859 'url': None, |
| 857 'status': suspected_cl_status.CORRECT, | 860 'status': suspected_cl_status.CORRECT, |
| 858 'confidence': build_failure._PercentFormat( | 861 'confidence': self._PercentFormat( |
| 859 self.cl_confidences.compile_heuristic_try_job.confidence) | 862 self.cl_confidences.compile_heuristic_try_job.confidence) |
| 860 } | 863 } |
| 861 ] | 864 ] |
| 862 | 865 |
| 863 build_url = buildbot.CreateBuildUrl('m', 'b', 123) | 866 build_url = buildbot.CreateBuildUrl('m', 'b', 123) |
| 864 response = self.test_app.get('/build-failure', | 867 response = self.test_app.get('/build-failure', |
| 865 params={'url': build_url, 'format': 'json'}) | 868 params={'url': build_url, 'format': 'json'}) |
| 866 | 869 |
| 867 self.assertEquals(200, response.status_int) | 870 self.assertEquals(200, response.status_int) |
| 868 self.assertEqual(expected_try_job_result, response.json_body['try_job']) | 871 self.assertEqual(expected_try_job_result, response.json_body['try_job']) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 'commit_position': 122, | 905 'commit_position': 122, |
| 903 'url': None, | 906 'url': None, |
| 904 'status': None, | 907 'status': None, |
| 905 'confidence': None | 908 'confidence': None |
| 906 } | 909 } |
| 907 ] | 910 ] |
| 908 | 911 |
| 909 suspected_cls = build_failure._GetAllSuspectedCLsAndCheckStatus( | 912 suspected_cls = build_failure._GetAllSuspectedCLsAndCheckStatus( |
| 910 master_name, builder_name, build_number, analysis) | 913 master_name, builder_name, build_number, analysis) |
| 911 self.assertEqual( | 914 self.assertEqual( |
| 912 expected_suspected_cls, suspected_cls) | 915 expected_suspected_cls, suspected_cls) |
| 913 | |
| 914 def testGetConfidenceScoreTestHeuristic(self): | |
| 915 build = { | |
| 916 'failure_type': failure_type.TEST, | |
| 917 'failures': None, | |
| 918 'status': suspected_cl_status.CORRECT, | |
| 919 'approaches': [analysis_approach_type.HEURISTIC], | |
| 920 'top_score': 5 | |
| 921 } | |
| 922 | |
| 923 self.assertEqual( | |
| 924 build_failure._PercentFormat( | |
| 925 self.cl_confidences.test_heuristic[1].confidence), | |
| 926 build_failure._GetConfidenceScore(self.cl_confidences, build)) | |
| 927 | |
| 928 def testGetConfidenceScoreCompileHeuristic(self): | |
| 929 build = { | |
| 930 'failure_type': failure_type.COMPILE, | |
| 931 'failures': None, | |
| 932 'status': suspected_cl_status.CORRECT, | |
| 933 'approaches': [analysis_approach_type.HEURISTIC], | |
| 934 'top_score': 4 | |
| 935 } | |
| 936 | |
| 937 self.assertEqual( | |
| 938 build_failure._PercentFormat( | |
| 939 self.cl_confidences.compile_heuristic[1].confidence), | |
| 940 build_failure._GetConfidenceScore(self.cl_confidences, build)) | |
| 941 | |
| 942 def testGetConfidenceScoreTestTryJob(self): | |
| 943 build = { | |
| 944 'failure_type': failure_type.TEST, | |
| 945 'failures': None, | |
| 946 'status': suspected_cl_status.CORRECT, | |
| 947 'approaches': [analysis_approach_type.TRY_JOB], | |
| 948 'top_score': 5 | |
| 949 } | |
| 950 | |
| 951 self.assertEqual( | |
| 952 build_failure._PercentFormat( | |
| 953 self.cl_confidences.test_try_job.confidence), | |
| 954 build_failure._GetConfidenceScore(self.cl_confidences, build)) | |
| 955 | |
| 956 def testGetConfidenceScoreCompileTryJob(self): | |
| 957 build = { | |
| 958 'failure_type': failure_type.COMPILE, | |
| 959 'failures': None, | |
| 960 'status': suspected_cl_status.CORRECT, | |
| 961 'approaches': [analysis_approach_type.TRY_JOB], | |
| 962 'top_score': 5 | |
| 963 } | |
| 964 | |
| 965 self.assertEqual( | |
| 966 build_failure._PercentFormat( | |
| 967 self.cl_confidences.test_try_job.confidence), | |
| 968 build_failure._GetConfidenceScore(self.cl_confidences, build)) | |
| 969 | |
| 970 def testGetConfidenceScoreTestHeuristicTryJob(self): | |
| 971 build = { | |
| 972 'failure_type': failure_type.TEST, | |
| 973 'failures': None, | |
| 974 'status': suspected_cl_status.CORRECT, | |
| 975 'approaches': [analysis_approach_type.HEURISTIC, | |
| 976 analysis_approach_type.TRY_JOB], | |
| 977 'top_score': 5 | |
| 978 } | |
| 979 | |
| 980 self.assertEqual( | |
| 981 build_failure._PercentFormat( | |
| 982 self.cl_confidences.test_heuristic_try_job.confidence), | |
| 983 build_failure._GetConfidenceScore(self.cl_confidences, build)) | |
| 984 | |
| 985 def testGetConfidenceScoreNone(self): | |
| 986 self.assertIsNone(build_failure._GetConfidenceScore(None, None)) | |
| 987 | |
| 988 def testGetConfidenceScoreUnexpected(self): | |
| 989 build = { | |
| 990 'failure_type': failure_type.COMPILE, | |
| 991 'failures': None, | |
| 992 'status': suspected_cl_status.CORRECT, | |
| 993 'approaches': [analysis_approach_type.HEURISTIC], | |
| 994 'top_score': 2 | |
| 995 } | |
| 996 | |
| 997 self.assertIsNone(build_failure._GetConfidenceScore( | |
| 998 self.cl_confidences, build)) | |
| 999 | |
| 1000 def testGetConfidenceScoreCompileNone(self): | |
| 1001 build = { | |
| 1002 'failure_type': failure_type.COMPILE, | |
| 1003 'approaches': [] | |
| 1004 } | |
| 1005 self.assertIsNone(build_failure._GetConfidenceScore( | |
| 1006 self.cl_confidences, build)) | |
| 1007 | |
| 1008 def testGetConfidenceScoreUnexpectedTest(self): | |
| 1009 build = { | |
| 1010 'failure_type': failure_type.TEST, | |
| 1011 'failures': None, | |
| 1012 'status': suspected_cl_status.CORRECT, | |
| 1013 'approaches': [analysis_approach_type.HEURISTIC], | |
| 1014 'top_score': 2 | |
| 1015 } | |
| 1016 | |
| 1017 self.assertIsNone(build_failure._GetConfidenceScore( | |
| 1018 self.cl_confidences, build)) | |
| 1019 | |
| 1020 def testGetConfidenceScoreTestNone(self): | |
| 1021 build = { | |
| 1022 'failure_type': failure_type.TEST, | |
| 1023 'approaches': [] | |
| 1024 } | |
| 1025 self.assertIsNone(build_failure._GetConfidenceScore( | |
| 1026 self.cl_confidences, build)) | |
| 1027 | |
| 1028 def testPercentFormatNone(self): | |
| 1029 self.assertIsNone(build_failure._PercentFormat(None)) | |
| OLD | NEW |