Ejemplo n.º 1
0
 def testCreateMask(self):
   m1 = image_tools.CreateMask([self.black25, self.white25])
   self.assertTrue(_AllPixelsOfColor(m1, (255, 255, 255, 255)))
   m2 = image_tools.CreateMask([self.black25, self.black25])
   self.assertTrue(_AllPixelsOfColor(m2, (0, 0, 0, 255)))
   m3 = image_tools.CreateMask([self.white25, self.white25])
   self.assertTrue(_AllPixelsOfColor(m3, (0, 0, 0, 255)))
Ejemplo n.º 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)
Ejemplo n.º 3
0
    def testCreateMask(self):
        black25x25 = _GenImage((25, 25), (0, 0, 0))
        white25x25 = _GenImage((25, 25), (255, 255, 255))

        m1 = image_tools.CreateMask([black25x25, white25x25])
        self.assertTrue(_AllPixelsOfColor(m1, (255, 255, 255)))
        m2 = image_tools.CreateMask([black25x25, black25x25])
        self.assertTrue(_AllPixelsOfColor(m2, (0, 0, 0)))
        m3 = image_tools.CreateMask([white25x25, white25x25])
        self.assertTrue(_AllPixelsOfColor(m3, (0, 0, 0)))
Ejemplo n.º 4
0
 def testAddMasks(self):
   m1 = image_tools.CreateMask([self.black25, self.white25])
   m2 = image_tools.CreateMask([self.black25, self.black25])
   m3 = image_tools.CreateMask([self.black50, self.black50])
   self.assertTrue(_AllPixelsOfColor(image_tools.AddMasks([m1]),
                                     (255, 255, 255, 255)))
   self.assertTrue(_AllPixelsOfColor(image_tools.AddMasks([m2]),
                                     (0, 0, 0, 255)))
   self.assertTrue(_AllPixelsOfColor(image_tools.AddMasks([m1, m2]),
                                     (255, 255, 255, 255)))
   self.assertTrue(_AllPixelsOfColor(image_tools.AddMasks([m1, m1]),
                                     (255, 255, 255, 255)))
   self.assertTrue(_AllPixelsOfColor(image_tools.AddMasks([m2, m2]),
                                     (0, 0, 0, 255)))
   self.assertTrue(_AllPixelsOfColor(image_tools.AddMasks([m3]),
                                     (0, 0, 0, 255)))
   self.assertRaises(Exception, image_tools.AddMasks, [])
   self.assertRaises(Exception, image_tools.AddMasks, [m1, m3])
Ejemplo n.º 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)
Ejemplo n.º 6
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)
Ejemplo n.º 7
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)