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

Side by Side Diff: cros_mark_as_stable_unittest.py

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

Powered by Google App Engine
This is Rietveld 408576698