Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

Unified Diff: tools/release/test_search_related_commits.py

Issue 1098123002: [release-tools] Tool to find related commits (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Made changes, made code testable, added 4 tests Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/release/test_search_related_commits.py
diff --git a/tools/release/test_search_related_commits.py b/tools/release/test_search_related_commits.py
new file mode 100755
index 0000000000000000000000000000000000000000..bdba5e070acc70fb29435771c6d7e44319f46fbd
--- /dev/null
+++ b/tools/release/test_search_related_commits.py
@@ -0,0 +1,210 @@
+#!/usr/bin/env python
+# Copyright 2015 the V8 project authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import unittest
Michael Achenbach 2015/04/28 21:23:51 nit sort by module name
Michael Hablich 2015/04/29 09:22:43 Done.
+import shutil
+from subprocess import Popen, PIPE, check_call
+from os import path
+from collections import namedtuple
+
+import search_related_commits
+
+TEST_CONFIG = {
+ "GIT_REPO": "/tmp/test-v8-search-related-commits",
+}
+
+class TestSearchRelatedCommits(unittest.TestCase):
+
+ base_dir = TEST_CONFIG["GIT_REPO"]
+
+ def _execute_git(self, commands):
Michael Achenbach 2015/04/28 21:23:51 Maybe use *args for commands (e.g. *commands), the
Michael Hablich 2015/04/29 09:22:43 Acknowledged.
+
+ fullCommand = ["git", "-C", self.base_dir] + commands
+ p = Popen(args=fullCommand, stdin=PIPE,
+ stdout=PIPE, stderr=PIPE)
+ output, err = p.communicate()
+ rc = p.returncode
+ if rc != 0:
+ raise Exception(err)
+ return output
+
+ def _add_commit_new_file(self, file_name, message, file_content):
+ #Initial commit
+ f = open(self.base_dir + "/" + file_name, 'w')
Michael Achenbach 2015/04/28 21:23:51 Use "with" statement
Michael Hablich 2015/04/29 09:22:42 Acknowledged.
+ f.write(file_content)
+ f.close()
+
+ self._execute_git(["add", self.base_dir + "/" + file_name])
Michael Achenbach 2015/04/28 21:23:51 Do you need files? There is a flag that allows emp
Michael Hablich 2015/04/29 09:22:43 Acknowledged.
+ self._execute_git(["commit", "-a", "-m", message])
+
+ def setUp(self):
+ if path.exists(self.base_dir):
+ shutil.rmtree(self.base_dir)
+
+ check_call(["git", "init", self.base_dir])
Michael Achenbach 2015/04/28 21:23:52 I like this testing approach! Will look into the d
+
+ #Initial commit
+ message = """[turbofan] Sanitize language mode for javascript operators.
+
+ R=mstarzinger@chromium.org
+
+ Review URL: https://codereview.chromium.org/1084243005
+
+ Cr-Commit-Position: refs/heads/master@{#28059}"""
+ self._add_commit_new_file("first", message, "Content")
+
+ message = """[crankshaft] Do some stuff
+
+ R=hablich@chromium.org
+
+ Review URL: https://codereview.chromium.org/1084243007
+
+ Cr-Commit-Position: refs/heads/master@{#28030}"""
+ self._add_commit_new_file("second", message, "Content2")
+
+ def tearDown(self):
+ if path.exists(self.base_dir):
+ shutil.rmtree(self.base_dir)
+
+ def _assert_correct_standard_result(
+ self, result, all_commits, hash_of_first_commit):
+ self.assertEqual(len(result), 1, "Master commit not found")
+ self.assertEqual(
+ result.keys()[0],
+ hash_of_first_commit,
+ "Master commit is wrong")
+
+ self.assertEqual(
+ len(result[hash_of_first_commit]),
+ 1,
+ "Child commit not found")
+ self.assertEqual(
+ all_commits[2],
+ result[hash_of_first_commit][0],
+ "Child commit wrong")
+
+ def _get_commits(self):
+ commits = self._execute_git(
+ ["log", "--format=%H", "--reverse"]).splitlines()
+ return commits
+
+ def testSearchByCommitPosition(self):
+ f = open(self.base_dir + "/first", 'w')
Michael Achenbach 2015/04/28 21:23:51 use "with" statement and/or extract some helper me
Michael Hablich 2015/04/29 09:22:42 Acknowledged.
+ f.write("reverted stuff")
+ f.close()
+
+ message = """Revert of some stuff.
+ > Cr-Commit-Position: refs/heads/master@{#28059}
+ R=mstarzinger@chromium.org
+
+ Review URL: https://codereview.chromium.org/1084243005
+
+ Cr-Commit-Position: refs/heads/master@{#28088}"""
+
+ self._execute_git(["commit", "-a", "-m", message])
+
+ commits = self._get_commits()
+ hash_of_first_commit = commits[0]
+
+ result = search_related_commits.search_all_related_commits(
+ self.base_dir, hash_of_first_commit, "HEAD",None)
+
+ self._assert_correct_standard_result(result, commits, hash_of_first_commit)
+
+ def testSearchByTitle(self):
+ f = open(self.base_dir + "/first", 'w')
+ f.write("reverted stuff")
+ f.close()
+
+ message = """Revert of some stuff.
+ > [turbofan] Sanitize language mode for javascript operators.
+ > Cr-Commit-Position: refs/heads/master@{#289}
+ R=mstarzinger@chromium.org
+
+ Review URL: https://codereview.chromium.org/1084243005
+
+ Cr-Commit-Position: refs/heads/master@{#28088}"""
+
+ self._execute_git(["commit", "-a", "-m", message])
+
+ commits = self._get_commits()
+ hash_of_first_commit = commits[0]
+
+ result = search_related_commits.search_all_related_commits(
+ self.base_dir, hash_of_first_commit, "HEAD",None)
+
+ self._assert_correct_standard_result(result, commits, hash_of_first_commit)
+
+ def testSearchByHash(self):
+ f = open(self.base_dir + "/first", 'w')
+ f.write("reverted stuff")
+ f.close()
+
+ commits = self._get_commits()
+ hash_of_first_commit = commits[0]
+
+ message = """Revert of some stuff.
+ > [turbofan] Sanitize language mode for javascript operators.
+ > Reverting """ + hash_of_first_commit + """
+ > R=mstarzinger@chromium.org
+
+ Review URL: https://codereview.chromium.org/1084243005
+
+ Cr-Commit-Position: refs/heads/master@{#28088}"""
+
+ self._execute_git(["commit", "-a", "-m", message])
+
+ #Fetch again for an update
+ commits = self._get_commits()
+ hash_of_first_commit = commits[0]
+
+ result = search_related_commits.search_all_related_commits(
+ self.base_dir,
+ hash_of_first_commit,
+ "HEAD",
+ None)
+
+ self._assert_correct_standard_result(result, commits, hash_of_first_commit)
+
+ def testPrettyPrint(self):
+ f = open(self.base_dir + "/first", 'w')
+ f.write("reverted stuff")
+ f.close()
+
+ message = """Revert of some stuff.
+ > [turbofan] Sanitize language mode for javascript operators.
+ > Cr-Commit-Position: refs/heads/master@{#289}
+ R=mstarzinger@chromium.org
+
+ Review URL: https://codereview.chromium.org/1084243005
+
+ Cr-Commit-Position: refs/heads/master@{#28088}"""
+
+ self._execute_git(["commit", "-a", "-m", message])
+
+ commits = self._get_commits()
+ hash_of_first_commit = commits[0]
+ OptionsStruct = namedtuple(
+ "OptionsStruct",
+ "git_dir of until all prettyprint deadline verbose")
+ options = OptionsStruct(
+ git_dir= self.base_dir,
+ of= [hash_of_first_commit],
+ until= [commits[2]],
+ all= True,
+ prettyprint= True,
+ deadline = None,
+ verbose=False)
+ output = []
+ for current_line in search_related_commits.main(options):
+ output.append(current_line)
+
+ self.assertIs(len(output), 2, "Not exactly two entries written")
+ self.assertTrue(output[0].startswith("+"), "Master entry not marked with +")
+ self.assertTrue(output[1].startswith("| "), "Child entry not marked with |")
+
+if __name__ == "__main__":
+ #import sys;sys.argv = ['', 'Test.testName']
+ unittest.main()
« tools/release/search_related_commits.py ('K') | « tools/release/search_related_commits.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698