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

Side by Side Diff: build/android/devil/utils/mock_calls_test.py

Issue 1325143002: [Android] Move Android version codes into devil/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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 | « build/android/devil/android/sdk/version_codes.py ('k') | build/android/provision_devices.py » ('j') | 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/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
11 import os 11 import os
12 import sys 12 import sys
13 import unittest 13 import unittest
14 14
15 from devil.android.sdk import version_codes
15 from devil.utils import mock_calls 16 from devil.utils import mock_calls
16 from pylib import constants 17 from pylib import constants
17 18
18 sys.path.append(os.path.join( 19 sys.path.append(os.path.join(
19 constants.DIR_SOURCE_ROOT, 'third_party', 'pymock')) 20 constants.DIR_SOURCE_ROOT, 'third_party', 'pymock'))
20 import mock # pylint: disable=F0401 21 import mock # pylint: disable=F0401
21 22
22 23
23 class _DummyAdb(object): 24 class _DummyAdb(object):
24 def __str__(self): 25 def __str__(self):
25 return '0123456789abcdef' 26 return '0123456789abcdef'
26 27
27 def Push(self, host_path, device_path): 28 def Push(self, host_path, device_path):
28 logging.debug('(device %s) pushing %r to %r', self, host_path, device_path) 29 logging.debug('(device %s) pushing %r to %r', self, host_path, device_path)
29 30
30 def IsOnline(self): 31 def IsOnline(self):
31 logging.debug('(device %s) checking device online', self) 32 logging.debug('(device %s) checking device online', self)
32 return True 33 return True
33 34
34 def Shell(self, cmd): 35 def Shell(self, cmd):
35 logging.debug('(device %s) running command %r', self, cmd) 36 logging.debug('(device %s) running command %r', self, cmd)
36 return "nice output\n" 37 return "nice output\n"
37 38
38 def Reboot(self): 39 def Reboot(self):
39 logging.debug('(device %s) rebooted!', self) 40 logging.debug('(device %s) rebooted!', self)
40 41
41 @property 42 @property
42 def build_version_sdk(self): 43 def build_version_sdk(self):
43 logging.debug('(device %s) getting build_version_sdk', self) 44 logging.debug('(device %s) getting build_version_sdk', self)
44 return constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP 45 return version_codes.LOLLIPOP
45 46
46 47
47 class TestCaseWithAssertCallsTest(mock_calls.TestCase): 48 class TestCaseWithAssertCallsTest(mock_calls.TestCase):
48 def setUp(self): 49 def setUp(self):
49 self.adb = _DummyAdb() 50 self.adb = _DummyAdb()
50 51
51 def ShellError(self): 52 def ShellError(self):
52 def action(cmd): 53 def action(cmd):
53 raise ValueError('(device %s) command %r is not nice' % (self.adb, cmd)) 54 raise ValueError('(device %s) command %r is not nice' % (self.adb, cmd))
54 return action 55 return action
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 def testPatchCall_global(self): 91 def testPatchCall_global(self):
91 with self.patch_call(mock.call.os.getcwd, return_value='/some/path'): 92 with self.patch_call(mock.call.os.getcwd, return_value='/some/path'):
92 self.assertEquals('/some/path', os.getcwd()) 93 self.assertEquals('/some/path', os.getcwd())
93 94
94 def testPatchCall_withSideEffect(self): 95 def testPatchCall_withSideEffect(self):
95 with self.patch_call(self.call.adb.Shell, side_effect=ValueError): 96 with self.patch_call(self.call.adb.Shell, side_effect=ValueError):
96 with self.assertRaises(ValueError): 97 with self.assertRaises(ValueError):
97 self.adb.Shell('echo hello') 98 self.adb.Shell('echo hello')
98 99
99 def testPatchCall_property(self): 100 def testPatchCall_property(self):
100 self.assertEquals(constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP, 101 self.assertEquals(version_codes.LOLLIPOP, self.adb.build_version_sdk)
101 self.adb.build_version_sdk)
102 with self.patch_call( 102 with self.patch_call(
103 self.call.adb.build_version_sdk, 103 self.call.adb.build_version_sdk,
104 return_value=constants.ANDROID_SDK_VERSION_CODES.KITKAT): 104 return_value=version_codes.KITKAT):
105 self.assertEquals(constants.ANDROID_SDK_VERSION_CODES.KITKAT, 105 self.assertEquals(version_codes.KITKAT, self.adb.build_version_sdk)
106 self.adb.build_version_sdk) 106 self.assertEquals(version_codes.LOLLIPOP, self.adb.build_version_sdk)
107 self.assertEquals(constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP,
108 self.adb.build_version_sdk)
109 107
110 def testAssertCalls_succeeds_simple(self): 108 def testAssertCalls_succeeds_simple(self):
111 self.assertEquals(42, self.get_answer()) 109 self.assertEquals(42, self.get_answer())
112 with self.assertCall(self.call.get_answer(), 123): 110 with self.assertCall(self.call.get_answer(), 123):
113 self.assertEquals(123, self.get_answer()) 111 self.assertEquals(123, self.get_answer())
114 self.assertEquals(42, self.get_answer()) 112 self.assertEquals(42, self.get_answer())
115 113
116 def testAssertCalls_succeeds_multiple(self): 114 def testAssertCalls_succeeds_multiple(self):
117 with self.assertCalls( 115 with self.assertCalls(
118 (mock.call.os.getcwd(), '/some/path'), 116 (mock.call.os.getcwd(), '/some/path'),
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 self.watchMethodCalls(self.call.adb) 164 self.watchMethodCalls(self.call.adb)
167 with self.assertRaises(AssertionError): 165 with self.assertRaises(AssertionError):
168 with self.assertCalls(): 166 with self.assertCalls():
169 self.adb.IsOnline() 167 self.adb.IsOnline()
170 168
171 169
172 if __name__ == '__main__': 170 if __name__ == '__main__':
173 logging.getLogger().setLevel(logging.DEBUG) 171 logging.getLogger().setLevel(logging.DEBUG)
174 unittest.main(verbosity=2) 172 unittest.main(verbosity=2)
175 173
OLDNEW
« no previous file with comments | « build/android/devil/android/sdk/version_codes.py ('k') | build/android/provision_devices.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698