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

Side by Side Diff: cros_mark_as_stable_unittest.py

Issue 6291013: Have the ability for the PFQ to both rev Chrome and other packages. (Closed) Base URL: http://git.chromium.org/git/crosutils.git@master
Patch Set: Nit Created 9 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 unified diff | Download patch | Annotate | Revision Log
« 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
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 import fileinput 9 import fileinput
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 import cros_mark_as_stable 15 import cros_mark_as_stable
16 16
17 class NonClassTests(mox.MoxTestBase): 17 class NonClassTests(mox.MoxTestBase):
18 def setUp(self): 18 def setUp(self):
19 mox.MoxTestBase.setUp(self) 19 mox.MoxTestBase.setUp(self)
20 self.mox.StubOutWithMock(cros_mark_as_stable, '_SimpleRunCommand') 20 self.mox.StubOutWithMock(cros_mark_as_stable, '_SimpleRunCommand')
21 self._branch = 'test_branch' 21 self._branch = 'test_branch'
22 self._tracking_branch = 'cros/test' 22 self._tracking_branch = 'cros/test'
23 23
24 def testPushChange(self): 24 def testPushChange(self):
25 git_log = 'Marking test_one as stable\nMarking test_two as stable\n' 25 git_log = 'Marking test_one as stable\nMarking test_two as stable\n'
26 fake_description = 'Marking set of ebuilds as stable\n\n%s' % git_log 26 fake_description = 'Marking set of ebuilds as stable\n\n%s' % git_log
27 self.mox.StubOutWithMock(cros_mark_as_stable, '_CheckOnStabilizingBranch') 27 self.mox.StubOutWithMock(cros_mark_as_stable, '_DoWeHaveLocalCommits')
28 self.mox.StubOutWithMock(cros_mark_as_stable.GitBranch, 'CreateBranch') 28 self.mox.StubOutWithMock(cros_mark_as_stable.GitBranch, 'CreateBranch')
29 self.mox.StubOutWithMock(cros_mark_as_stable.GitBranch, 'Exists') 29 self.mox.StubOutWithMock(cros_mark_as_stable.GitBranch, 'Exists')
30 30
31 cros_mark_as_stable._CheckOnStabilizingBranch(self._branch).AndReturn(True) 31 cros_mark_as_stable._DoWeHaveLocalCommits(
32 self._branch, self._tracking_branch).AndReturn(True)
32 cros_mark_as_stable.GitBranch.CreateBranch() 33 cros_mark_as_stable.GitBranch.CreateBranch()
33 cros_mark_as_stable.GitBranch.Exists().AndReturn(True) 34 cros_mark_as_stable.GitBranch.Exists().AndReturn(True)
34 cros_mark_as_stable._SimpleRunCommand('git log --format=format:%s%n%n%b ' + 35 cros_mark_as_stable._SimpleRunCommand('git log --format=format:%s%n%n%b ' +
35 self._tracking_branch + '..').AndReturn(git_log) 36 self._tracking_branch + '..').AndReturn(git_log)
36 cros_mark_as_stable._SimpleRunCommand('repo sync .') 37 cros_mark_as_stable._SimpleRunCommand('repo sync .')
37 cros_mark_as_stable._SimpleRunCommand('git merge --squash %s' % 38 cros_mark_as_stable._SimpleRunCommand('git merge --squash %s' %
38 self._branch) 39 self._branch)
39 cros_mark_as_stable._SimpleRunCommand('git commit -m "%s"' % 40 cros_mark_as_stable._SimpleRunCommand('git commit -m "%s"' %
40 fake_description) 41 fake_description)
41 cros_mark_as_stable._SimpleRunCommand('git config push.default tracking') 42 cros_mark_as_stable._SimpleRunCommand('git config push.default tracking')
42 cros_mark_as_stable._SimpleRunCommand('git push') 43 cros_mark_as_stable._SimpleRunCommand('git push')
43 self.mox.ReplayAll() 44 self.mox.ReplayAll()
44 cros_mark_as_stable.PushChange(self._branch, self._tracking_branch) 45 cros_mark_as_stable.PushChange(self._branch, self._tracking_branch)
45 self.mox.VerifyAll() 46 self.mox.VerifyAll()
46 47
47 48
48 class GitBranchTest(mox.MoxTestBase): 49 class GitBranchTest(mox.MoxTestBase):
49 50
50 def setUp(self): 51 def setUp(self):
51 mox.MoxTestBase.setUp(self) 52 mox.MoxTestBase.setUp(self)
52 # Always stub RunCommmand out as we use it in every method. 53 # Always stub RunCommmand out as we use it in every method.
53 self.mox.StubOutWithMock(cros_mark_as_stable, '_SimpleRunCommand') 54 self.mox.StubOutWithMock(cros_mark_as_stable, '_SimpleRunCommand')
54 self._branch = 'test_branch' 55 self._branch = self.mox.CreateMock(cros_mark_as_stable.GitBranch)
56 self._branch_name = 'test_branch'
57 self._branch.branch_name = self._branch_name
55 self._tracking_branch = 'cros/test' 58 self._tracking_branch = 'cros/test'
56 59 self._branch.tracking_branch = self._tracking_branch
57 def testCreateBranchNoPrevious(self):
58 # Test init with no previous branch existing.
59 branch = cros_mark_as_stable.GitBranch(self._branch, self._tracking_branch)
60 self.mox.StubOutWithMock(branch, 'Exists')
61 self.mox.StubOutWithMock(branch, '_Checkout')
62 branch.Exists().AndReturn(False)
63 branch._Checkout(self._branch)
64 self.mox.ReplayAll()
65 branch.CreateBranch()
66 self.mox.VerifyAll()
67
68 def testCreateBranchWithPrevious(self):
69 # Test init with previous branch existing.
70 branch = cros_mark_as_stable.GitBranch(self._branch, self._tracking_branch)
71 self.mox.StubOutWithMock(branch, 'Exists')
72 self.mox.StubOutWithMock(branch, 'Delete')
73 self.mox.StubOutWithMock(branch, '_Checkout')
74 branch.Exists().AndReturn(True)
75 branch.Delete()
76 branch._Checkout(self._branch)
77 self.mox.ReplayAll()
78 branch.CreateBranch()
79 self.mox.VerifyAll()
80 60
81 def testCheckoutCreate(self): 61 def testCheckoutCreate(self):
82 # Test init with no previous branch existing. 62 # Test init with no previous branch existing.
63 self._branch.Exists().AndReturn(False)
83 cros_mark_as_stable._SimpleRunCommand( 64 cros_mark_as_stable._SimpleRunCommand(
84 'git checkout -b %s %s' % (self._branch, self._tracking_branch)) 65 'git checkout -b %s %s' % (self._branch_name, self._tracking_branch))
85 self.mox.ReplayAll() 66 self.mox.ReplayAll()
86 branch = cros_mark_as_stable.GitBranch(self._branch, self._tracking_branch) 67 cros_mark_as_stable.GitBranch.Checkout(self._branch)
87 branch._Checkout(self._branch)
88 self.mox.VerifyAll() 68 self.mox.VerifyAll()
89 69
90 def testCheckoutNoCreate(self): 70 def testCheckoutNoCreate(self):
91 # Test init with previous branch existing. 71 # Test init with previous branch existing.
72 self._branch.Exists().AndReturn(True)
92 cros_mark_as_stable._SimpleRunCommand('git checkout %s' % ( 73 cros_mark_as_stable._SimpleRunCommand('git checkout %s' % (
93 self._tracking_branch)) 74 self._branch_name))
94 self.mox.ReplayAll() 75 self.mox.ReplayAll()
95 branch = cros_mark_as_stable.GitBranch(self._branch, self._tracking_branch) 76 cros_mark_as_stable.GitBranch.Checkout(self._branch)
96 branch._Checkout(self._tracking_branch, False)
97 self.mox.VerifyAll() 77 self.mox.VerifyAll()
98 78
99 def testDelete(self): 79 def testDelete(self):
100 branch = cros_mark_as_stable.GitBranch(self._branch, self._tracking_branch) 80 self.mox.StubOutWithMock(cros_mark_as_stable.GitBranch, 'Checkout')
101 self.mox.StubOutWithMock(branch, '_Checkout') 81 branch = cros_mark_as_stable.GitBranch(self._branch_name,
102 branch._Checkout(self._tracking_branch, create=False) 82 self._tracking_branch)
103 cros_mark_as_stable._SimpleRunCommand('git branch -D ' + self._branch) 83 cros_mark_as_stable.GitBranch.Checkout(mox.IgnoreArg())
84 cros_mark_as_stable._SimpleRunCommand('git branch -D ' + self._branch_name)
104 self.mox.ReplayAll() 85 self.mox.ReplayAll()
105 branch.Delete() 86 branch.Delete()
106 self.mox.VerifyAll() 87 self.mox.VerifyAll()
107 88
108 def testExists(self): 89 def testExists(self):
109 branch = cros_mark_as_stable.GitBranch(self._branch, self._tracking_branch) 90 branch = cros_mark_as_stable.GitBranch(self._branch_name,
110 91 self._tracking_branch)
111 # Test if branch exists that is created 92 # Test if branch exists that is created
112 cros_mark_as_stable._SimpleRunCommand('git branch').AndReturn( 93 cros_mark_as_stable._SimpleRunCommand('git branch').AndReturn(
113 '%s %s' % (self._branch, self._tracking_branch)) 94 '%s' % self._branch_name)
114 self.mox.ReplayAll() 95 self.mox.ReplayAll()
115 self.assertTrue(branch.Exists()) 96 self.assertTrue(branch.Exists())
116 self.mox.VerifyAll() 97 self.mox.VerifyAll()
117 98
118 99
119 class EBuildTest(mox.MoxTestBase): 100 class EBuildTest(mox.MoxTestBase):
120 101
121 def setUp(self): 102 def setUp(self):
122 mox.MoxTestBase.setUp(self) 103 mox.MoxTestBase.setUp(self)
123 104
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 cros_mark_as_stable._FindUprevCandidates([]).AndReturn(package) 304 cros_mark_as_stable._FindUprevCandidates([]).AndReturn(package)
324 self.mox.ReplayAll() 305 self.mox.ReplayAll()
325 cros_mark_as_stable._BuildEBuildDictionary(overlays, False, []) 306 cros_mark_as_stable._BuildEBuildDictionary(overlays, False, [])
326 self.assertEquals(len(overlays), 1) 307 self.assertEquals(len(overlays), 1)
327 self.assertEquals(overlays["/overlay"], []) 308 self.assertEquals(overlays["/overlay"], [])
328 self.mox.VerifyAll() 309 self.mox.VerifyAll()
329 310
330 311
331 if __name__ == '__main__': 312 if __name__ == '__main__':
332 unittest.main() 313 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