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

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

Issue 1105323002: [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_devicesEqual(self):
167 other = device_utils.DeviceUtils(_AdbWrapperMock('0123456789abcdef'))
168 self.assertTrue(self.device == other)
169
170 def testEq_devicesNotEqual(self):
171 other = device_utils.DeviceUtils(_AdbWrapperMock('0123456789abcdee'))
172 self.assertFalse(self.device == other)
173
174 def testEq_identity(self):
175 self.assertTrue(self.device == self.device)
176
177 def testEq_serialInList(self):
178 devices = [self.device]
179 self.assertTrue('0123456789abcdef' in devices)
180
181
182 class DeviceUtilsLtTest(DeviceUtilsTest):
183
184 def testLt_lessThan(self):
185 other = device_utils.DeviceUtils(_AdbWrapperMock('ffffffffffffffff'))
186 self.assertTrue(self.device < other)
187
188 def testLt_greaterThan(self):
189 other = device_utils.DeviceUtils(_AdbWrapperMock('0000000000000000'))
190 self.assertFalse(self.device < other)
191
192 def testLt_equal(self):
193 other = device_utils.DeviceUtils(_AdbWrapperMock('0123456789abcdef'))
194 self.assertFalse(self.device < other)
195
196 def testLt_sorted(self):
197 devices = [
198 device_utils.DeviceUtils(_AdbWrapperMock('ffffffffffffffff')),
199 device_utils.DeviceUtils(_AdbWrapperMock('0000000000000000')),
200 ]
201 sorted_devices = sorted(devices)
202 self.assertEquals('0000000000000000',
203 sorted_devices[0].adb.GetDeviceSerial())
204 self.assertEquals('ffffffffffffffff',
205 sorted_devices[1].adb.GetDeviceSerial())
206
207
208 class DeviceUtilsStrTest(DeviceUtilsTest):
209
210 def testStr_returnsSerial(self):
211 with self.assertCalls(
212 (self.call.adb.GetDeviceSerial(), '0123456789abcdef')):
213 self.assertEqual('0123456789abcdef', str(self.device))
214
215
164 class DeviceUtilsIsOnlineTest(DeviceUtilsTest): 216 class DeviceUtilsIsOnlineTest(DeviceUtilsTest):
165 217
166 def testIsOnline_true(self): 218 def testIsOnline_true(self):
167 with self.assertCall(self.call.adb.GetState(), 'device'): 219 with self.assertCall(self.call.adb.GetState(), 'device'):
168 self.assertTrue(self.device.IsOnline()) 220 self.assertTrue(self.device.IsOnline())
169 221
170 def testIsOnline_false(self): 222 def testIsOnline_false(self):
171 with self.assertCall(self.call.adb.GetState(), 'offline'): 223 with self.assertCall(self.call.adb.GetState(), 'offline'):
172 self.assertFalse(self.device.IsOnline()) 224 self.assertFalse(self.device.IsOnline())
173 225
(...skipping 1358 matching lines...) Expand 10 before | Expand all | Expand 10 after
1532 'Rss': 101, 1584 'Rss': 101,
1533 'Pss': 102, 1585 'Pss': 102,
1534 'Shared_Clean': 103, 1586 'Shared_Clean': 103,
1535 'Shared_Dirty': 104, 1587 'Shared_Dirty': 104,
1536 'Private_Clean': 105, 1588 'Private_Clean': 105,
1537 'Private_Dirty': 106, 1589 'Private_Dirty': 106,
1538 }, 1590 },
1539 self.device.GetMemoryUsageForPid(4321)) 1591 self.device.GetMemoryUsageForPid(4321))
1540 1592
1541 1593
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
1550 class DeviceUtilsClientCache(DeviceUtilsTest): 1594 class DeviceUtilsClientCache(DeviceUtilsTest):
1551 1595
1552 def testClientCache_twoCaches(self): 1596 def testClientCache_twoCaches(self):
1553 self.device._cache['test'] = 0 1597 self.device._cache['test'] = 0
1554 client_cache_one = self.device.GetClientCache('ClientOne') 1598 client_cache_one = self.device.GetClientCache('ClientOne')
1555 client_cache_one['test'] = 1 1599 client_cache_one['test'] = 1
1556 client_cache_two = self.device.GetClientCache('ClientTwo') 1600 client_cache_two = self.device.GetClientCache('ClientTwo')
1557 client_cache_two['test'] = 2 1601 client_cache_two['test'] = 2
1558 self.assertEqual(self.device._cache, {'test': 0}) 1602 self.assertEqual(self.device._cache, {'test': 0})
1559 self.assertEqual(client_cache_one, {'test': 1}) 1603 self.assertEqual(client_cache_one, {'test': 1})
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1621 devices = device_utils.DeviceUtils.HealthyDevices() 1665 devices = device_utils.DeviceUtils.HealthyDevices()
1622 self.assertEquals(1, len(devices)) 1666 self.assertEquals(1, len(devices))
1623 self.assertTrue(isinstance(devices[0], device_utils.DeviceUtils)) 1667 self.assertTrue(isinstance(devices[0], device_utils.DeviceUtils))
1624 self.assertEquals('0123456789abcdef', devices[0].adb.GetDeviceSerial()) 1668 self.assertEquals('0123456789abcdef', devices[0].adb.GetDeviceSerial())
1625 1669
1626 1670
1627 if __name__ == '__main__': 1671 if __name__ == '__main__':
1628 logging.getLogger().setLevel(logging.DEBUG) 1672 logging.getLogger().setLevel(logging.DEBUG)
1629 unittest.main(verbosity=2) 1673 unittest.main(verbosity=2)
1630 1674
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698