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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 def testEnableRoot_rootFails(self): | 281 def testEnableRoot_rootFails(self): |
282 with self.assertCallsSequence([ | 282 with self.assertCallsSequence([ |
283 ('adb -s 0123456789abcdef shell getprop ro.build.type', | 283 ('adb -s 0123456789abcdef shell getprop ro.build.type', |
284 'userdebug\r\n'), | 284 'userdebug\r\n'), |
285 ('adb -s 0123456789abcdef root', 'no\r\n'), | 285 ('adb -s 0123456789abcdef root', 'no\r\n'), |
286 ('adb -s 0123456789abcdef wait-for-device', '')]): | 286 ('adb -s 0123456789abcdef wait-for-device', '')]): |
287 with self.assertRaises(device_errors.CommandFailedError): | 287 with self.assertRaises(device_errors.CommandFailedError): |
288 self.device.EnableRoot() | 288 self.device.EnableRoot() |
289 | 289 |
290 | 290 |
| 291 class DeviceUtilsIsUserBuildTest(DeviceUtilsOldImplTest): |
| 292 |
| 293 def testIsUserBuild_yes(self): |
| 294 with self.assertCalls( |
| 295 'adb -s 0123456789abcdef shell getprop ro.build.type', |
| 296 'user\r\n'): |
| 297 self.assertTrue(self.device.IsUserBuild()) |
| 298 |
| 299 def testIsUserBuild_no(self): |
| 300 with self.assertCalls( |
| 301 'adb -s 0123456789abcdef shell getprop ro.build.type', |
| 302 'userdebug\r\n'): |
| 303 self.assertFalse(self.device.IsUserBuild()) |
| 304 |
| 305 |
291 class DeviceUtilsGetExternalStoragePathTest(DeviceUtilsOldImplTest): | 306 class DeviceUtilsGetExternalStoragePathTest(DeviceUtilsOldImplTest): |
292 | 307 |
293 def testGetExternalStoragePath_succeeds(self): | 308 def testGetExternalStoragePath_succeeds(self): |
294 fakeStoragePath = '/fake/storage/path' | 309 fakeStoragePath = '/fake/storage/path' |
295 with self.assertCalls( | 310 with self.assertCalls( |
296 "adb -s 0123456789abcdef shell 'echo $EXTERNAL_STORAGE'", | 311 "adb -s 0123456789abcdef shell 'echo $EXTERNAL_STORAGE'", |
297 '%s\r\n' % fakeStoragePath): | 312 '%s\r\n' % fakeStoragePath): |
298 self.assertEquals(fakeStoragePath, | 313 self.assertEquals(fakeStoragePath, |
299 self.device.GetExternalStoragePath()) | 314 self.device.GetExternalStoragePath()) |
300 | 315 |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
889 ('/test/host/path/file1', '/test/device/path/file1'), | 904 ('/test/host/path/file1', '/test/device/path/file1'), |
890 ('/test/host/path/file2', '/test/device/path/file2')] | 905 ('/test/host/path/file2', '/test/device/path/file2')] |
891 self.device._PushChangedFilesIndividually(test_files) | 906 self.device._PushChangedFilesIndividually(test_files) |
892 self.assertEqual(2, self.adb.Push.call_count) | 907 self.assertEqual(2, self.adb.Push.call_count) |
893 self.adb.Push.assert_any_call( | 908 self.adb.Push.assert_any_call( |
894 '/test/host/path/file1', '/test/device/path/file1') | 909 '/test/host/path/file1', '/test/device/path/file1') |
895 self.adb.Push.assert_any_call( | 910 self.adb.Push.assert_any_call( |
896 '/test/host/path/file2', '/test/device/path/file2') | 911 '/test/host/path/file2', '/test/device/path/file2') |
897 | 912 |
898 | 913 |
| 914 @mock.patch('pylib.device.commands.install_commands.Installed', new=None) |
| 915 @mock.patch('pylib.device.commands.install_commands.InstallCommands', new=None) |
899 class DeviceUtilsPushChangedFilesZippedTest(DeviceUtilsHybridImplTest): | 916 class DeviceUtilsPushChangedFilesZippedTest(DeviceUtilsHybridImplTest): |
900 | 917 |
901 def setUp(self): | 918 def setUp(self): |
902 super(DeviceUtilsPushChangedFilesZippedTest, self).setUp() | 919 super(DeviceUtilsPushChangedFilesZippedTest, self).setUp() |
903 self.original_install_commands = self.device._InstallCommands | |
904 self.device._InstallCommands = mock.Mock() | |
905 | 920 |
906 def testPushChangedFilesZipped_empty(self): | 921 def testPushChangedFilesZipped_empty(self): |
907 test_files = [] | 922 test_files = [] |
908 self.device._PushChangedFilesZipped(test_files) | 923 self.device._PushChangedFilesZipped(test_files) |
909 self.assertEqual(0, self.adb.Push.call_count) | 924 self.assertEqual(0, self.adb.Push.call_count) |
910 | 925 |
911 def testPushChangedFilesZipped_single(self): | 926 def testPushChangedFilesZipped_single(self): |
912 test_files = [('/test/host/path/file1', '/test/device/path/file1')] | 927 test_files = [('/test/host/path/file1', '/test/device/path/file1')] |
913 | 928 |
914 self.device._GetExternalStoragePathImpl = mock.Mock( | 929 self.device._GetExternalStoragePathImpl = mock.Mock( |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1511 self.device = device_utils.DeviceUtils(None) | 1526 self.device = device_utils.DeviceUtils(None) |
1512 with self.assertCalls('adb get-serialno', 'unknown'), ( | 1527 with self.assertCalls('adb get-serialno', 'unknown'), ( |
1513 self.assertRaises(device_errors.NoDevicesError)): | 1528 self.assertRaises(device_errors.NoDevicesError)): |
1514 str(self.device) | 1529 str(self.device) |
1515 | 1530 |
1516 | 1531 |
1517 if __name__ == '__main__': | 1532 if __name__ == '__main__': |
1518 logging.getLogger().setLevel(logging.DEBUG) | 1533 logging.getLogger().setLevel(logging.DEBUG) |
1519 unittest.main(verbosity=2) | 1534 unittest.main(verbosity=2) |
1520 | 1535 |
OLD | NEW |