コード例 #1
0
 def assertImagesSimilar(self, path1, path2):
     similarity = compareImages(path1, path2)
     # XXX 0.013 is a rather high value. We only have one test currently that uses this:
     # "test_imageObject", and that shows a rather high difference on Python 2 (although it's not visible)
     self.assertLessEqual(
         similarity, 0.013, "Images %r and %s are not similar enough: %s" %
         (path1, path2, similarity))
コード例 #2
0
ファイル: testScripts.py プロジェクト: thedemodev/drawbot
 def assertPDFFilesEqual(self, path1, path2):
     # read as pdf document
     pdf1 = AppKit.PDFDocument.alloc().initWithURL_(
         AppKit.NSURL.fileURLWithPath_(path1))
     pdf2 = AppKit.PDFDocument.alloc().initWithURL_(
         AppKit.NSURL.fileURLWithPath_(path2))
     self.assertIsNotNone(pdf1, "PDF could not be read from %r" % path1)
     self.assertIsNotNone(pdf2, "PDF could not be read from %r" % path2)
     self.assertTrue(pdf1.pageCount() == pdf2.pageCount(),
                     "PDFs has not the same amount of pages")
     # loop over all pages
     for pageIndex in range(pdf1.pageCount()):
         # get the pages
         page1 = pdf1.pageAtIndex_(pageIndex)
         page2 = pdf2.pageAtIndex_(pageIndex)
         # create images from the page data
         image1 = AppKit.NSImage.alloc().initWithData_(
             page1.dataRepresentation())
         image2 = AppKit.NSImage.alloc().initWithData_(
             page2.dataRepresentation())
         # compare the image tiff data
         # no use to show the complete diff of the binary data
         data1 = image1.TIFFRepresentation()
         data2 = image2.TIFFRepresentation()
         if data1 == data2:
             return  # all fine
         # Fall back to fuzzy image compare
         f1 = io.BytesIO(data1)
         f2 = io.BytesIO(data2)
         similarity = compareImages(f1, f2)
         self.assertLessEqual(
             similarity, 0.0011,
             "PDF files %r and %r are not similar enough: %s (page %s)" %
             (path1, path2, similarity, pageIndex + 1))
コード例 #3
0
ファイル: testScripts.py プロジェクト: wzl284486628/drawbot
 def assertImageFilesEqual(self, path1, path2):
     data1 = readData(path1)
     data2 = readData(path2)
     if data1 == data2:
         return  # all fine
     # Fall back to fuzzy image compare
     f1 = io.BytesIO(data1)
     f2 = io.BytesIO(data2)
     similarity = compareImages(f1, f2)
     self.assertLessEqual(similarity, 0.0011, "Images %r and %r are not similar enough: %s" % (path1, path2, similarity))
コード例 #4
0
ファイル: testExamples.py プロジェクト: typemytype/drawbot
 def assertImagesSimilar(self, path1, path2):
     similarity = compareImages(path1, path2)
     # XXX 0.013 is a rather high value. We only have one test currently that uses this:
     # "test_imageObject", and that shows a rather high difference on Python 2 (although it's not visible)
     self.assertLessEqual(similarity, 0.013, "Images %r and %s are not similar enough: %s" % (path1, path2, similarity))
コード例 #5
0
 def assertImagesSimilar(self, path1, path2):
     similarity = compareImages(path1, path2)
     self.assertLessEqual(
         similarity, 0.0012, "Images %r and %s are not similar enough: %s" %
         (path1, path2, similarity))
コード例 #6
0
tests = [
    os.path.join(root, filename) for filename in os.listdir(root)
    if os.path.splitext(filename)[-1].lower() == ".png"
]

drawBot.newDrawing()
for path in tests:
    fileName = os.path.basename(path)
    if not fileName.startswith("example_"):
        fileName = "expected_" + fileName

    localPath = os.path.join(testDataDir, fileName)
    if not os.path.exists(localPath):
        continue
    w, h = drawBot.imageSize(path)
    a = compareImages(localPath, path)
    padding = 0
    if a > 0.0012:
        padding = 50
    pathPadding = 30
    drawBot.newPage(w * 4 + padding * 2, h + padding * 2 + pathPadding)
    drawBot.translate(0, pathPadding)
    if padding:
        with drawBot.savedState():
            drawBot.fill(None)
            drawBot.stroke(1, 0, 0)
            drawBot.strokeWidth(padding * 2)
            drawBot.rect(0, 0, drawBot.width(), drawBot.height())
        drawBot.translate(padding, padding)

    drawBot.text(f"{os.path.basename(path)} - {os.path.basename(localPath)}",