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

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

Issue 706203003: Update from https://crrev.com/303153 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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/pylib/device/device_utils.py ('k') | build/android/pylib/gtest/setup.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 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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 def assertShellCallSequence(self, calls): 306 def assertShellCallSequence(self, calls):
307 '''Assert that we expect a sequence of calls to adb.Shell. 307 '''Assert that we expect a sequence of calls to adb.Shell.
308 308
309 Args: 309 Args:
310 calls: a sequence of (cmd, return_value) pairs, where |cmd| is the 310 calls: a sequence of (cmd, return_value) pairs, where |cmd| is the
311 expected shell command to run on the device (with any quoting already 311 expected shell command to run on the device (with any quoting already
312 applied), and |return_value| is either a string to give as mock output 312 applied), and |return_value| is either a string to give as mock output
313 or a _ShellError object to raise an AdbShellCommandFailedError. 313 or a _ShellError object to raise an AdbShellCommandFailedError.
314 ''' 314 '''
315 def mk_expected_call(cmd, return_value): 315 def mk_expected_call(cmd, return_value):
316 expected_args = Args(cmd, expect_rc=0, timeout=10, retries=0) 316 expected_args = Args(cmd, expect_rc=0)
317 if isinstance(return_value, _ShellError): 317 if isinstance(return_value, _ShellError):
318 return_value = device_errors.AdbShellCommandFailedError(cmd, 318 return_value = device_errors.AdbShellCommandFailedError(cmd,
319 return_value.return_code, return_value.output, str(self.device)) 319 return_value.return_code, return_value.output, str(self.device))
320 elif isinstance(return_value, _CmdTimeout): 320 elif isinstance(return_value, _CmdTimeout):
321 return_value = device_errors.CommandTimeoutError(return_value.msg, 321 return_value = device_errors.CommandTimeoutError(return_value.msg,
322 str(self.device)) 322 str(self.device))
323 return (expected_args, return_value) 323 return (expected_args, return_value)
324 324
325 expected_calls = (mk_expected_call(a, r) for a, r in calls) 325 expected_calls = (mk_expected_call(a, r) for a, r in calls)
326 return MockCallSequence(self, self.adb, 'Shell', expected_calls) 326 return MockCallSequence(self, self.adb, 'Shell', expected_calls)
(...skipping 14 matching lines...) Expand all
341 def testIsOnline_true(self): 341 def testIsOnline_true(self):
342 self.adb.GetState = mock.Mock(return_value='device') 342 self.adb.GetState = mock.Mock(return_value='device')
343 self.assertTrue(self.device.IsOnline()) 343 self.assertTrue(self.device.IsOnline())
344 self.adb.GetState.assert_called_once_with() 344 self.adb.GetState.assert_called_once_with()
345 345
346 def testIsOnline_false(self): 346 def testIsOnline_false(self):
347 self.adb.GetState = mock.Mock(return_value='offline') 347 self.adb.GetState = mock.Mock(return_value='offline')
348 self.assertFalse(self.device.IsOnline()) 348 self.assertFalse(self.device.IsOnline())
349 self.adb.GetState.assert_called_once_with() 349 self.adb.GetState.assert_called_once_with()
350 350
351 def testIsOnline_error(self):
352 self.adb.GetState = mock.Mock(
353 side_effect=device_errors.CommandFailedError('falied'))
354 self.assertFalse(self.device.IsOnline())
355 self.adb.GetState.assert_called_once_with()
351 356
352 class DeviceUtilsHasRootTest(DeviceUtilsNewImplTest): 357 class DeviceUtilsHasRootTest(DeviceUtilsNewImplTest):
353 358
354 def testHasRoot_true(self): 359 def testHasRoot_true(self):
355 with self.assertShellCall('ls /root', 'foo\r\n'): 360 with self.assertShellCall('ls /root', 'foo\r\n'):
356 self.assertTrue(self.device.HasRoot()) 361 self.assertTrue(self.device.HasRoot())
357 362
358 def testHasRoot_false(self): 363 def testHasRoot_false(self):
359 with self.assertShellCall('ls /root', _ShellError()): 364 with self.assertShellCall('ls /root', _ShellError()):
360 self.assertFalse(self.device.HasRoot()) 365 self.assertFalse(self.device.HasRoot())
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 with self.assertRaises(device_errors.CommandFailedError): 438 with self.assertRaises(device_errors.CommandFailedError):
434 self.device.GetApplicationPath('android') 439 self.device.GetApplicationPath('android')
435 440
436 441
437 class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsNewImplTest): 442 class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsNewImplTest):
438 443
439 def testWaitUntilFullyBooted_succeedsNoWifi(self): 444 def testWaitUntilFullyBooted_succeedsNoWifi(self):
440 with self.assertShellCallSequence([ 445 with self.assertShellCallSequence([
441 # sc_card_ready 446 # sc_card_ready
442 ('echo $EXTERNAL_STORAGE', '/fake/storage/path\r\n'), 447 ('echo $EXTERNAL_STORAGE', '/fake/storage/path\r\n'),
443 ('ls /fake/storage/path', '/fake/storage/path\r\n'), 448 ('test -d /fake/storage/path', ''),
444 # pm_ready 449 # pm_ready
445 ('pm path android', 'package:this.is.a.test.package\r\n'), 450 ('pm path android', 'package:this.is.a.test.package\r\n'),
446 # boot_completed 451 # boot_completed
447 ('getprop sys.boot_completed', '1\r\n')]): 452 ('getprop sys.boot_completed', '1\r\n')]):
448 self.device.WaitUntilFullyBooted(wifi=False) 453 self.device.WaitUntilFullyBooted(wifi=False)
449 self.adb.WaitForDevice.assert_called_once_with() 454 self.adb.WaitForDevice.assert_called_once_with()
450 455
451 def testWaitUntilFullyBooted_succeedsWithWifi(self): 456 def testWaitUntilFullyBooted_succeedsWithWifi(self):
452 with self.assertShellCallSequence([ 457 with self.assertShellCallSequence([
453 # sc_card_ready 458 # sc_card_ready
454 ('echo $EXTERNAL_STORAGE', '/fake/storage/path\r\n'), 459 ('echo $EXTERNAL_STORAGE', '/fake/storage/path\r\n'),
455 ('ls /fake/storage/path', '/fake/storage/path\r\n'), 460 ('test -d /fake/storage/path', ''),
456 # pm_ready 461 # pm_ready
457 ('pm path android', 'package:this.is.a.test.package\r\n'), 462 ('pm path android', 'package:this.is.a.test.package\r\n'),
458 # boot_completed 463 # boot_completed
459 ('getprop sys.boot_completed', '1\r\n'), 464 ('getprop sys.boot_completed', '1\r\n'),
460 # wifi_enabled 465 # wifi_enabled
461 ('dumpsys wifi', 'stuff\r\nWi-Fi is enabled\r\nmore stuff\r\n')]): 466 ('dumpsys wifi', 'stuff\r\nWi-Fi is enabled\r\nmore stuff\r\n')]):
462 self.device.WaitUntilFullyBooted(wifi=True) 467 self.device.WaitUntilFullyBooted(wifi=True)
463 self.adb.WaitForDevice.assert_called_once_with() 468 self.adb.WaitForDevice.assert_called_once_with()
464 469
465 def testWaitUntilFullyBooted_sdCardReadyFails_noPath(self): 470 def testWaitUntilFullyBooted_sdCardReadyFails_noPath(self):
466 with self.assertShellCallSequence([ 471 with self.assertShellCallSequence([
467 # sc_card_ready 472 # sc_card_ready
468 ('echo $EXTERNAL_STORAGE', '\r\n')]): 473 ('echo $EXTERNAL_STORAGE', '\r\n')]):
469 with self.assertRaises(device_errors.CommandFailedError): 474 with self.assertRaises(device_errors.CommandFailedError):
470 self.device.WaitUntilFullyBooted(wifi=False) 475 self.device.WaitUntilFullyBooted(wifi=False)
471 476
472 def testWaitUntilFullyBooted_sdCardReadyFails_emptyPath(self): 477 def testWaitUntilFullyBooted_sdCardReadyFails_emptyPath(self):
473 with mock.patch('time.sleep'): 478 with mock.patch('time.sleep'):
474 with self.assertShellCallSequence([ 479 with self.assertShellCallSequence([
475 # sc_card_ready 480 # sc_card_ready
476 ('echo $EXTERNAL_STORAGE', '/fake/storage/path\r\n'), 481 ('echo $EXTERNAL_STORAGE', '/fake/storage/path\r\n'),
477 ('ls /fake/storage/path', '\r\n'), 482 ('test -d /fake/storage/path', _ShellError()),
478 # sc_card_ready 483 # sc_card_ready
479 ('ls /fake/storage/path', '\r\n'), 484 ('test -d /fake/storage/path', _ShellError()),
480 # sc_card_ready 485 # sc_card_ready
481 ('ls /fake/storage/path', _CmdTimeout())]): 486 ('test -d /fake/storage/path', _CmdTimeout())]):
482 with self.assertRaises(device_errors.CommandTimeoutError): 487 with self.assertRaises(device_errors.CommandTimeoutError):
483 self.device.WaitUntilFullyBooted(wifi=False) 488 self.device.WaitUntilFullyBooted(wifi=False)
484 489
485 def testWaitUntilFullyBooted_devicePmFails(self): 490 def testWaitUntilFullyBooted_devicePmFails(self):
486 with mock.patch('time.sleep'): 491 with mock.patch('time.sleep'):
487 with self.assertShellCallSequence([ 492 with self.assertShellCallSequence([
488 # sc_card_ready 493 # sc_card_ready
489 ('echo $EXTERNAL_STORAGE', '/fake/storage/path\r\n'), 494 ('echo $EXTERNAL_STORAGE', '/fake/storage/path\r\n'),
490 ('ls /fake/storage/path', '/fake/storage/path\r\n'), 495 ('test -d /fake/storage/path', ''),
491 # pm_ready 496 # pm_ready
492 ('pm path android', 'Error. Is package manager running?\r\n'), 497 ('pm path android', 'Error. Is package manager running?\r\n'),
493 # pm_ready 498 # pm_ready
494 ('pm path android', 'Error. Is package manager running?\r\n'), 499 ('pm path android', 'Error. Is package manager running?\r\n'),
495 # pm_ready 500 # pm_ready
496 ('pm path android', _CmdTimeout())]): 501 ('pm path android', _CmdTimeout())]):
497 with self.assertRaises(device_errors.CommandTimeoutError): 502 with self.assertRaises(device_errors.CommandTimeoutError):
498 self.device.WaitUntilFullyBooted(wifi=False) 503 self.device.WaitUntilFullyBooted(wifi=False)
499 504
500 def testWaitUntilFullyBooted_bootFails(self): 505 def testWaitUntilFullyBooted_bootFails(self):
501 with mock.patch('time.sleep'): 506 with mock.patch('time.sleep'):
502 with self.assertShellCallSequence([ 507 with self.assertShellCallSequence([
503 # sc_card_ready 508 # sc_card_ready
504 ('echo $EXTERNAL_STORAGE', '/fake/storage/path\r\n'), 509 ('echo $EXTERNAL_STORAGE', '/fake/storage/path\r\n'),
505 ('ls /fake/storage/path', '/fake/storage/path\r\n'), 510 ('test -d /fake/storage/path', ''),
506 # pm_ready 511 # pm_ready
507 ('pm path android', 'package:this.is.a.test.package\r\n'), 512 ('pm path android', 'package:this.is.a.test.package\r\n'),
508 # boot_completed 513 # boot_completed
509 ('getprop sys.boot_completed', '0\r\n'), 514 ('getprop sys.boot_completed', '0\r\n'),
510 # boot_completed 515 # boot_completed
511 ('getprop sys.boot_completed', '0\r\n'), 516 ('getprop sys.boot_completed', '0\r\n'),
512 # boot_completed 517 # boot_completed
513 ('getprop sys.boot_completed', _CmdTimeout())]): 518 ('getprop sys.boot_completed', _CmdTimeout())]):
514 with self.assertRaises(device_errors.CommandTimeoutError): 519 with self.assertRaises(device_errors.CommandTimeoutError):
515 self.device.WaitUntilFullyBooted(wifi=False) 520 self.device.WaitUntilFullyBooted(wifi=False)
516 521
517 def testWaitUntilFullyBooted_wifiFails(self): 522 def testWaitUntilFullyBooted_wifiFails(self):
518 with mock.patch('time.sleep'): 523 with mock.patch('time.sleep'):
519 with self.assertShellCallSequence([ 524 with self.assertShellCallSequence([
520 # sc_card_ready 525 # sc_card_ready
521 ('echo $EXTERNAL_STORAGE', '/fake/storage/path\r\n'), 526 ('echo $EXTERNAL_STORAGE', '/fake/storage/path\r\n'),
522 ('ls /fake/storage/path', '/fake/storage/path\r\n'), 527 ('test -d /fake/storage/path', ''),
523 # pm_ready 528 # pm_ready
524 ('pm path android', 'package:this.is.a.test.package\r\n'), 529 ('pm path android', 'package:this.is.a.test.package\r\n'),
525 # boot_completed 530 # boot_completed
526 ('getprop sys.boot_completed', '1\r\n'), 531 ('getprop sys.boot_completed', '1\r\n'),
527 # wifi_enabled 532 # wifi_enabled
528 ('dumpsys wifi', 'stuff\r\nmore stuff\r\n'), 533 ('dumpsys wifi', 'stuff\r\nmore stuff\r\n'),
529 # wifi_enabled 534 # wifi_enabled
530 ('dumpsys wifi', 'stuff\r\nmore stuff\r\n'), 535 ('dumpsys wifi', 'stuff\r\nmore stuff\r\n'),
531 # wifi_enabled 536 # wifi_enabled
532 ('dumpsys wifi', _CmdTimeout())]): 537 ('dumpsys wifi', _CmdTimeout())]):
533 with self.assertRaises(device_errors.CommandTimeoutError): 538 with self.assertRaises(device_errors.CommandTimeoutError):
534 self.device.WaitUntilFullyBooted(wifi=True) 539 self.device.WaitUntilFullyBooted(wifi=True)
535 540
536 541
537 class DeviceUtilsRebootTest(DeviceUtilsNewImplTest): 542 class DeviceUtilsRebootTest(DeviceUtilsNewImplTest):
538 543
539 def testReboot_nonBlocking(self): 544 def testReboot_nonBlocking(self):
540 self.adb.Reboot = mock.Mock() 545 self.adb.Reboot = mock.Mock()
541 self.device.IsOnline = mock.Mock(return_value=False) 546 self.device.IsOnline = mock.Mock(return_value=False)
542 self.device.Reboot(block=False) 547 self.device.Reboot(block=False)
543 self.adb.Reboot.assert_called_once_with() 548 self.adb.Reboot.assert_called_once_with()
544 self.device.IsOnline.assert_called_once_with() 549 self.device.IsOnline.assert_called_once_with()
545 550
546 def testReboot_blocking(self): 551 def testReboot_blocking(self):
547 self.adb.Reboot = mock.Mock() 552 self.adb.Reboot = mock.Mock()
548 self.device.IsOnline = mock.Mock(return_value=False) 553 self.device.IsOnline = mock.Mock(return_value=False)
549 with self.assertShellCallSequence([ 554 with self.assertShellCallSequence([
550 # sc_card_ready 555 # sc_card_ready
551 ('echo $EXTERNAL_STORAGE', '/fake/storage/path\r\n'), 556 ('echo $EXTERNAL_STORAGE', '/fake/storage/path\r\n'),
552 ('ls /fake/storage/path', '/fake/storage/path\r\n'), 557 ('test -d /fake/storage/path', ''),
553 # pm_ready 558 # pm_ready
554 ('pm path android', 'package:this.is.a.test.package\r\n'), 559 ('pm path android', 'package:this.is.a.test.package\r\n'),
555 # boot_completed 560 # boot_completed
556 ('getprop sys.boot_completed', '1\r\n')]): 561 ('getprop sys.boot_completed', '1\r\n')]):
557 self.device.Reboot(block=True) 562 self.device.Reboot(block=True)
558 self.adb.Reboot.assert_called_once_with() 563 self.adb.Reboot.assert_called_once_with()
559 self.device.IsOnline.assert_called_once_with() 564 self.device.IsOnline.assert_called_once_with()
560 self.adb.WaitForDevice.assert_called_once_with() 565 self.adb.WaitForDevice.assert_called_once_with()
561 566
562 567
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 def testNewRunShellImpl_withCwd(self): 683 def testNewRunShellImpl_withCwd(self):
679 with self.assertShellCall('cd /some/test/path && ls'): 684 with self.assertShellCall('cd /some/test/path && ls'):
680 self.device.RunShellCommand('ls', cwd='/some/test/path') 685 self.device.RunShellCommand('ls', cwd='/some/test/path')
681 686
682 def testNewRunShellImpl_withCwdQuoted(self): 687 def testNewRunShellImpl_withCwdQuoted(self):
683 with self.assertShellCall("cd '/some test/path with/spaces' && ls"): 688 with self.assertShellCall("cd '/some test/path with/spaces' && ls"):
684 self.device.RunShellCommand('ls', cwd='/some test/path with/spaces') 689 self.device.RunShellCommand('ls', cwd='/some test/path with/spaces')
685 690
686 def testRunShellCommand_withSu(self): 691 def testRunShellCommand_withSu(self):
687 with self.assertShellCallSequence([ 692 with self.assertShellCallSequence([
688 ('ls /root', _ShellError()), 693 ('su -c ls /root && ! ls /root', ''),
689 ('su -c setprop service.adb.root 0', '')]): 694 ('su -c setprop service.adb.root 0', '')]):
690 self.device.RunShellCommand('setprop service.adb.root 0', as_root=True) 695 self.device.RunShellCommand('setprop service.adb.root 0', as_root=True)
691 696
692 def testRunShellCommand_withRoot(self): 697 def testRunShellCommand_withRoot(self):
693 with self.assertShellCallSequence([ 698 with self.assertShellCallSequence([
694 ('ls /root', '\r\n'), 699 ('su -c ls /root && ! ls /root', _ShellError()),
695 ('setprop service.adb.root 0', '')]): 700 ('setprop service.adb.root 0', '')]):
696 self.device.RunShellCommand('setprop service.adb.root 0', as_root=True) 701 self.device.RunShellCommand('setprop service.adb.root 0', as_root=True)
697 702
698 def testRunShellCommand_manyLines(self): 703 def testRunShellCommand_manyLines(self):
699 cmd = 'ls /some/path' 704 cmd = 'ls /some/path'
700 with self.assertShellCall(cmd, 'file1\r\nfile2\r\nfile3\r\n'): 705 with self.assertShellCall(cmd, 'file1\r\nfile2\r\nfile3\r\n'):
701 self.assertEquals(['file1', 'file2', 'file3'], 706 self.assertEquals(['file1', 'file2', 'file3'],
702 self.device.RunShellCommand(cmd)) 707 self.device.RunShellCommand(cmd))
703 708
704 def testRunShellCommand_singleLine_success(self): 709 def testRunShellCommand_singleLine_success(self):
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 'this.is.a.test.process\r\n'), 787 'this.is.a.test.process\r\n'),
783 ('ps', 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n')]): 788 ('ps', 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n')]):
784 self.assertEquals(1, 789 self.assertEquals(1,
785 self.device.KillAll('this.is.a.test.process', blocking=True)) 790 self.device.KillAll('this.is.a.test.process', blocking=True))
786 791
787 def testKillAll_root(self): 792 def testKillAll_root(self):
788 with self.assertShellCallSequence([ 793 with self.assertShellCallSequence([
789 ('ps', 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n' 794 ('ps', 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n'
790 'u0_a1 1234 174 123456 54321 ffffffff 456789ab ' 795 'u0_a1 1234 174 123456 54321 ffffffff 456789ab '
791 'this.is.a.test.process\r\n'), 796 'this.is.a.test.process\r\n'),
792 ('ls /root', _ShellError()), 797 ('su -c ls /root && ! ls /root', ''),
793 ('su -c kill -9 1234', '')]): 798 ('su -c kill -9 1234', '')]):
794 self.assertEquals(1, 799 self.assertEquals(1,
795 self.device.KillAll('this.is.a.test.process', as_root=True)) 800 self.device.KillAll('this.is.a.test.process', as_root=True))
796 801
797 def testKillAll_sigterm(self): 802 def testKillAll_sigterm(self):
798 with self.assertShellCallSequence([ 803 with self.assertShellCallSequence([
799 ('ps', 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n' 804 ('ps', 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n'
800 'u0_a1 1234 174 123456 54321 ffffffff 456789ab ' 805 'u0_a1 1234 174 123456 54321 ffffffff 456789ab '
801 'this.is.a.test.process\r\n'), 806 'this.is.a.test.process\r\n'),
802 ('kill -15 1234', '')]): 807 ('kill -15 1234', '')]):
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 test_files = [] 1088 test_files = []
1084 self.device._PushChangedFilesZipped(test_files) 1089 self.device._PushChangedFilesZipped(test_files)
1085 self.assertEqual(0, self.adb.Push.call_count) 1090 self.assertEqual(0, self.adb.Push.call_count)
1086 1091
1087 def testPushChangedFilesZipped_single(self): 1092 def testPushChangedFilesZipped_single(self):
1088 test_files = [('/test/host/path/file1', '/test/device/path/file1')] 1093 test_files = [('/test/host/path/file1', '/test/device/path/file1')]
1089 1094
1090 self.device._GetExternalStoragePathImpl = mock.Mock( 1095 self.device._GetExternalStoragePathImpl = mock.Mock(
1091 return_value='/test/device/external_dir') 1096 return_value='/test/device/external_dir')
1092 self.device.IsOnline = mock.Mock(return_value=True) 1097 self.device.IsOnline = mock.Mock(return_value=True)
1093 self.device._RunShellCommandImpl = mock.Mock() 1098 self.device.RunShellCommand = mock.Mock()
1094 mock_zip_temp = mock.mock_open() 1099 mock_zip_temp = mock.mock_open()
1095 mock_zip_temp.return_value.name = '/test/temp/file/tmp.zip' 1100 mock_zip_temp.return_value.name = '/test/temp/file/tmp.zip'
1096 with mock.patch('multiprocessing.Process') as mock_zip_proc, ( 1101 with mock.patch('multiprocessing.Process') as mock_zip_proc, (
1097 mock.patch('tempfile.NamedTemporaryFile', mock_zip_temp)): 1102 mock.patch('tempfile.NamedTemporaryFile', mock_zip_temp)):
1098 self.device._PushChangedFilesZipped(test_files) 1103 self.device._PushChangedFilesZipped(test_files)
1099 1104
1100 mock_zip_proc.assert_called_once_with( 1105 mock_zip_proc.assert_called_once_with(
1101 target=device_utils.DeviceUtils._CreateDeviceZip, 1106 target=device_utils.DeviceUtils._CreateDeviceZip,
1102 args=('/test/temp/file/tmp.zip', test_files)) 1107 args=('/test/temp/file/tmp.zip', test_files))
1103 self.adb.Push.assert_called_once_with( 1108 self.adb.Push.assert_called_once_with(
1104 '/test/temp/file/tmp.zip', '/test/device/external_dir/tmp.zip') 1109 '/test/temp/file/tmp.zip', '/test/device/external_dir/tmp.zip')
1105 self.assertEqual(2, self.device._RunShellCommandImpl.call_count) 1110 self.assertEqual(2, self.device.RunShellCommand.call_count)
1106 self.device._RunShellCommandImpl.assert_any_call( 1111 self.device.RunShellCommand.assert_any_call(
1107 ['unzip', '/test/device/external_dir/tmp.zip'], 1112 ['unzip', '/test/device/external_dir/tmp.zip'],
1108 as_root=True, 1113 as_root=True,
1109 env={'PATH': '$PATH:/data/local/tmp/bin'}, 1114 env={'PATH': '$PATH:/data/local/tmp/bin'},
1110 check_return=True) 1115 check_return=True)
1111 self.device._RunShellCommandImpl.assert_any_call( 1116 self.device.RunShellCommand.assert_any_call(
1112 ['rm', '/test/device/external_dir/tmp.zip'], check_return=True) 1117 ['rm', '/test/device/external_dir/tmp.zip'], check_return=True)
1113 1118
1114 def testPushChangedFilesZipped_multiple(self): 1119 def testPushChangedFilesZipped_multiple(self):
1115 test_files = [('/test/host/path/file1', '/test/device/path/file1'), 1120 test_files = [('/test/host/path/file1', '/test/device/path/file1'),
1116 ('/test/host/path/file2', '/test/device/path/file2')] 1121 ('/test/host/path/file2', '/test/device/path/file2')]
1117 1122
1118 self.device._GetExternalStoragePathImpl = mock.Mock( 1123 self.device._GetExternalStoragePathImpl = mock.Mock(
1119 return_value='/test/device/external_dir') 1124 return_value='/test/device/external_dir')
1120 self.device.IsOnline = mock.Mock(return_value=True) 1125 self.device.IsOnline = mock.Mock(return_value=True)
1121 self.device._RunShellCommandImpl = mock.Mock() 1126 self.device.RunShellCommand = mock.Mock()
1122 mock_zip_temp = mock.mock_open() 1127 mock_zip_temp = mock.mock_open()
1123 mock_zip_temp.return_value.name = '/test/temp/file/tmp.zip' 1128 mock_zip_temp.return_value.name = '/test/temp/file/tmp.zip'
1124 with mock.patch('multiprocessing.Process') as mock_zip_proc, ( 1129 with mock.patch('multiprocessing.Process') as mock_zip_proc, (
1125 mock.patch('tempfile.NamedTemporaryFile', mock_zip_temp)): 1130 mock.patch('tempfile.NamedTemporaryFile', mock_zip_temp)):
1126 self.device._PushChangedFilesZipped(test_files) 1131 self.device._PushChangedFilesZipped(test_files)
1127 1132
1128 mock_zip_proc.assert_called_once_with( 1133 mock_zip_proc.assert_called_once_with(
1129 target=device_utils.DeviceUtils._CreateDeviceZip, 1134 target=device_utils.DeviceUtils._CreateDeviceZip,
1130 args=('/test/temp/file/tmp.zip', test_files)) 1135 args=('/test/temp/file/tmp.zip', test_files))
1131 self.adb.Push.assert_called_once_with( 1136 self.adb.Push.assert_called_once_with(
1132 '/test/temp/file/tmp.zip', '/test/device/external_dir/tmp.zip') 1137 '/test/temp/file/tmp.zip', '/test/device/external_dir/tmp.zip')
1133 self.assertEqual(2, self.device._RunShellCommandImpl.call_count) 1138 self.assertEqual(2, self.device.RunShellCommand.call_count)
1134 self.device._RunShellCommandImpl.assert_any_call( 1139 self.device.RunShellCommand.assert_any_call(
1135 ['unzip', '/test/device/external_dir/tmp.zip'], 1140 ['unzip', '/test/device/external_dir/tmp.zip'],
1136 as_root=True, 1141 as_root=True,
1137 env={'PATH': '$PATH:/data/local/tmp/bin'}, 1142 env={'PATH': '$PATH:/data/local/tmp/bin'},
1138 check_return=True) 1143 check_return=True)
1139 self.device._RunShellCommandImpl.assert_any_call( 1144 self.device.RunShellCommand.assert_any_call(
1140 ['rm', '/test/device/external_dir/tmp.zip'], check_return=True) 1145 ['rm', '/test/device/external_dir/tmp.zip'], check_return=True)
1141 1146
1142 1147
1143 class DeviceUtilsFileExistsTest(DeviceUtilsOldImplTest): 1148 class DeviceUtilsFileExistsTest(DeviceUtilsOldImplTest):
1144 1149
1145 def testFileExists_usingTest_fileExists(self): 1150 def testFileExists_usingTest_fileExists(self):
1146 with self.assertCalls( 1151 with self.assertCalls(
1147 "adb -s 0123456789abcdef shell " 1152 "adb -s 0123456789abcdef shell "
1148 "'test -e \"/data/app/test.file.exists\"; echo $?'", 1153 "'test -e \"/data/app/test.file.exists\"; echo $?'",
1149 '0\r\n'): 1154 '0\r\n'):
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1371 with self.assertShellCall('echo some.string > /test/file/to.write'): 1376 with self.assertShellCall('echo some.string > /test/file/to.write'):
1372 self.device.WriteTextFile('/test/file/to.write', 'some.string') 1377 self.device.WriteTextFile('/test/file/to.write', 'some.string')
1373 1378
1374 def testWriteTextFileTest_quoted(self): 1379 def testWriteTextFileTest_quoted(self):
1375 with self.assertShellCall( 1380 with self.assertShellCall(
1376 "echo 'some other string' > '/test/file/to write'"): 1381 "echo 'some other string' > '/test/file/to write'"):
1377 self.device.WriteTextFile('/test/file/to write', 'some other string') 1382 self.device.WriteTextFile('/test/file/to write', 'some other string')
1378 1383
1379 def testWriteTextFileTest_asRoot(self): 1384 def testWriteTextFileTest_asRoot(self):
1380 with self.assertShellCallSequence([ 1385 with self.assertShellCallSequence([
1381 ('ls /root', _ShellError()), 1386 ('su -c ls /root && ! ls /root', ''),
1382 ('su -c echo string > /test/file', '')]): 1387 ('su -c echo string > /test/file', '')]):
1383 self.device.WriteTextFile('/test/file', 'string', as_root=True) 1388 self.device.WriteTextFile('/test/file', 'string', as_root=True)
1384 1389
1385 class DeviceUtilsLsTest(DeviceUtilsOldImplTest): 1390 class DeviceUtilsLsTest(DeviceUtilsOldImplTest):
1386 1391
1387 def testLs_nothing(self): 1392 def testLs_nothing(self):
1388 with self.assertCallsSequence([ 1393 with self.assertCallsSequence([
1389 ("adb -s 0123456789abcdef shell 'ls -lR /this/file/does.not.exist'", 1394 ("adb -s 0123456789abcdef shell 'ls -lR /this/file/does.not.exist'",
1390 '/this/file/does.not.exist: No such file or directory\r\n'), 1395 '/this/file/does.not.exist: No such file or directory\r\n'),
1391 ("adb -s 0123456789abcdef shell 'date +%z'", '+0000')]): 1396 ("adb -s 0123456789abcdef shell 'date +%z'", '+0000')]):
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
1676 self.device = device_utils.DeviceUtils(None) 1681 self.device = device_utils.DeviceUtils(None)
1677 with self.assertCalls('adb get-serialno', 'unknown'), ( 1682 with self.assertCalls('adb get-serialno', 'unknown'), (
1678 self.assertRaises(device_errors.NoDevicesError)): 1683 self.assertRaises(device_errors.NoDevicesError)):
1679 str(self.device) 1684 str(self.device)
1680 1685
1681 1686
1682 if __name__ == '__main__': 1687 if __name__ == '__main__':
1683 logging.getLogger().setLevel(logging.DEBUG) 1688 logging.getLogger().setLevel(logging.DEBUG)
1684 unittest.main(verbosity=2) 1689 unittest.main(verbosity=2)
1685 1690
OLDNEW
« no previous file with comments | « build/android/pylib/device/device_utils.py ('k') | build/android/pylib/gtest/setup.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698