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

Side by Side Diff: cros_mark_as_stable_unittest.py

Issue 3266004: Move RunCommand, and Info/Warning/Die into common pylib (Closed) Base URL: ssh://git@chromiumos-git//crosutils.git
Patch Set: rebased Created 10 years, 3 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 unified diff | Download patch
« no previous file with comments | « cros_mark_as_stable.py ('k') | generate_test_report.py » ('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/python 1 #!/usr/bin/python
2 2
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Unit tests for cros_mark_as_stable.py.""" 7 """Unit tests for cros_mark_as_stable.py."""
8 8
9 9
10 import mox 10 import mox
11 import os 11 import os
12 import sys 12 import sys
13 import unittest 13 import unittest
14 14
15 # Required to include '.' in the python path. 15 # Required to include '.' in the python path.
16 sys.path.append(os.path.dirname(__file__)) 16 sys.path.append(os.path.dirname(__file__))
17 import cros_mark_as_stable 17 import cros_mark_as_stable
18 18
19 class GitBranchTest(mox.MoxTestBase): 19 class GitBranchTest(mox.MoxTestBase):
20 20
21 def setUp(self): 21 def setUp(self):
22 mox.MoxTestBase.setUp(self) 22 mox.MoxTestBase.setUp(self)
23 # Always stub RunCommmand out as we use it in every method. 23 # Always stub RunCommmand out as we use it in every method.
24 self.mox.StubOutWithMock(cros_mark_as_stable, '_RunCommand') 24 self.mox.StubOutWithMock(cros_mark_as_stable, '_SimpleRunCommand')
25 self._branch = 'test_branch' 25 self._branch = 'test_branch'
26 26
27 def testCreateBranchNoPrevious(self): 27 def testCreateBranchNoPrevious(self):
28 # Test init with no previous branch existing. 28 # Test init with no previous branch existing.
29 branch = cros_mark_as_stable._GitBranch(self._branch) 29 branch = cros_mark_as_stable._GitBranch(self._branch)
30 self.mox.StubOutWithMock(branch, 'Exists') 30 self.mox.StubOutWithMock(branch, 'Exists')
31 self.mox.StubOutWithMock(branch, '_Checkout') 31 self.mox.StubOutWithMock(branch, '_Checkout')
32 branch.Exists().AndReturn(False) 32 branch.Exists().AndReturn(False)
33 branch._Checkout(self._branch) 33 branch._Checkout(self._branch)
34 self.mox.ReplayAll() 34 self.mox.ReplayAll()
35 branch.CreateBranch() 35 branch.CreateBranch()
36 self.mox.VerifyAll() 36 self.mox.VerifyAll()
37 37
38 def testCreateBranchWithPrevious(self): 38 def testCreateBranchWithPrevious(self):
39 # Test init with previous branch existing. 39 # Test init with previous branch existing.
40 branch = cros_mark_as_stable._GitBranch(self._branch) 40 branch = cros_mark_as_stable._GitBranch(self._branch)
41 self.mox.StubOutWithMock(branch, 'Exists') 41 self.mox.StubOutWithMock(branch, 'Exists')
42 self.mox.StubOutWithMock(branch, 'Delete') 42 self.mox.StubOutWithMock(branch, 'Delete')
43 self.mox.StubOutWithMock(branch, '_Checkout') 43 self.mox.StubOutWithMock(branch, '_Checkout')
44 branch.Exists().AndReturn(True) 44 branch.Exists().AndReturn(True)
45 branch.Delete() 45 branch.Delete()
46 branch._Checkout(self._branch) 46 branch._Checkout(self._branch)
47 self.mox.ReplayAll() 47 self.mox.ReplayAll()
48 branch.CreateBranch() 48 branch.CreateBranch()
49 self.mox.VerifyAll() 49 self.mox.VerifyAll()
50 50
51 def testCheckoutCreate(self): 51 def testCheckoutCreate(self):
52 # Test init with no previous branch existing. 52 # Test init with no previous branch existing.
53 cros_mark_as_stable._RunCommand('git checkout -b %s origin' % self._branch) 53 cros_mark_as_stable._SimpleRunCommand(
54 'git checkout -b %s cros/master' % self._branch)
54 self.mox.ReplayAll() 55 self.mox.ReplayAll()
55 branch = cros_mark_as_stable._GitBranch(self._branch) 56 branch = cros_mark_as_stable._GitBranch(self._branch)
56 branch._Checkout(self._branch) 57 branch._Checkout(self._branch)
57 self.mox.VerifyAll() 58 self.mox.VerifyAll()
58 59
59 def testCheckoutNoCreate(self): 60 def testCheckoutNoCreate(self):
60 # Test init with previous branch existing. 61 # Test init with previous branch existing.
61 cros_mark_as_stable._RunCommand('git checkout master') 62 cros_mark_as_stable._SimpleRunCommand('git checkout cros/master')
62 self.mox.ReplayAll() 63 self.mox.ReplayAll()
63 branch = cros_mark_as_stable._GitBranch(self._branch) 64 branch = cros_mark_as_stable._GitBranch(self._branch)
64 branch._Checkout('master', False) 65 branch._Checkout('cros/master', False)
65 self.mox.VerifyAll() 66 self.mox.VerifyAll()
66 67
67 def testDelete(self): 68 def testDelete(self):
68 branch = cros_mark_as_stable._GitBranch(self._branch) 69 branch = cros_mark_as_stable._GitBranch(self._branch)
69 self.mox.StubOutWithMock(branch, '_Checkout') 70 self.mox.StubOutWithMock(branch, '_Checkout')
70 branch._Checkout('master', create=False) 71 branch._Checkout('cros/master', create=False)
71 cros_mark_as_stable._RunCommand('git branch -D ' + self._branch) 72 cros_mark_as_stable._SimpleRunCommand('git branch -D ' + self._branch)
72 self.mox.ReplayAll() 73 self.mox.ReplayAll()
73 branch.Delete() 74 branch.Delete()
74 self.mox.VerifyAll() 75 self.mox.VerifyAll()
75 76
76 def testExists(self): 77 def testExists(self):
77 branch = cros_mark_as_stable._GitBranch(self._branch) 78 branch = cros_mark_as_stable._GitBranch(self._branch)
78 79
79 # Test if branch exists that is created 80 # Test if branch exists that is created
80 cros_mark_as_stable._RunCommand('git branch').AndReturn( 81 cros_mark_as_stable._SimpleRunCommand('git branch').AndReturn(
81 '%s %s' % (self._branch, 'master')) 82 '%s %s' % (self._branch, 'cros/master'))
82 self.mox.ReplayAll() 83 self.mox.ReplayAll()
83 self.assertTrue(branch.Exists()) 84 self.assertTrue(branch.Exists())
84 self.mox.VerifyAll() 85 self.mox.VerifyAll()
85 86
86 87
87 class EBuildTest(mox.MoxTestBase): 88 class EBuildTest(mox.MoxTestBase):
88 89
89 def setUp(self): 90 def setUp(self):
90 mox.MoxTestBase.setUp(self) 91 mox.MoxTestBase.setUp(self)
91 self.package = 'test_package' 92 self.package = 'test_package'
(...skipping 15 matching lines...) Expand all
107 self.mox.VerifyAll() 108 self.mox.VerifyAll()
108 self.assertEquals(ebuild.package, self.package) 109 self.assertEquals(ebuild.package, self.package)
109 self.assertEquals(ebuild.ebuild_path, self.ebuild_path) 110 self.assertEquals(ebuild.ebuild_path, self.ebuild_path)
110 self.assertEquals(ebuild.ebuild_path_no_revision, 111 self.assertEquals(ebuild.ebuild_path_no_revision,
111 '/path/test_package-0.0.1') 112 '/path/test_package-0.0.1')
112 self.assertEquals(ebuild.ebuild_path_no_version, '/path/test_package') 113 self.assertEquals(ebuild.ebuild_path_no_version, '/path/test_package')
113 self.assertEquals(ebuild.current_revision, 1) 114 self.assertEquals(ebuild.current_revision, 1)
114 self.assertEquals(ebuild.commit_id, 'my_id') 115 self.assertEquals(ebuild.commit_id, 'my_id')
115 116
116 def testFindEBuildPath(self): 117 def testFindEBuildPath(self):
117 self.mox.StubOutWithMock(cros_mark_as_stable, '_RunCommand') 118 self.mox.StubOutWithMock(cros_mark_as_stable, '_SimpleRunCommand')
118 cros_mark_as_stable._RunCommand( 119 cros_mark_as_stable._SimpleRunCommand(
119 'equery-x86-generic which %s 2> /dev/null' % self.package).AndReturn( 120 'equery-x86-generic which %s 2> /dev/null' % self.package).AndReturn(
120 self.ebuild_path) 121 self.ebuild_path)
121 self.mox.ReplayAll() 122 self.mox.ReplayAll()
122 path = cros_mark_as_stable._EBuild._FindEBuildPath(self.package) 123 path = cros_mark_as_stable._EBuild._FindEBuildPath(self.package)
123 self.mox.VerifyAll() 124 self.mox.VerifyAll()
124 self.assertEquals(path, self.ebuild_path) 125 self.assertEquals(path, self.ebuild_path)
125 126
126 def testParseEBuildPath(self): 127 def testParseEBuildPath(self):
127 # Test with ebuild with revision number. 128 # Test with ebuild with revision number.
128 no_rev, no_version, revision = cros_mark_as_stable._EBuild._ParseEBuildPath( 129 no_rev, no_version, revision = cros_mark_as_stable._EBuild._ParseEBuildPath(
129 self.ebuild_path) 130 self.ebuild_path)
130 self.assertEquals(no_rev, '/path/test_package-0.0.1') 131 self.assertEquals(no_rev, '/path/test_package-0.0.1')
131 self.assertEquals(no_version, '/path/test_package') 132 self.assertEquals(no_version, '/path/test_package')
132 self.assertEquals(revision, 1) 133 self.assertEquals(revision, 1)
133 134
134 def testParseEBuildPathNoRevisionNumber(self): 135 def testParseEBuildPathNoRevisionNumber(self):
135 # Test with ebuild without revision number. 136 # Test with ebuild without revision number.
136 no_rev, no_version, revision = cros_mark_as_stable._EBuild._ParseEBuildPath( 137 no_rev, no_version, revision = cros_mark_as_stable._EBuild._ParseEBuildPath(
137 self.ebuild_path_no_rev) 138 self.ebuild_path_no_rev)
138 self.assertEquals(no_rev, '/path/test_package-0.0.1') 139 self.assertEquals(no_rev, '/path/test_package-0.0.1')
139 self.assertEquals(no_version, '/path/test_package') 140 self.assertEquals(no_version, '/path/test_package')
140 self.assertEquals(revision, 0) 141 self.assertEquals(revision, 0)
141 142
142 143
143 class EBuildStableMarkerTest(mox.MoxTestBase): 144 class EBuildStableMarkerTest(mox.MoxTestBase):
144 145
145 def setUp(self): 146 def setUp(self):
146 mox.MoxTestBase.setUp(self) 147 mox.MoxTestBase.setUp(self)
147 self.mox.StubOutWithMock(cros_mark_as_stable, '_RunCommand') 148 self.mox.StubOutWithMock(cros_mark_as_stable, '_SimpleRunCommand')
148 self.m_ebuild = self.mox.CreateMock(cros_mark_as_stable._EBuild) 149 self.m_ebuild = self.mox.CreateMock(cros_mark_as_stable._EBuild)
149 self.m_ebuild.package = 'test_package' 150 self.m_ebuild.package = 'test_package'
150 self.m_ebuild.current_revision = 1 151 self.m_ebuild.current_revision = 1
151 self.m_ebuild.ebuild_path_no_revision = '/path/test_package-0.0.1' 152 self.m_ebuild.ebuild_path_no_revision = '/path/test_package-0.0.1'
152 self.m_ebuild.ebuild_path_no_version = '/path/test_package' 153 self.m_ebuild.ebuild_path_no_version = '/path/test_package'
153 self.m_ebuild.ebuild_path = '/path/test_package-0.0.1-r1.ebuild' 154 self.m_ebuild.ebuild_path = '/path/test_package-0.0.1-r1.ebuild'
154 self.revved_ebuild_path = '/path/test_package-0.0.1-r2.ebuild' 155 self.revved_ebuild_path = '/path/test_package-0.0.1-r2.ebuild'
155 156
156 def testRevEBuild(self): 157 def testRevEBuild(self):
157 self.mox.StubOutWithMock(cros_mark_as_stable.fileinput, 'input') 158 self.mox.StubOutWithMock(cros_mark_as_stable.fileinput, 'input')
158 self.mox.StubOutWithMock(cros_mark_as_stable.shutil, 'copyfile') 159 self.mox.StubOutWithMock(cros_mark_as_stable.shutil, 'copyfile')
159 m_file = self.mox.CreateMock(file) 160 m_file = self.mox.CreateMock(file)
160 161
161 # Prepare mock fileinput. This tests to make sure both the commit id 162 # Prepare mock fileinput. This tests to make sure both the commit id
162 # and keywords are changed correctly. 163 # and keywords are changed correctly.
163 mock_file = ['EAPI=2', 'CROS_WORKON_COMMIT=old_id', 164 mock_file = ['EAPI=2', 'CROS_WORKON_COMMIT=old_id',
164 'KEYWORDS=\"~x86 ~arm\"', 'src_unpack(){}'] 165 'KEYWORDS=\"~x86 ~arm\"', 'src_unpack(){}']
165 166
166 cros_mark_as_stable.shutil.copyfile( 167 cros_mark_as_stable.shutil.copyfile(
167 self.m_ebuild.ebuild_path_no_version + '-9999.ebuild', 168 self.m_ebuild.ebuild_path_no_version + '-9999.ebuild',
168 self.revved_ebuild_path) 169 self.revved_ebuild_path)
169 cros_mark_as_stable.fileinput.input(self.revved_ebuild_path, 170 cros_mark_as_stable.fileinput.input(self.revved_ebuild_path,
170 inplace=1).AndReturn(mock_file) 171 inplace=1).AndReturn(mock_file)
171 m_file.write('EAPI=2') 172 m_file.write('EAPI=2')
172 m_file.write('CROS_WORKON_COMMIT="my_id"\n') 173 m_file.write('CROS_WORKON_COMMIT="my_id"\n')
173 m_file.write('KEYWORDS="x86 arm"') 174 m_file.write('KEYWORDS="x86 arm"')
174 m_file.write('src_unpack(){}') 175 m_file.write('src_unpack(){}')
175 cros_mark_as_stable._RunCommand('git add ' + self.revved_ebuild_path) 176 cros_mark_as_stable._SimpleRunCommand('git add ' + self.revved_ebuild_path)
176 cros_mark_as_stable._RunCommand('git rm ' + self.m_ebuild.ebuild_path) 177 cros_mark_as_stable._SimpleRunCommand('git rm ' + self.m_ebuild.ebuild_path)
177 178
178 self.mox.ReplayAll() 179 self.mox.ReplayAll()
179 marker = cros_mark_as_stable.EBuildStableMarker(self.m_ebuild) 180 marker = cros_mark_as_stable.EBuildStableMarker(self.m_ebuild)
180 marker.RevEBuild('my_id', redirect_file=m_file) 181 marker.RevEBuild('my_id', redirect_file=m_file)
181 self.mox.VerifyAll() 182 self.mox.VerifyAll()
182 183
183 184
184 def testCommitChange(self): 185 def testCommitChange(self):
185 mock_message = 'Commit me' 186 mock_message = 'Commit me'
186 cros_mark_as_stable._RunCommand( 187 cros_mark_as_stable._SimpleRunCommand(
187 'git commit -am "%s"' % mock_message) 188 'git commit -am "%s"' % mock_message)
188 self.mox.ReplayAll() 189 self.mox.ReplayAll()
189 marker = cros_mark_as_stable.EBuildStableMarker(self.m_ebuild) 190 marker = cros_mark_as_stable.EBuildStableMarker(self.m_ebuild)
190 marker.CommitChange(mock_message) 191 marker.CommitChange(mock_message)
191 self.mox.VerifyAll() 192 self.mox.VerifyAll()
192 193
193 def testPushChange(self): 194 def testPushChange(self):
194 #cros_mark_as_stable._RunCommand('git push') 195 #cros_mark_as_stable._SimpleRunCommand('git push')
195 #self.mox.ReplayAll() 196 #self.mox.ReplayAll()
196 #marker = cros_mark_as_stable.EBuildStableMarker(self.m_ebuild) 197 #marker = cros_mark_as_stable.EBuildStableMarker(self.m_ebuild)
197 #marker.PushChange() 198 #marker.PushChange()
198 #self.mox.VerifyAll() 199 #self.mox.VerifyAll()
199 pass 200 pass
200 201
201 202
202 if __name__ == '__main__': 203 if __name__ == '__main__':
203 unittest.main() 204 unittest.main()
OLDNEW
« no previous file with comments | « cros_mark_as_stable.py ('k') | generate_test_report.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698