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

Side by Side Diff: cros_mark_as_stable_unittest.py

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