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

Side by Side Diff: build/android/pylib/device/device_utils_test.py

Issue 1116493003: Revert of [Android] Remove more uses of android_commands from build/android/pylib. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
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 device_utils.py (mostly DeviceUtils). 7 Unit tests for the contents of device_utils.py (mostly DeviceUtils).
8 """ 8 """
9 9
10 # pylint: disable=C0321 10 # pylint: disable=C0321
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 return mock.Mock(side_effect=device_errors.CommandTimeoutError( 154 return mock.Mock(side_effect=device_errors.CommandTimeoutError(
155 msg, str(self.device))) 155 msg, str(self.device)))
156 156
157 def CommandError(self, msg=None): 157 def CommandError(self, msg=None):
158 if msg is None: 158 if msg is None:
159 msg = 'Command failed' 159 msg = 'Command failed'
160 return mock.Mock(side_effect=device_errors.CommandFailedError( 160 return mock.Mock(side_effect=device_errors.CommandFailedError(
161 msg, str(self.device))) 161 msg, str(self.device)))
162 162
163 163
164 class DeviceUtilsEqTest(DeviceUtilsTest):
165
166 def testEq_equal_deviceUtils(self):
167 other = device_utils.DeviceUtils(_AdbWrapperMock('0123456789abcdef'))
168 self.assertTrue(self.device == other)
169 self.assertTrue(other == self.device)
170
171 def testEq_equal_adbWrapper(self):
172 other = adb_wrapper.AdbWrapper('0123456789abcdef')
173 self.assertTrue(self.device == other)
174 self.assertTrue(other == self.device)
175
176 def testEq_equal_string(self):
177 other = '0123456789abcdef'
178 self.assertTrue(self.device == other)
179 self.assertTrue(other == self.device)
180
181 def testEq_devicesNotEqual(self):
182 other = device_utils.DeviceUtils(_AdbWrapperMock('0123456789abcdee'))
183 self.assertFalse(self.device == other)
184 self.assertFalse(other == self.device)
185
186 def testEq_identity(self):
187 self.assertTrue(self.device == self.device)
188
189 def testEq_serialInList(self):
190 devices = [self.device]
191 self.assertTrue('0123456789abcdef' in devices)
192
193
194 class DeviceUtilsLtTest(DeviceUtilsTest):
195
196 def testLt_lessThan(self):
197 other = device_utils.DeviceUtils(_AdbWrapperMock('ffffffffffffffff'))
198 self.assertTrue(self.device < other)
199 self.assertTrue(other > self.device)
200
201 def testLt_greaterThan_lhs(self):
202 other = device_utils.DeviceUtils(_AdbWrapperMock('0000000000000000'))
203 self.assertFalse(self.device < other)
204 self.assertFalse(other > self.device)
205
206 def testLt_equal(self):
207 other = device_utils.DeviceUtils(_AdbWrapperMock('0123456789abcdef'))
208 self.assertFalse(self.device < other)
209 self.assertFalse(other > self.device)
210
211 def testLt_sorted(self):
212 devices = [
213 device_utils.DeviceUtils(_AdbWrapperMock('ffffffffffffffff')),
214 device_utils.DeviceUtils(_AdbWrapperMock('0000000000000000')),
215 ]
216 sorted_devices = sorted(devices)
217 self.assertEquals('0000000000000000',
218 sorted_devices[0].adb.GetDeviceSerial())
219 self.assertEquals('ffffffffffffffff',
220 sorted_devices[1].adb.GetDeviceSerial())
221
222
223 class DeviceUtilsStrTest(DeviceUtilsTest):
224
225 def testStr_returnsSerial(self):
226 with self.assertCalls(
227 (self.call.adb.GetDeviceSerial(), '0123456789abcdef')):
228 self.assertEqual('0123456789abcdef', str(self.device))
229
230
231 class DeviceUtilsIsOnlineTest(DeviceUtilsTest): 164 class DeviceUtilsIsOnlineTest(DeviceUtilsTest):
232 165
233 def testIsOnline_true(self): 166 def testIsOnline_true(self):
234 with self.assertCall(self.call.adb.GetState(), 'device'): 167 with self.assertCall(self.call.adb.GetState(), 'device'):
235 self.assertTrue(self.device.IsOnline()) 168 self.assertTrue(self.device.IsOnline())
236 169
237 def testIsOnline_false(self): 170 def testIsOnline_false(self):
238 with self.assertCall(self.call.adb.GetState(), 'offline'): 171 with self.assertCall(self.call.adb.GetState(), 'offline'):
239 self.assertFalse(self.device.IsOnline()) 172 self.assertFalse(self.device.IsOnline())
240 173
(...skipping 1358 matching lines...) Expand 10 before | Expand all | Expand 10 after
1599 'Rss': 101, 1532 'Rss': 101,
1600 'Pss': 102, 1533 'Pss': 102,
1601 'Shared_Clean': 103, 1534 'Shared_Clean': 103,
1602 'Shared_Dirty': 104, 1535 'Shared_Dirty': 104,
1603 'Private_Clean': 105, 1536 'Private_Clean': 105,
1604 'Private_Dirty': 106, 1537 'Private_Dirty': 106,
1605 }, 1538 },
1606 self.device.GetMemoryUsageForPid(4321)) 1539 self.device.GetMemoryUsageForPid(4321))
1607 1540
1608 1541
1542 class DeviceUtilsStrTest(DeviceUtilsTest):
1543
1544 def testStr_returnsSerial(self):
1545 with self.assertCalls(
1546 (self.call.adb.GetDeviceSerial(), '0123456789abcdef')):
1547 self.assertEqual('0123456789abcdef', str(self.device))
1548
1549
1609 class DeviceUtilsClientCache(DeviceUtilsTest): 1550 class DeviceUtilsClientCache(DeviceUtilsTest):
1610 1551
1611 def testClientCache_twoCaches(self): 1552 def testClientCache_twoCaches(self):
1612 self.device._cache['test'] = 0 1553 self.device._cache['test'] = 0
1613 client_cache_one = self.device.GetClientCache('ClientOne') 1554 client_cache_one = self.device.GetClientCache('ClientOne')
1614 client_cache_one['test'] = 1 1555 client_cache_one['test'] = 1
1615 client_cache_two = self.device.GetClientCache('ClientTwo') 1556 client_cache_two = self.device.GetClientCache('ClientTwo')
1616 client_cache_two['test'] = 2 1557 client_cache_two['test'] = 2
1617 self.assertEqual(self.device._cache, {'test': 0}) 1558 self.assertEqual(self.device._cache, {'test': 0})
1618 self.assertEqual(client_cache_one, {'test': 1}) 1559 self.assertEqual(client_cache_one, {'test': 1})
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1680 devices = device_utils.DeviceUtils.HealthyDevices() 1621 devices = device_utils.DeviceUtils.HealthyDevices()
1681 self.assertEquals(1, len(devices)) 1622 self.assertEquals(1, len(devices))
1682 self.assertTrue(isinstance(devices[0], device_utils.DeviceUtils)) 1623 self.assertTrue(isinstance(devices[0], device_utils.DeviceUtils))
1683 self.assertEquals('0123456789abcdef', devices[0].adb.GetDeviceSerial()) 1624 self.assertEquals('0123456789abcdef', devices[0].adb.GetDeviceSerial())
1684 1625
1685 1626
1686 if __name__ == '__main__': 1627 if __name__ == '__main__':
1687 logging.getLogger().setLevel(logging.DEBUG) 1628 logging.getLogger().setLevel(logging.DEBUG)
1688 unittest.main(verbosity=2) 1629 unittest.main(verbosity=2)
1689 1630
OLDNEW
« no previous file with comments | « build/android/pylib/device/device_utils.py ('k') | build/android/pylib/perf/perf_control_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698