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 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 Loading... |
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 |
164 class DeviceUtilsIsOnlineTest(DeviceUtilsTest): | 231 class DeviceUtilsIsOnlineTest(DeviceUtilsTest): |
165 | 232 |
166 def testIsOnline_true(self): | 233 def testIsOnline_true(self): |
167 with self.assertCall(self.call.adb.GetState(), 'device'): | 234 with self.assertCall(self.call.adb.GetState(), 'device'): |
168 self.assertTrue(self.device.IsOnline()) | 235 self.assertTrue(self.device.IsOnline()) |
169 | 236 |
170 def testIsOnline_false(self): | 237 def testIsOnline_false(self): |
171 with self.assertCall(self.call.adb.GetState(), 'offline'): | 238 with self.assertCall(self.call.adb.GetState(), 'offline'): |
172 self.assertFalse(self.device.IsOnline()) | 239 self.assertFalse(self.device.IsOnline()) |
173 | 240 |
(...skipping 1358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1532 'Rss': 101, | 1599 'Rss': 101, |
1533 'Pss': 102, | 1600 'Pss': 102, |
1534 'Shared_Clean': 103, | 1601 'Shared_Clean': 103, |
1535 'Shared_Dirty': 104, | 1602 'Shared_Dirty': 104, |
1536 'Private_Clean': 105, | 1603 'Private_Clean': 105, |
1537 'Private_Dirty': 106, | 1604 'Private_Dirty': 106, |
1538 }, | 1605 }, |
1539 self.device.GetMemoryUsageForPid(4321)) | 1606 self.device.GetMemoryUsageForPid(4321)) |
1540 | 1607 |
1541 | 1608 |
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): | 1609 class DeviceUtilsClientCache(DeviceUtilsTest): |
1551 | 1610 |
1552 def testClientCache_twoCaches(self): | 1611 def testClientCache_twoCaches(self): |
1553 self.device._cache['test'] = 0 | 1612 self.device._cache['test'] = 0 |
1554 client_cache_one = self.device.GetClientCache('ClientOne') | 1613 client_cache_one = self.device.GetClientCache('ClientOne') |
1555 client_cache_one['test'] = 1 | 1614 client_cache_one['test'] = 1 |
1556 client_cache_two = self.device.GetClientCache('ClientTwo') | 1615 client_cache_two = self.device.GetClientCache('ClientTwo') |
1557 client_cache_two['test'] = 2 | 1616 client_cache_two['test'] = 2 |
1558 self.assertEqual(self.device._cache, {'test': 0}) | 1617 self.assertEqual(self.device._cache, {'test': 0}) |
1559 self.assertEqual(client_cache_one, {'test': 1}) | 1618 self.assertEqual(client_cache_one, {'test': 1}) |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1621 devices = device_utils.DeviceUtils.HealthyDevices() | 1680 devices = device_utils.DeviceUtils.HealthyDevices() |
1622 self.assertEquals(1, len(devices)) | 1681 self.assertEquals(1, len(devices)) |
1623 self.assertTrue(isinstance(devices[0], device_utils.DeviceUtils)) | 1682 self.assertTrue(isinstance(devices[0], device_utils.DeviceUtils)) |
1624 self.assertEquals('0123456789abcdef', devices[0].adb.GetDeviceSerial()) | 1683 self.assertEquals('0123456789abcdef', devices[0].adb.GetDeviceSerial()) |
1625 | 1684 |
1626 | 1685 |
1627 if __name__ == '__main__': | 1686 if __name__ == '__main__': |
1628 logging.getLogger().setLevel(logging.DEBUG) | 1687 logging.getLogger().setLevel(logging.DEBUG) |
1629 unittest.main(verbosity=2) | 1688 unittest.main(verbosity=2) |
1630 | 1689 |
OLD | NEW |