def PerformComparison(self, test_run, expectation, actual): """Runs an image comparison, and uploads discrepancies to GS. Args: test_run: the name of the test_run. expectation: the name of the expectation to use for comparison. actual: an RGB-encoded PIL.Image that is the actual result. Raises: cloud_bucket.NotFoundError: if the given expectation is not found. ValueError: if the expectation name is invalid. """ if not IsValidExpectationName(expectation): raise ValueError("Expectation name contains an illegal character: %s." % str(_INVALID_EXPECTATION_CHARS)) expectation_tuple = self.GetExpectation(expectation) if not image_tools.SameImage( actual, expectation_tuple.expected, mask=expectation_tuple.mask): self.UploadImage( GetFailurePath(test_run, expectation, 'actual.png'), actual) diff, diff_pxls = image_tools.VisualizeImageDifferences( expectation_tuple.expected, actual, mask=expectation_tuple.mask) self.UploadImage(GetFailurePath(test_run, expectation, 'diff.png'), diff) self.cloud_bucket.UploadFile( GetFailurePath(test_run, expectation, 'info.txt'), json.dumps({ 'different_pixels': diff_pxls, 'fraction_different': diff_pxls / float(actual.size[0] * actual.size[1])}), 'application/json')
def RunTest(self, test_run, expectation, actual): """Runs an image comparison, and uploads discrepancies to GS. Args: test_run: the name of the test_run. expectation: the name of the expectation to use for comparison. actual: an RGB-encoded PIL.Image that is the actual result. Raises: cloud_bucket.NotFoundError: if the given expectation is not found. """ expectation_tuple = self.GetExpectation(expectation) if not image_tools.SameImage(actual, expectation_tuple.expected, mask=expectation_tuple.mask): self.UploadImage( GetFailurePath(test_run, expectation, 'actual.png'), actual) diff, diff_pxls = image_tools.VisualizeImageDifferences( expectation_tuple.expected, actual, mask=expectation_tuple.mask) self.UploadImage(GetFailurePath(test_run, expectation, 'diff.png'), diff) self.cloud_bucket.UploadFile( GetFailurePath(test_run, expectation, 'info.txt'), json.dumps({ 'different_pixels': diff_pxls, 'fraction_different': diff_pxls / float(actual.size[0] * actual.size[1]) }), 'application/json')
def testSameImage(self): self.assertTrue(image_tools.SameImage(self.white25, self.white25)) self.assertFalse(image_tools.SameImage(self.white25, self.black25)) self.assertTrue( image_tools.SameImage(self.white25, self.black25, mask=self.white25)) self.assertFalse( image_tools.SameImage(self.white25, self.black25, mask=self.black25)) self.assertTrue(image_tools.SameImage(self.black25, self.black25)) self.assertTrue( image_tools.SameImage(self.black25, self.black25, mask=self.white25)) self.assertTrue( image_tools.SameImage(self.white25, self.white25, mask=self.white25)) self.assertRaises(Exception, image_tools.SameImage, self.white25, self.white50) self.assertRaises(Exception, image_tools.SameImage, self.white25, self.white25, mask=self.white50)
def testSameImage(self): white25x25 = _GenImage((25, 25), (255, 255, 255)) black25x25 = _GenImage((25, 25), (0, 0, 0)) white50x50 = _GenImage((50, 50), (255, 255, 255)) self.assertTrue(image_tools.SameImage(white25x25, white25x25)) self.assertFalse(image_tools.SameImage(white25x25, black25x25)) self.assertTrue( image_tools.SameImage(white25x25, black25x25, mask=white25x25)) self.assertFalse( image_tools.SameImage(white25x25, black25x25, mask=black25x25)) self.assertTrue(image_tools.SameImage(black25x25, black25x25)) self.assertTrue( image_tools.SameImage(black25x25, black25x25, mask=white25x25)) self.assertTrue( image_tools.SameImage(white25x25, white25x25, mask=white25x25)) self.assertRaises(Exception, image_tools.SameImage, white25x25, white50x50) self.assertRaises(Exception, image_tools.SameImage, white25x25, white25x25, mask=white50x50)