def testCheckFilesAgainstDEPSRollWithUnrelatedLinesChanged(self): failure_signal_json = { 'files': { 'src/third_party/dep1/f.cc': [123], } } change_log_json = { 'revision': 'rev', 'touched_files': [ { 'change_type': ChangeType.MODIFY, 'old_path': 'DEPS', 'new_path': 'DEPS' }, ] } deps_info = { 'deps_rolls': { 'rev': [ { 'path': 'src/third_party/dep1/', 'repo_url': 'https://url_dep1', 'old_revision': '7', 'new_revision': '9', }, ] } } self.mock(GitilesRepository, 'GetChangeLog', self._MockGetChangeLog) self.mock(GitilesRepository, 'GetCommitsBetweenRevisions', self._MockGetCommitsBetweenRevisions) self.mock(GitilesRepository, 'GetBlame', self._MockGetBlame) justification = build_failure_analysis._CheckFiles( FailureSignal.FromDict(failure_signal_json), change_log_json, deps_info) self.assertIsNotNone(justification) # The score is 1 because: # +1 rolled third_party/dep1/ and src/third_party/dep1/f.cc was in log. self.assertEqual(1, justification['score'])
def testCheckFilesAgainstUnrelatedCL(self): failure_signal_json = { 'files': { 'src/a/b/f.cc': [], } } change_log_json = { 'revision': 'rev', 'touched_files': [ { 'change_type': ChangeType.ADD, 'old_path': '/dev/null', 'new_path': 'a/d/f1.cc' }, ] } deps_info = {} justification = build_failure_analysis._CheckFiles( FailureSignal.FromDict(failure_signal_json), change_log_json, deps_info) self.assertIsNone(justification)
def testCheckFilesAgainstDEPSRoll(self): failure_signal_json = { 'files': { 'src/third_party/dep1/f.cc': [123], } } change_log_json = { 'revision': 'rev', 'touched_files': [ { 'change_type': ChangeType.MODIFY, 'old_path': 'DEPS', 'new_path': 'DEPS' }, ] } deps_info = { 'deps_rolls': { 'rev': [ { 'path': 'src/third_party/dep1/', 'repo_url': 'https://url_dep1', 'old_revision': '7', 'new_revision': '9', }, ] } } self.mock(GitRepository, 'GetChangeLog', self._MockGetChangeLog) self.mock(GitRepository, 'GetBlame', self._MockGetBlame) justification = build_failure_analysis._CheckFiles( FailureSignal.FromDict(failure_signal_json), change_log_json, deps_info) self.assertIsNotNone(justification) # The score is 1 because: # +1 rolled third_party/dep1/ and src/third_party/dep1/f.cc was in log. self.assertEqual(1, justification['score'])
def testCheckFilesAgainstSuspectedCL(self): failure_signal_json = { 'files': { 'src/a/b/f1.cc': [], 'd/e/a2_test.cc': [], 'b/c/f2.cc': [10, 20], 'd/e/f3.h': [], 'x/y/f4.py': [], 'f5_impl.cc': [] } } change_log_json = { 'revision': 'rev', 'touched_files': [ { 'change_type': ChangeType.ADD, 'old_path': '/dev/null', 'new_path': 'a/b/f1.cc' }, { 'change_type': ChangeType.ADD, 'old_path': '/dev/null', 'new_path': 'd/e/a2.cc' }, { 'change_type': ChangeType.MODIFY, 'old_path': 'a/b/c/f2.h', 'new_path': 'a/b/c/f2.h' }, { 'change_type': ChangeType.MODIFY, 'old_path': 'd/e/f3.h', 'new_path': 'd/e/f3.h' }, { 'change_type': ChangeType.DELETE, 'old_path': 'x/y/f4.py', 'new_path': '/dev/null' }, { 'change_type': ChangeType.DELETE, 'old_path': 'h/f5.h', 'new_path': '/dev/null' }, { 'change_type': ChangeType.RENAME, 'old_path': 't/y/x.cc', 'new_path': 's/z/x.cc' }, ] } deps_info = {} justification = build_failure_analysis._CheckFiles( FailureSignal.FromDict(failure_signal_json), change_log_json, deps_info) self.assertIsNotNone(justification) # The score is 15 because: # +5 added a/b/f1.cc (same file src/a/b/f1.cc in failure_signal log) # +1 added d/e/a2.cc (related file a2_test.cc in failure_signal log) # +1 modified b/c/f2.h (related file a/b/c/f2.cc in failure_signal log) # +2 modified d/e/f3.h (same file d/e/f3.h in failure_signal log) # +5 deleted x/y/f4.py (same file x/y/f4.py in failure_signal log) # +1 deleted h/f5.h (related file f5_impl.cc in failure_signal log) # +0 renamed t/y/x.cc -> s/z/x.cc (no related file in failure_signal log) self.assertEqual(15, justification['score'])