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

Unified Diff: tests/presubmit_unittest.py

Issue 178223016: Support multiple try masters when sending tries to rietveld. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: More review. Created 6 years, 10 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
« no previous file with comments | « rietveld.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/presubmit_unittest.py
diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py
index 28bf5bcecf12870cdb97fb3333ecb6fe99f6512e..6c2c8b3a6022085ab50a3f3bb2d44b20f8ed1f8e 100755
--- a/tests/presubmit_unittest.py
+++ b/tests/presubmit_unittest.py
@@ -8,6 +8,7 @@
# pylint: disable=E1101,E1103
import functools
+import itertools
import logging
import os
import StringIO
@@ -60,6 +61,11 @@ def GetPreferredTrySlaves(project):
return %s
"""
+ presubmit_trymaster = """
+def GetPreferredTryMasters(project, change):
+ return %s
+"""
+
presubmit_diffs = """
--- file1 2011-02-09 10:38:16.517224845 -0800
+++ file2 2011-02-09 10:38:53.177226516 -0800
@@ -170,7 +176,8 @@ class PresubmitUnittest(PresubmitTestsBase):
'marshal', 'normpath', 'optparse', 'os', 'owners', 'pickle',
'presubmit_canned_checks', 'random', 're', 'rietveld', 'scm',
'subprocess', 'sys', 'tempfile', 'time', 'traceback', 'types', 'unittest',
- 'urllib2', 'warn', 'multiprocessing',
+ 'urllib2', 'warn', 'multiprocessing', 'DoGetTryMasters',
+ 'GetTryMastersExecuter', 'itertools',
]
# If this test fails, you should add the relevant test.
self.compareMembers(presubmit, members)
@@ -1027,6 +1034,103 @@ def CheckChangeOnCommit(input_api, output_api):
except presubmit.PresubmitFailure:
pass
+ def testGetTryMastersExecuter(self):
+ self.mox.ReplayAll()
+ change = presubmit.Change(
+ 'foo',
+ 'Blah Blah\n\nSTORY=http://tracker.com/42\nBUG=boo\n',
+ self.fake_root_dir,
+ None,
+ 0,
+ 0,
+ None)
+ executer = presubmit.GetTryMastersExecuter()
+ self.assertEqual({}, executer.ExecPresubmitScript('', '', '', change))
+ self.assertEqual({},
+ executer.ExecPresubmitScript('def foo():\n return\n', '', '', change))
+
Michael Achenbach 2014/03/01 01:30:40 After removing the checks, there are no bad result
+ expected_result = {'m1': {'s1': set(['t1', 't2'])},
+ 'm2': {'s1': set(['defaulttests']),
+ 's2': set(['defaulttests'])}}
+ empty_result1 = {}
+ empty_result2 = {'m': {}}
+ space_in_name_result = {'m r': {'s\tv': set(['t1'])}}
+ for result in (
+ expected_result, empty_result1, empty_result2, space_in_name_result):
+ self.assertEqual(
+ result,
+ executer.ExecPresubmitScript(
+ self.presubmit_trymaster % result, '', '', change))
+
+ def testMergeMasters(self):
+ merge = presubmit._MergeMasters
+ self.assertEqual({}, merge({}, {}))
+ self.assertEqual({'m1': {}}, merge({}, {'m1': {}}))
+ self.assertEqual({'m1': {}}, merge({'m1': {}}, {}))
+ parts = [
+ {'try1.cr': {'win': set(['defaulttests'])}},
+ {'try1.cr': {'linux1': set(['test1'])},
+ 'try2.cr': {'linux2': set(['defaulttests'])}},
+ {'try1.cr': {'mac1': set(['defaulttests']),
+ 'mac2': set(['test1', 'test2']),
+ 'linux1': set(['defaulttests'])}},
+ ]
+ expected = {
+ 'try1.cr': {'win': set(['defaulttests']),
+ 'linux1': set(['defaulttests', 'test1']),
+ 'mac1': set(['defaulttests']),
+ 'mac2': set(['test1', 'test2'])},
+ 'try2.cr': {'linux2': set(['defaulttests'])},
+ }
+ for permutation in itertools.permutations(parts):
+ self.assertEqual(expected, reduce(merge, permutation, {}))
+
+ def testDoGetTryMasters(self):
+ root_text = (self.presubmit_trymaster
+ % '{"t1.cr": {"win": set(["defaulttests"])}}')
+ linux_text = (self.presubmit_trymaster
+ % ('{"t1.cr": {"linux1": set(["t1"])},'
+ ' "t2.cr": {"linux2": set(["defaulttests"])}}'))
+
+ join = presubmit.os.path.join
+ isfile = presubmit.os.path.isfile
+ FileRead = presubmit.gclient_utils.FileRead
+ filename = 'foo.cc'
+ filename_linux = join('linux_only', 'penguin.cc')
+ root_presubmit = join(self.fake_root_dir, 'PRESUBMIT.py')
+ linux_presubmit = join(self.fake_root_dir, 'linux_only', 'PRESUBMIT.py')
+ inherit_path = join(self.fake_root_dir, self._INHERIT_SETTINGS)
+
+ isfile(inherit_path).AndReturn(False)
+ isfile(root_presubmit).AndReturn(True)
+ FileRead(root_presubmit, 'rU').AndReturn(root_text)
+
+ isfile(inherit_path).AndReturn(False)
+ isfile(root_presubmit).AndReturn(True)
+ isfile(linux_presubmit).AndReturn(True)
+ FileRead(root_presubmit, 'rU').AndReturn(root_text)
+ FileRead(linux_presubmit, 'rU').AndReturn(linux_text)
+ self.mox.ReplayAll()
+
+ change = presubmit.Change(
+ 'mychange', '', self.fake_root_dir, [], 0, 0, None)
+
+ output = StringIO.StringIO()
+ self.assertEqual({'t1.cr': {'win': ['defaulttests']}},
+ presubmit.DoGetTryMasters(change, [filename],
+ self.fake_root_dir,
+ None, None, False, output))
+ output = StringIO.StringIO()
+ expected = {
+ 't1.cr': {'win': ['defaulttests'], 'linux1': ['t1']},
+ 't2.cr': {'linux2': ['defaulttests']},
+ }
+ self.assertEqual(expected,
+ presubmit.DoGetTryMasters(change,
+ [filename, filename_linux],
+ self.fake_root_dir, None, None,
+ False, output))
+
def testMainUnversioned(self):
# OptParser calls presubmit.os.path.exists and is a pain when mocked.
self.UnMock(presubmit.os.path, 'exists')
« no previous file with comments | « rietveld.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698