OLD | NEW |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2011 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 """Unittests for commands. Needs to be run inside of chroot for mox.""" | 7 """Unittests for commands. Needs to be run inside of chroot for mox.""" |
8 | 8 |
9 import __builtin__ | 9 import __builtin__ |
10 import mox | 10 import mox |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
102 binhosts = [binhost, None] | 102 binhosts = [binhost, None] |
103 check = mox.And(mox.IsA(list), mox.In(binhost), mox.Not(mox.In(None)), | 103 check = mox.And(mox.IsA(list), mox.In(binhost), mox.Not(mox.In(None)), |
104 mox.In('chromeos-images:/var/www/prebuilt/'), | 104 mox.In('chromeos-images:/var/www/prebuilt/'), |
105 mox.In('chrome')) | 105 mox.In('chrome')) |
106 cros_lib.OldRunCommand(check, cwd=os.path.dirname(commands.__file__)) | 106 cros_lib.OldRunCommand(check, cwd=os.path.dirname(commands.__file__)) |
107 self.mox.ReplayAll() | 107 self.mox.ReplayAll() |
108 commands.UploadPrebuilts(self._buildroot, self._test_board, 'private', | 108 commands.UploadPrebuilts(self._buildroot, self._test_board, 'private', |
109 binhosts, 'chrome', 'tot') | 109 binhosts, 'chrome', 'tot') |
110 self.mox.VerifyAll() | 110 self.mox.VerifyAll() |
111 | 111 |
112 def testRepoSyncRetriesFail(self): | |
113 """Case where we exceed default retry attempts""" | |
davidjames
2011/04/01 20:20:27
Please add a trailing period.
rcui1
2011/04/01 20:44:08
Done.
| |
114 cros_lib.OldRunCommand(mox.In('sync'), | |
115 cwd=self._buildroot).AndRaise(Exception("failed")) | |
116 cros_lib.OldRunCommand(mox.In('sync'), | |
117 cwd=self._buildroot).AndRaise(Exception("failed")) | |
118 cros_lib.OldRunCommand(mox.In('sync'), | |
119 cwd=self._buildroot).AndRaise(Exception("failed")) | |
120 self.mox.ReplayAll() | |
121 self.assertRaises(Exception, lambda : commands._RepoSync(self._buildroot)) | |
davidjames
2011/04/01 20:20:27
No need for the space between 'lambda' and ':'.
(
rcui1
2011/04/01 20:44:08
Done.
| |
122 self.mox.VerifyAll() | |
123 | |
124 def testRepoSyncRetriesPass(self): | |
125 """Case where we fail twice and pass on the third try.""" | |
126 cros_lib.OldRunCommand(mox.In('sync'), | |
127 cwd=self._buildroot).AndRaise(Exception("failed")) | |
128 cros_lib.OldRunCommand(mox.In('sync'), | |
129 cwd=self._buildroot).AndRaise(Exception("failed")) | |
130 cros_lib.OldRunCommand(mox.In('sync'), cwd=self._buildroot) | |
131 cros_lib.OldRunCommand(mox.In('forall'), cwd=self._buildroot) | |
132 cros_lib.OldRunCommand(mox.In('manifest'), cwd=self._buildroot) | |
133 self.mox.ReplayAll() | |
134 commands._RepoSync(self._buildroot) | |
135 self.mox.VerifyAll() | |
136 | |
137 def testRepoSyncCustomRetriesFail(self): | |
138 """Case where _RepoSync is called with a custom retry value of 1. Should | |
139 throw exception after first failure.""" | |
140 cros_lib.OldRunCommand(mox.In('sync'), | |
141 cwd=self._buildroot).AndRaise(Exception("failed")) | |
142 self.mox.ReplayAll() | |
143 self.assertRaises( | |
144 Exception, | |
145 lambda : commands._RepoSync(self._buildroot, retries=1)) | |
davidjames
2011/04/01 20:20:27
Ditto.
rcui1
2011/04/01 20:44:08
Done.
| |
146 self.mox.VerifyAll() | |
147 | |
148 def testRepoSyncCustomRetriesPass(self): | |
149 """Case where _RepoSync is called with a custom retry value of 2 and passes | |
150 the second time.""" | |
151 cros_lib.OldRunCommand(mox.In('sync'), | |
152 cwd=self._buildroot).AndRaise(Exception("failed")) | |
153 cros_lib.OldRunCommand(mox.In('sync'), cwd=self._buildroot) | |
154 cros_lib.OldRunCommand(mox.In('forall'), cwd=self._buildroot) | |
155 cros_lib.OldRunCommand(mox.In('manifest'), cwd=self._buildroot) | |
156 self.mox.ReplayAll() | |
157 commands._RepoSync(self._buildroot, retries=2) | |
158 self.mox.VerifyAll() | |
159 | |
112 | 160 |
113 if __name__ == '__main__': | 161 if __name__ == '__main__': |
114 unittest.main() | 162 unittest.main() |
OLD | NEW |