예제 #1
0
    def testChooseImage(self):
        """Tests that we can detect a GPT image."""
        # pylint: disable=protected-access

        with self.PatchObject(flash,
                              '_IsFilePathGPTDiskImage',
                              return_value=True):
            # No images defined. Choosing the image should raise an error.
            with self.assertRaises(ValueError):
                flash._ChooseImageFromDirectory(self.tempdir)

            file_a = os.path.join(self.tempdir, 'a')
            osutils.Touch(file_a)
            # Only one image available, it should be selected automatically.
            self.assertEqual(file_a,
                             flash._ChooseImageFromDirectory(self.tempdir))

            osutils.Touch(os.path.join(self.tempdir, 'b'))
            file_c = os.path.join(self.tempdir, 'c')
            osutils.Touch(file_c)
            osutils.Touch(os.path.join(self.tempdir, 'd'))

            # Multiple images available, we should ask the user to select the right
            # image.
            with self.PatchObject(cros_build_lib, 'GetChoice', return_value=2):
                self.assertEqual(file_c,
                                 flash._ChooseImageFromDirectory(self.tempdir))
예제 #2
0
  def testChooseImage(self):
    """Tests that we can detect a GPT image."""
    # pylint: disable=protected-access

    with self.PatchObject(flash, '_IsFilePathGPTDiskImage', return_value=True):
      # No images defined. Choosing the image should raise an error.
      with self.assertRaises(ValueError):
        flash._ChooseImageFromDirectory(self.tempdir)

      file_a = os.path.join(self.tempdir, 'a')
      osutils.Touch(file_a)
      # Only one image available, it should be selected automatically.
      self.assertEqual(file_a, flash._ChooseImageFromDirectory(self.tempdir))

      osutils.Touch(os.path.join(self.tempdir, 'b'))
      file_c = os.path.join(self.tempdir, 'c')
      osutils.Touch(file_c)
      osutils.Touch(os.path.join(self.tempdir, 'd'))

      # Multiple images available, we should ask the user to select the right
      # image.
      with self.PatchObject(cros_build_lib, 'GetChoice', return_value=2):
        self.assertEqual(file_c, flash._ChooseImageFromDirectory(self.tempdir))