def testPNGEncodeDecode(self):
     self.assertTrue(
         _AllPixelsOfColor(
             image_tools.DecodePNG(image_tools.EncodePNG(self.white25)),
             (255, 255, 255, 255)))
     self.assertTrue(
         _AllPixelsOfColor(
             image_tools.DecodePNG(image_tools.EncodePNG(self.black25)),
             (0, 0, 0, 255)))
 def testUpdateImage(self):
   self.bucket.Reset()
   # Upload some images to the datastore.
   self.ispy_utils.UploadImage('path/to/image.png', self.white)
   self.assertEquals(self.bucket.datastore['path/to/image.png'],
                     image_tools.EncodePNG(self.white))
   self.ispy_utils.UpdateImage('path/to/image.png', self.black)
   # Confirm that the image actually got updated.
   self.assertEquals(self.bucket.datastore['path/to/image.png'],
                     image_tools.EncodePNG(self.black))
Exemple #3
0
  def UpdateImage(self, full_path, image):
    """Updates an existing image in GS, preserving permissions and metadata.

    Args:
      full_path: the path to the file in GS including the file extension.
      image: a RGB PIL.Image.
    """
    self.cloud_bucket.UpdateFile(full_path, image_tools.EncodePNG(image))
 def testUploadExpectation(self):
   self.bucket.Reset()
   # Upload some tests to the datastore.
   self.ispy_utils.UploadExpectation('test', [self.white, self.black])
   self.ispy_utils.UploadExpectation('test1', [self.black, self.black])
   # Confirm that the tests were successfully uploaded.
   self.assertEquals(self.bucket.datastore[
       ispy_utils.GetExpectationPath('test', 'expected.png')],
       image_tools.EncodePNG(self.white))
   self.assertEquals(self.bucket.datastore[
       ispy_utils.GetExpectationPath('test', 'mask.png')],
       image_tools.EncodePNG(self.white))
   self.assertEquals(self.bucket.datastore[
       ispy_utils.GetExpectationPath('test1', 'expected.png')],
       image_tools.EncodePNG(self.black))
   self.assertEquals(self.bucket.datastore[
       ispy_utils.GetExpectationPath('test1', 'mask.png')],
       image_tools.EncodePNG(self.black))
Exemple #5
0
  def UploadImage(self, full_path, image):
    """Uploads an image to a location in GS.

    Args:
      full_path: the path to the file in GS including the file extension.
      image: a RGB PIL.Image to be uploaded.
    """
    self.cloud_bucket.UploadFile(
        full_path, image_tools.EncodePNG(image), 'image/png')
 def testRunTest(self):
   self.bucket.Reset()
   self.ispy_utils.UploadExpectation('test1', [self.red, self.red])
   self.ispy_utils.RunTest('test', 'test1', self.black)
   self.assertEquals(self.bucket.datastore[
       ispy_utils.GetFailurePath('test', 'test1', 'actual.png')],
       image_tools.EncodePNG(self.black))
   self.ispy_utils.RunTest('test', 'test1', self.red)
   self.assertTrue(self.bucket.datastore.has_key(
           ispy_utils.GetFailurePath('test', 'test1', 'actual.png')))
Exemple #7
0
 def testPerformComparison(self):
   self.bucket.Reset()
   self.ispy_utils.GenerateExpectation('test1', [self.red, self.red])
   self.ispy_utils.PerformComparison('test', 'test1', self.black)
   self.assertEquals(self.bucket.datastore[
       ispy_utils.GetFailurePath('test', 'test1', 'actual.png')],
       image_tools.EncodePNG(self.black))
   self.ispy_utils.PerformComparison('test', 'test1', self.red)
   self.assertTrue(self.bucket.datastore.has_key(
           ispy_utils.GetFailurePath('test', 'test1', 'actual.png')))
 def testGetExpectation(self):
   self.bucket.Reset()
   # Upload some tests to the datastore
   self.ispy_utils.UploadExpectation('test1', [self.white, self.black])
   self.ispy_utils.UploadExpectation('test2', [self.red, self.white])
   test1 = self.ispy_utils.GetExpectation('test1')
   test2 = self.ispy_utils.GetExpectation('test2')
   # Check that GetExpectation gets the appropriate tests.
   self.assertEquals(image_tools.EncodePNG(test1.expected),
                     image_tools.EncodePNG(self.white))
   self.assertEquals(image_tools.EncodePNG(test1.mask),
                     image_tools.EncodePNG(self.white))
   self.assertEquals(image_tools.EncodePNG(test2.expected),
                     image_tools.EncodePNG(self.red))
   self.assertEquals(image_tools.EncodePNG(test2.mask),
                     image_tools.EncodePNG(self.white))
   # Check that GetExpectation throws an error for a nonexistant test.
   self.assertRaises(
       cloud_bucket.FileNotFoundError, self.ispy_utils.GetExpectation, 'test3')
 def testGetFailure(self):
   self.bucket.Reset()
   # Upload a result
   self.ispy_utils.UploadExpectation('test1', [self.red, self.red])
   self.ispy_utils.RunTest('test', 'test1', self.black)
   res = self.ispy_utils.GetFailure('test', 'test1')
   # Check that the function correctly got the result.
   self.assertEquals(image_tools.EncodePNG(res.expected),
                     image_tools.EncodePNG(self.red))
   self.assertEquals(image_tools.EncodePNG(res.diff),
                     image_tools.EncodePNG(self.masked))
   self.assertEquals(image_tools.EncodePNG(res.actual),
                     image_tools.EncodePNG(self.black))
   # Check that the function raises an error when given non-existant results.
   self.assertRaises(cloud_bucket.FileNotFoundError,
                     self.ispy_utils.GetFailure, 'test', 'test2')
 def testDownloadImage(self):
     self.bucket.Reset()
     # Upload some images to the datastore.
     self.ispy_utils.UploadImage('path/to/white.png', self.white)
     self.ispy_utils.UploadImage('path/to/black.png', self.black)
     self.ispy_utils.UploadImage('path/to/red.png', self.red)
     # Check that the DownloadImage function gets the correct images.
     self.assertEquals(
         image_tools.EncodePNG(
             self.ispy_utils.DownloadImage('path/to/white.png')),
         image_tools.EncodePNG(self.white))
     self.assertEquals(
         image_tools.EncodePNG(
             self.ispy_utils.DownloadImage('path/to/black.png')),
         image_tools.EncodePNG(self.black))
     self.assertEquals(
         image_tools.EncodePNG(
             self.ispy_utils.DownloadImage('path/to/red.png')),
         image_tools.EncodePNG(self.red))
     # Check that the DownloadImage function throws an error for a
     #  nonexistant image.
     self.assertRaises(cloud_bucket.FileNotFoundError,
                       self.ispy_utils.DownloadImage, 'path/to/yellow.png')