OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """ | 6 """ |
7 Unit tests for the contents of mock_calls.py. | 7 Unit tests for the contents of mock_calls.py. |
8 """ | 8 """ |
9 | 9 |
10 import logging | 10 import logging |
(...skipping 20 matching lines...) Expand all Loading... |
31 logging.debug('(device %s) checking device online', self) | 31 logging.debug('(device %s) checking device online', self) |
32 return True | 32 return True |
33 | 33 |
34 def Shell(self, cmd): | 34 def Shell(self, cmd): |
35 logging.debug('(device %s) running command %r', self, cmd) | 35 logging.debug('(device %s) running command %r', self, cmd) |
36 return "nice output\n" | 36 return "nice output\n" |
37 | 37 |
38 def Reboot(self): | 38 def Reboot(self): |
39 logging.debug('(device %s) rebooted!', self) | 39 logging.debug('(device %s) rebooted!', self) |
40 | 40 |
| 41 @property |
| 42 def build_version_sdk(self): |
| 43 logging.debug('(device %s) getting build_version_sdk', self) |
| 44 return constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP |
| 45 |
41 | 46 |
42 class TestCaseWithAssertCallsTest(mock_calls.TestCase): | 47 class TestCaseWithAssertCallsTest(mock_calls.TestCase): |
43 def setUp(self): | 48 def setUp(self): |
44 self.adb = _DummyAdb() | 49 self.adb = _DummyAdb() |
45 | 50 |
46 def ShellError(self): | 51 def ShellError(self): |
47 def action(cmd): | 52 def action(cmd): |
48 raise ValueError('(device %s) command %r is not nice' % (self.adb, cmd)) | 53 raise ValueError('(device %s) command %r is not nice' % (self.adb, cmd)) |
49 return action | 54 return action |
50 | 55 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 89 |
85 def testPatchCall_global(self): | 90 def testPatchCall_global(self): |
86 with self.patch_call(mock.call.os.getcwd, return_value='/some/path'): | 91 with self.patch_call(mock.call.os.getcwd, return_value='/some/path'): |
87 self.assertEquals('/some/path', os.getcwd()) | 92 self.assertEquals('/some/path', os.getcwd()) |
88 | 93 |
89 def testPatchCall_withSideEffect(self): | 94 def testPatchCall_withSideEffect(self): |
90 with self.patch_call(self.call.adb.Shell, side_effect=ValueError): | 95 with self.patch_call(self.call.adb.Shell, side_effect=ValueError): |
91 with self.assertRaises(ValueError): | 96 with self.assertRaises(ValueError): |
92 self.adb.Shell('echo hello') | 97 self.adb.Shell('echo hello') |
93 | 98 |
| 99 def testPatchCall_property(self): |
| 100 self.assertEquals(constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP, |
| 101 self.adb.build_version_sdk) |
| 102 with self.patch_call( |
| 103 self.call.adb.build_version_sdk, |
| 104 return_value=constants.ANDROID_SDK_VERSION_CODES.KITKAT): |
| 105 self.assertEquals(constants.ANDROID_SDK_VERSION_CODES.KITKAT, |
| 106 self.adb.build_version_sdk) |
| 107 self.assertEquals(constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP, |
| 108 self.adb.build_version_sdk) |
| 109 |
94 def testAssertCalls_succeeds_simple(self): | 110 def testAssertCalls_succeeds_simple(self): |
95 self.assertEquals(42, self.get_answer()) | 111 self.assertEquals(42, self.get_answer()) |
96 with self.assertCall(self.call.get_answer(), 123): | 112 with self.assertCall(self.call.get_answer(), 123): |
97 self.assertEquals(123, self.get_answer()) | 113 self.assertEquals(123, self.get_answer()) |
98 self.assertEquals(42, self.get_answer()) | 114 self.assertEquals(42, self.get_answer()) |
99 | 115 |
100 def testAssertCalls_succeeds_multiple(self): | 116 def testAssertCalls_succeeds_multiple(self): |
101 with self.assertCalls( | 117 with self.assertCalls( |
102 (mock.call.os.getcwd(), '/some/path'), | 118 (mock.call.os.getcwd(), '/some/path'), |
103 (self.call.echo('hello'), 'hello'), | 119 (self.call.echo('hello'), 'hello'), |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 self.watchMethodCalls(self.call.adb) | 166 self.watchMethodCalls(self.call.adb) |
151 with self.assertRaises(AssertionError): | 167 with self.assertRaises(AssertionError): |
152 with self.assertCalls(): | 168 with self.assertCalls(): |
153 self.adb.IsOnline() | 169 self.adb.IsOnline() |
154 | 170 |
155 | 171 |
156 if __name__ == '__main__': | 172 if __name__ == '__main__': |
157 logging.getLogger().setLevel(logging.DEBUG) | 173 logging.getLogger().setLevel(logging.DEBUG) |
158 unittest.main(verbosity=2) | 174 unittest.main(verbosity=2) |
159 | 175 |
OLD | NEW |