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

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

Issue 2581493003: Move tools/autoroller to tools-webrtc/ + rename script (Closed)
Patch Set: Renamed the script 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/roll_chromium_revision.py ('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
(Empty)
1 #!/usr/bin/env python
2 # Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 #
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
6 # tree. An additional intellectual property rights grant can be found
7 # in the file PATENTS. All contributing project authors may
8 # be found in the AUTHORS file in the root of the source tree.
9
10 import glob
11 import os
12 import shutil
13 import sys
14 import tempfile
15 import unittest
16
17
18 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
19 PARENT_DIR = os.path.join(SCRIPT_DIR, os.pardir)
20 sys.path.append(PARENT_DIR)
21 import roll_chromium_revision
22 from roll_chromium_revision import CalculateChangedDepsProper, \
23 GetMatchingDepsEntries, ParseDepsDict, \
24 ParseLocalDepsFile, UpdateDepsFile
25
26
27 TEST_DATA_VARS = {
28 'chromium_git': 'https://chromium.googlesource.com',
29 'chromium_revision': '1b9c098a08e40114e44b6c1ec33ddf95c40b901d',
30 }
31
32 DEPS_ENTRIES = {
33 'src/build': 'https://build.com',
34 'src/buildtools': 'https://buildtools.com',
35 'src/testing/gtest': 'https://gtest.com',
36 'src/testing/gmock': 'https://gmock.com',
37 }
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
67
68 class TestRollChromiumRevision(unittest.TestCase):
69 def setUp(self):
70 self._output_dir = tempfile.mkdtemp()
71 for test_file in glob.glob(os.path.join(SCRIPT_DIR, 'testdata', '*')):
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)
80
81 def tearDown(self):
82 shutil.rmtree(self._output_dir, ignore_errors=True)
83 self.assertEqual(self.fake.expectations, [])
84 setattr(roll_chromium_revision, '_RunCommand', self.old_RunCommand)
85
86 def testUpdateDepsFile(self):
87 new_rev = 'aaaaabbbbbcccccdddddeeeeefffff0000011111'
88
89 current_rev = TEST_DATA_VARS['chromium_revision']
90 UpdateDepsFile(self._webrtc_depsfile, current_rev, new_rev, [])
91 with open(self._webrtc_depsfile) as deps_file:
92 deps_contents = deps_file.read()
93 self.assertTrue(new_rev in deps_contents,
94 'Failed to find %s in\n%s' % (new_rev, deps_contents))
95
96 def testParseDepsDict(self):
97 with open(self._webrtc_depsfile) as deps_file:
98 deps_contents = deps_file.read()
99 local_scope = ParseDepsDict(deps_contents)
100 vars_dict = local_scope['vars']
101
102 def assertVar(variable_name):
103 self.assertEquals(vars_dict[variable_name], TEST_DATA_VARS[variable_name])
104 assertVar('chromium_git')
105 assertVar('chromium_revision')
106 self.assertEquals(len(local_scope['deps']), 3)
107 self.assertEquals(len(local_scope['deps_os']), 1)
108
109 def testGetMatchingDepsEntriesReturnsPathInSimpleCase(self):
110 entries = GetMatchingDepsEntries(DEPS_ENTRIES, 'src/testing/gtest')
111 self.assertEquals(len(entries), 1)
112 self.assertEquals(entries[0], DEPS_ENTRIES['src/testing/gtest'])
113
114 def testGetMatchingDepsEntriesHandlesSimilarStartingPaths(self):
115 entries = GetMatchingDepsEntries(DEPS_ENTRIES, 'src/testing')
116 self.assertEquals(len(entries), 2)
117
118 def testGetMatchingDepsEntriesHandlesTwoPathsWithIdenticalFirstParts(self):
119 entries = GetMatchingDepsEntries(DEPS_ENTRIES, 'src/build')
120 self.assertEquals(len(entries), 1)
121 self.assertEquals(entries[0], DEPS_ENTRIES['src/build'])
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
153 if __name__ == '__main__':
154 unittest.main()
OLDNEW
« no previous file with comments | « tools/autoroller/roll_chromium_revision.py ('k') | tools/autoroller/unittests/testdata/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698