Пример #1
0
    def testFlashUsingCustomBinary(self, mock_class):
        """Test for FlashUsingCustomBinary().

            Tests if the method passes right args to customflasher
            and the execution path of the method.
        """
        mock_device = mock.Mock()
        mock_class.AndroidDevice.return_value = mock_device
        flasher = build_flasher.BuildFlasher("mySerial", "myCustomBinary")

        mock_device.isBootloaderMode = False
        device_images = {"img": "my/image/path"}
        flasher.FlashUsingCustomBinary(device_images, "reboottowhatever",
                                       ["myarg"])
        mock_device.adb.reboot.assert_called_with("reboottowhatever")
        mock_device.customflasher.ExecCustomFlasherCmd.assert_called_with(
            "myarg", "my/image/path")

        mock_device.reset_mock()
        mock_device.isBootloaderMode = True
        device_images["img"] = "my/other/image/path"
        flasher.FlashUsingCustomBinary(device_images, "reboottowhatever",
                                       ["myarg"])
        mock_device.adb.reboot.assert_not_called()
        mock_device.customflasher.ExecCustomFlasherCmd.assert_called_with(
            "myarg", "my/other/image/path")
Пример #2
0
 def testFlashGSIBadPath(self, mock_os, mock_class):
     flasher = build_flasher.BuildFlasher("thisismyserial")
     mock_os.path.exists.return_value = False
     with self.assertRaises(ValueError) as cm:
         flasher.FlashGSI("notexists.img")
     self.assertEqual("Couldn't find system image at notexists.img",
                      str(cm.exception))
Пример #3
0
 def testFlashGSISystemOnly(self, mock_os, mock_class):
     mock_device = mock.Mock()
     mock_class.AndroidDevice.return_value = mock_device
     flasher = build_flasher.BuildFlasher("thisismyserial")
     mock_os.path.exists.return_value = True
     flasher.FlashGSI("exists.img")
     mock_device.fastboot.erase.assert_any_call('system')
     mock_device.fastboot.flash.assert_any_call('system', 'exists.img')
     mock_device.fastboot.erase.assert_any_call('metadata')
Пример #4
0
    def testRepackageArtifacts(self, mock_open, mock_os, mock_cmd_utils,
                               mock_logger, mock_class):
        """Test for RepackageArtifacts().

            Tests if the method executes in correct path regarding
            given arguments.
        """
        mock_device = mock.Mock()
        mock_class.AndroidDevice.return_value = mock_device
        flasher = build_flasher.BuildFlasher("serial")
        device_images = {
            "system.img": "/my/tmp/path/system.img",
            "vendor.img": "/my/tmp/path/vendor.img"
        }
        mock_cmd_utils.ExecuteOneShellCommand.return_value = "", "", 0
        ret = flasher.RepackageArtifacts(device_images, "tar.md5")
        self.assertEqual(ret, True)
        self.assertIsNotNone(device_images["img"])

        ret = flasher.RepackageArtifacts(device_images, "incorrect")
        self.assertFalse(ret)
        mock_logger.error.assert_called_with(
            "Please specify correct repackage form: --repackage=incorrect")
Пример #5
0
 def testEmptySerial(self, mock_class):
     mock_class.list_adb_devices.return_value = ['oneserial']
     flasher = build_flasher.BuildFlasher(serial="")
     mock_class.AndroidDevice.assert_called_with("oneserial",
                                                 device_callback_port=-1)
Пример #6
0
 def testFlashall(self, mock_class):
     mock_device = mock.Mock()
     mock_class.AndroidDevice.return_value = mock_device
     flasher = build_flasher.BuildFlasher("thisismyserial")
     flasher.Flashall("path/to/dir")
     mock_device.fastboot.flashall.assert_called_with()