Chromium Code Reviews| Index: tools/release/test_mergeinfo.py |
| diff --git a/tools/release/test_mergeinfo.py b/tools/release/test_mergeinfo.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..04c32fc754b4e493abc891e8c748b1dd506f1256 |
| --- /dev/null |
| +++ b/tools/release/test_mergeinfo.py |
| @@ -0,0 +1,125 @@ |
| +#!/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. |
| + |
| +from collections import namedtuple |
| +from os import path |
|
Michael Achenbach
2015/09/17 14:19:00
nit: order
Michael Hablich
2015/09/18 07:38:47
Acknowledged.
|
| +import mergeinfo |
| +import shutil |
| +from subprocess import Popen, PIPE, check_call |
| +import unittest |
| + |
| + |
| +TEST_CONFIG = { |
| + "GIT_REPO": "/tmp/test-v8-search-related-commits", |
| +} |
| + |
| +class TestSearchRelatedCommits(unittest.TestCase): |
| + |
| + base_dir = TEST_CONFIG["GIT_REPO"] |
| + |
| + def _execute_git(self, git_args): |
| + |
| + fullCommand = ["git", "-C", self.base_dir] + git_args |
| + 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 setUp(self): |
| + if path.exists(self.base_dir): |
| + shutil.rmtree(self.base_dir) |
| + |
| + check_call(["git", "init", self.base_dir]) |
| + |
| + # 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._make_empty_commit(message) |
| + |
| + message = """[crankshaft] Do some stuff |
| + |
| + R=hablich@chromium.org |
| + |
| + Review URL: https://codereview.chromium.org/1084243007 |
| + |
| + Cr-Commit-Position: refs/heads/master@{#28030}""" |
| + |
| + self._make_empty_commit(message) |
| + |
| + 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.assertTrue( |
| + result.get(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( |
|
Michael Achenbach
2015/09/17 14:19:00
nit: remove local var?
Michael Hablich
2015/09/18 07:38:47
I think it is easier to debug that way.
|
| + ["log", "--format=%H", "--reverse"]).splitlines() |
| + return commits |
| + |
| + def _make_empty_commit(self, message): |
| + self._execute_git(["commit", "--allow-empty", "-m", message]) |
| + |
| + def testLonelyCommit(self): |
| + message = '''Initial commit''' |
| + self._make_empty_commit(message) |
| + commits = self._get_commits() |
| + hash_of_first_commit = commits[0] |
| + |
| + result = mergeinfo.describe_commit( |
| + self.base_dir, |
| + hash_of_first_commit, |
| + False) |
| + |
| + self.assertEqual( |
| + result, |
| + hash_of_first_commit) |
| + |
| + def testSearchFollowUpCommits(self): |
| + message = 'Initial commit' |
| + self._make_empty_commit(message) |
| + commits = self._get_commits() |
| + hash_of_first_commit = commits[0] |
| + |
| + message = 'Follow-up commit of ' + hash_of_first_commit |
| + self._make_empty_commit(message) |
| + self._make_empty_commit(message) |
| + self._make_empty_commit(message) |
| + message = 'Not related commit' |
| + self._make_empty_commit(message) |
| + |
| + commits = self._get_commits() |
| + |
| + followups = mergeinfo.get_followup_commits( |
| + self.base_dir, |
| + hash_of_first_commit, |
| + False) |
|
Michael Achenbach
2015/09/17 14:19:00
Shoudn't this assert something?"
Michael Hablich
2015/09/18 07:38:47
Right. Currently I am in the process of writing th
|
| + |
| + |
| +if __name__ == "__main__": |
| + #import sys;sys.argv = ['', 'Test.testName'] |
| + unittest.main() |