Beispiel #1
0
 def testInflateMask(self):
   cross_image = Image.new('RGBA', (3, 3))
   white_image = Image.new('RGBA', (3, 3))
   dot_image = Image.new('RGBA', (3, 3))
   b = (0, 0, 0, 255)
   w = (255, 255, 255, 255)
   dot_image.putdata([b, b, b,
                      b, w, b,
                      b, b, b])
   cross_image.putdata([b, w, b,
                        w, w, w,
                        b, w, b])
   white_image.putdata([w, w, w,
                        w, w, w,
                        w, w, w])
   self.assertEquals(list(image_tools.InflateMask(dot_image, 1).getdata()),
                     list(cross_image.getdata()))
   self.assertEquals(list(image_tools.InflateMask(dot_image, 0).getdata()),
                     list(dot_image.getdata()))
   self.assertEquals(list(image_tools.InflateMask(dot_image, 2).getdata()),
                     list(white_image.getdata()))
   self.assertEquals(list(image_tools.InflateMask(dot_image, 3).getdata()),
                     list(white_image.getdata()))
   self.assertEquals(list(image_tools.InflateMask(self.black25, 1).getdata()),
                     list(self.black25.getdata()))
Beispiel #2
0
  def GenerateExpectationPinkOut(self, expectation, images, pint_out, rgb):
    """Uploads an ispy-test to GS with the pink_out workaround.

    Args:
      expectation: the name of the expectation to be uploaded.
      images: a json encoded list of base64 encoded png images.
      pink_out: an image.
      RGB: a json list representing the RGB values of a color to mask out.

    Raises:
      ValueError: if expectation name is invalid.
    """
    if not IsValidExpectationName(expectation):
      raise ValueError("Expectation name contains an illegal character: %s." %
                       str(_INVALID_EXPECTATION_CHARS))

    # convert the pink_out into a mask
    black = (0, 0, 0, 255)
    white = (255, 255, 255, 255)
    pink_out.putdata(
        [black if px == (rgb[0], rgb[1], rgb[2], 255) else white
         for px in pink_out.getdata()])
    mask = image_tools.CreateMask(images)
    mask = image_tools.InflateMask(image_tools.CreateMask(images), 7)
    combined_mask = image_tools.AddMasks([mask, pink_out])
    self.UploadImage(GetExpectationPath(expectation, 'expected.png'), images[0])
    self.UploadImage(GetExpectationPath(expectation, 'mask.png'), combined_mask)
Beispiel #3
0
    def UploadExpectation(self, expectation, images):
        """Creates and uploads an expectation to GS from a set of images and name.

    This method generates a mask from the uploaded images, then
      uploads the mask and first of the images to GS as a expectation.

    Args:
      expectation: name for this expectation, any existing expectation with the
        name will be replaced.
      images: a list of RGB encoded PIL.Images
    """
        mask = image_tools.InflateMask(image_tools.CreateMask(images), 7)
        self.UploadImage(GetExpectationPath(expectation, 'expected.png'),
                         images[0])
        self.UploadImage(GetExpectationPath(expectation, 'mask.png'), mask)
Beispiel #4
0
  def GenerateExpectation(self, expectation, images):
    """Creates and uploads an expectation to GS from a set of images and name.

    This method generates a mask from the uploaded images, then
      uploads the mask and first of the images to GS as a expectation.

    Args:
      expectation: name for this expectation, any existing expectation with the
        name will be replaced.
      images: a list of RGB encoded PIL.Images

    Raises:
      ValueError: if the expectation name is invalid.
    """
    if not IsValidExpectationName(expectation):
      raise ValueError("Expectation name contains an illegal character: %s." %
                       str(_INVALID_EXPECTATION_CHARS))

    mask = image_tools.InflateMask(image_tools.CreateMask(images), 7)
    self.UploadImage(
        GetExpectationPath(expectation, 'expected.png'), images[0])
    self.UploadImage(GetExpectationPath(expectation, 'mask.png'), mask)
Beispiel #5
0
    def UploadExpectationPinkOut(self, expectation, images, pint_out, rgb):
        """Uploads an ispy-test to GS with the pink_out workaround.

    Args:
      expectation: the name of the expectation to be uploaded.
      images: a json encoded list of base64 encoded png images.
      pink_out: an image.
      RGB: a json list representing the RGB values of a color to mask out.
    """
        # convert the pink_out into a mask
        black = (0, 0, 0, 255)
        white = (255, 255, 255, 255)
        pink_out.putdata([
            black if px == (rgb[0], rgb[1], rgb[2], 255) else white
            for px in pink_out.getdata()
        ])
        mask = image_tools.CreateMask(images)
        mask = image_tools.InflateMask(image_tools.CreateMask(images), 7)
        combined_mask = image_tools.AddMasks([mask, pink_out])
        self.UploadImage(GetExpectationPath(expectation, 'expected.png'),
                         images[0])
        self.UploadImage(GetExpectationPath(expectation, 'mask.png'),
                         combined_mask)