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

Side by Side Diff: tools/autoroller/unittests/roll_chromium_revision_test.py

Issue 2570603003: Autoroller: Support for rolling individual DEPS entries. (Closed)
Patch Set: Updated after review Created 4 years 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 unified diff | Download patch
« no previous file with comments | « tools/autoroller/unittests/DEPS ('k') | tools/autoroller/unittests/testdata/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 # Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 # 3 #
4 # Use of this source code is governed by a BSD-style license 4 # Use of this source code is governed by a BSD-style license
5 # that can be found in the LICENSE file in the root of the source 5 # that can be found in the LICENSE file in the root of the source
6 # tree. An additional intellectual property rights grant can be found 6 # tree. An additional intellectual property rights grant can be found
7 # in the file PATENTS. All contributing project authors may 7 # in the file PATENTS. All contributing project authors may
8 # be found in the AUTHORS file in the root of the source tree. 8 # be found in the AUTHORS file in the root of the source tree.
9 9
10 import glob
10 import os 11 import os
11 import shutil 12 import shutil
12 import sys 13 import sys
13 import tempfile 14 import tempfile
14 import unittest 15 import unittest
15 16
16 17
17 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) 18 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
18 PARENT_DIR = os.path.join(SCRIPT_DIR, os.pardir) 19 PARENT_DIR = os.path.join(SCRIPT_DIR, os.pardir)
19 sys.path.append(PARENT_DIR) 20 sys.path.append(PARENT_DIR)
20 from roll_chromium_revision import ParseDepsDict, UpdateDeps, \ 21 import roll_chromium_revision
21 GetMatchingDepsEntries 22 from roll_chromium_revision import CalculateChangedDepsProper, \
23 GetMatchingDepsEntries, ParseDepsDict, \
24 ParseLocalDepsFile, UpdateDepsFile
25
22 26
23 TEST_DATA_VARS = { 27 TEST_DATA_VARS = {
24 'chromium_git': 'https://chromium.googlesource.com', 28 'chromium_git': 'https://chromium.googlesource.com',
25 'chromium_revision': '1b9c098a08e40114e44b6c1ec33ddf95c40b901d', 29 'chromium_revision': '1b9c098a08e40114e44b6c1ec33ddf95c40b901d',
26 } 30 }
27 31
28 DEPS_ENTRIES = { 32 DEPS_ENTRIES = {
29 'src/build': 'https://build.com', 33 'src/build': 'https://build.com',
30 'src/buildtools': 'https://buildtools.com', 34 'src/buildtools': 'https://buildtools.com',
31 'src/testing/gtest': 'https://gtest.com', 35 'src/testing/gtest': 'https://gtest.com',
32 'src/testing/gmock': 'https://gmock.com', 36 'src/testing/gmock': 'https://gmock.com',
33 } 37 }
34 38
39 BUILD_OLD_REV = '52f7afeca991d96d68cf0507e20dbdd5b845691f'
40 BUILD_NEW_REV = 'HEAD'
41 BUILDTOOLS_OLD_REV = '64e38f0cebdde27aa0cfb405f330063582f9ac76'
42 BUILDTOOLS_NEW_REV = '55ad626b08ef971fd82a62b7abb325359542952b'
43
44
45 class TestError(Exception):
46 pass
47
48
49 class FakeCmd(object):
50 def __init__(self):
51 self.expectations = []
52
53 def add_expectation(self, *args, **kwargs):
54 returns = kwargs.pop('_returns', None)
55 self.expectations.append((args, kwargs, returns))
56
57 def __call__(self, *args, **kwargs):
58 if not self.expectations:
59 raise TestError('Got unexpected\n%s\n%s' % (args, kwargs))
60 exp_args, exp_kwargs, exp_returns = self.expectations.pop(0)
61 if args != exp_args or kwargs != exp_kwargs:
62 message = 'Expected:\n args: %s\n kwargs: %s\n' % (exp_args, exp_kwargs)
63 message += 'Got:\n args: %s\n kwargs: %s\n' % (args, kwargs)
64 raise TestError(message)
65 return exp_returns
66
35 67
36 class TestRollChromiumRevision(unittest.TestCase): 68 class TestRollChromiumRevision(unittest.TestCase):
37 def setUp(self): 69 def setUp(self):
38 self._output_dir = tempfile.mkdtemp() 70 self._output_dir = tempfile.mkdtemp()
39 shutil.copy(os.path.join(SCRIPT_DIR, 'DEPS'), self._output_dir) 71 for test_file in glob.glob(os.path.join(SCRIPT_DIR, 'testdata', '*')):
40 self._deps_filename = os.path.join(self._output_dir, 'DEPS') 72 shutil.copy(test_file, self._output_dir)
73 self._webrtc_depsfile = os.path.join(self._output_dir, 'DEPS')
74 self._old_cr_depsfile = os.path.join(self._output_dir, 'DEPS.chromium.old')
75 self._new_cr_depsfile = os.path.join(self._output_dir, 'DEPS.chromium.new')
76
77 self.fake = FakeCmd()
78 self.old_RunCommand = getattr(roll_chromium_revision, '_RunCommand')
79 setattr(roll_chromium_revision, '_RunCommand', self.fake)
41 80
42 def tearDown(self): 81 def tearDown(self):
43 shutil.rmtree(self._output_dir, ignore_errors=True) 82 shutil.rmtree(self._output_dir, ignore_errors=True)
83 self.assertEqual(self.fake.expectations, [])
84 setattr(roll_chromium_revision, '_RunCommand', self.old_RunCommand)
44 85
45 def testUpdateDeps(self): 86 def testUpdateDepsFile(self):
46 new_rev = 'aaaaabbbbbcccccdddddeeeeefffff0000011111' 87 new_rev = 'aaaaabbbbbcccccdddddeeeeefffff0000011111'
47 88
48 current_rev = TEST_DATA_VARS['chromium_revision'] 89 current_rev = TEST_DATA_VARS['chromium_revision']
49 UpdateDeps(self._deps_filename, current_rev, new_rev) 90 UpdateDepsFile(self._webrtc_depsfile, current_rev, new_rev, [])
50 with open(self._deps_filename) as deps_file: 91 with open(self._webrtc_depsfile) as deps_file:
51 deps_contents = deps_file.read() 92 deps_contents = deps_file.read()
52 self.assertTrue(new_rev in deps_contents, 93 self.assertTrue(new_rev in deps_contents,
53 'Failed to find %s in\n%s' % (new_rev, deps_contents)) 94 'Failed to find %s in\n%s' % (new_rev, deps_contents))
54 95
55 def testParseDepsDict(self): 96 def testParseDepsDict(self):
56 with open(self._deps_filename) as deps_file: 97 with open(self._webrtc_depsfile) as deps_file:
57 deps_contents = deps_file.read() 98 deps_contents = deps_file.read()
58 local_scope = ParseDepsDict(deps_contents) 99 local_scope = ParseDepsDict(deps_contents)
59 vars_dict = local_scope['vars'] 100 vars_dict = local_scope['vars']
60 101
61 def assertVar(variable_name): 102 def assertVar(variable_name):
62 self.assertEquals(vars_dict[variable_name], TEST_DATA_VARS[variable_name]) 103 self.assertEquals(vars_dict[variable_name], TEST_DATA_VARS[variable_name])
63 assertVar('chromium_git') 104 assertVar('chromium_git')
64 assertVar('chromium_revision') 105 assertVar('chromium_revision')
106 self.assertEquals(len(local_scope['deps']), 3)
107 self.assertEquals(len(local_scope['deps_os']), 1)
65 108
66 def testGetMatchingDepsEntriesReturnsPathInSimpleCase(self): 109 def testGetMatchingDepsEntriesReturnsPathInSimpleCase(self):
67 entries = GetMatchingDepsEntries(DEPS_ENTRIES, 'src/testing/gtest') 110 entries = GetMatchingDepsEntries(DEPS_ENTRIES, 'src/testing/gtest')
68 self.assertEquals(len(entries), 1) 111 self.assertEquals(len(entries), 1)
69 self.assertEquals(entries[0], DEPS_ENTRIES['src/testing/gtest']) 112 self.assertEquals(entries[0], DEPS_ENTRIES['src/testing/gtest'])
70 113
71 def testGetMatchingDepsEntriesHandlesSimilarStartingPaths(self): 114 def testGetMatchingDepsEntriesHandlesSimilarStartingPaths(self):
72 entries = GetMatchingDepsEntries(DEPS_ENTRIES, 'src/testing') 115 entries = GetMatchingDepsEntries(DEPS_ENTRIES, 'src/testing')
73 self.assertEquals(len(entries), 2) 116 self.assertEquals(len(entries), 2)
74 117
75 def testGetMatchingDepsEntriesHandlesTwoPathsWithIdenticalFirstParts(self): 118 def testGetMatchingDepsEntriesHandlesTwoPathsWithIdenticalFirstParts(self):
76 entries = GetMatchingDepsEntries(DEPS_ENTRIES, 'src/build') 119 entries = GetMatchingDepsEntries(DEPS_ENTRIES, 'src/build')
77 self.assertEquals(len(entries), 1) 120 self.assertEquals(len(entries), 1)
78 self.assertEquals(entries[0], DEPS_ENTRIES['src/build']) 121 self.assertEquals(entries[0], DEPS_ENTRIES['src/build'])
79 122
123 def testCalculateChangedDepsProper(self):
124 _SetupGitLsRemoteCall(self.fake,
125 'https://chromium.googlesource.com/chromium/src/build', BUILD_NEW_REV)
126 webrtc_deps = ParseLocalDepsFile(self._webrtc_depsfile)
127 new_cr_deps = ParseLocalDepsFile(self._new_cr_depsfile)
128 changed_deps = CalculateChangedDepsProper(webrtc_deps, new_cr_deps)
129 self.assertEquals(len(changed_deps), 2)
130 self.assertEquals(changed_deps[0].path, 'src/build')
131 self.assertEquals(changed_deps[0].current_rev, BUILD_OLD_REV)
132 self.assertEquals(changed_deps[0].new_rev, BUILD_NEW_REV)
133
134 self.assertEquals(changed_deps[1].path, 'src/buildtools')
135 self.assertEquals(changed_deps[1].current_rev, BUILDTOOLS_OLD_REV)
136 self.assertEquals(changed_deps[1].new_rev, BUILDTOOLS_NEW_REV)
137
138 def testCalculateChangedDepsLegacy(self):
139 old_cr_deps = ParseLocalDepsFile(self._old_cr_depsfile)
140 new_cr_deps = ParseLocalDepsFile(self._new_cr_depsfile)
141 changed_deps = CalculateChangedDepsProper(old_cr_deps, new_cr_deps)
142 self.assertEquals(len(changed_deps), 1)
143 self.assertEquals(changed_deps[0].path, 'src/buildtools')
144 self.assertEquals(changed_deps[0].current_rev, BUILDTOOLS_OLD_REV)
145 self.assertEquals(changed_deps[0].new_rev, BUILDTOOLS_NEW_REV)
146
147
148 def _SetupGitLsRemoteCall(cmd_fake, url, revision):
149 cmd = ['git', 'ls-remote', url, revision]
150 cmd_fake.add_expectation(cmd, _returns=(revision, None))
151
152
80 if __name__ == '__main__': 153 if __name__ == '__main__':
81 unittest.main() 154 unittest.main()
OLDNEW
« no previous file with comments | « tools/autoroller/unittests/DEPS ('k') | tools/autoroller/unittests/testdata/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698