def test_linkURL_svg(self): expectedPath = os.path.join(testDataDir, "expected_svgLinkURL.svg") drawBot.newDrawing() drawBot.newPage(200, 200) drawBot.rect(10, 10, 20, 20) drawBot.linkURL("http://drawbot.com", (10, 10, 20, 20)) with TempFile(suffix=".svg") as tmp: drawBot.saveImage(tmp.path) self.assertEqual(readData(tmp.path), readData(expectedPath), "Files %r and %s are not the same" % (tmp.path, expectedPath))
def test_formattedStringURL_svg(self): expectedPath = os.path.join(testDataDir, "expected_formattedStringURL.svg") drawBot.newDrawing() drawBot.newPage(200, 200) drawBot.underline("single") drawBot.url("http://drawbot.com") drawBot.text("foo", (10, 10)) with TempFile(suffix=".svg") as tmp: drawBot.saveImage(tmp.path) self.assertEqual(readData(tmp.path), readData(expectedPath), "Files %r and %s are not the same" % (tmp.path, expectedPath))
def test_export_svg_fallbackFont(self): expectedPath = os.path.join(testDataDir, "expected_svgSaveFallback.svg") drawBot.newDrawing() drawBot.newPage(100, 100) drawBot.fallbackFont("Courier") drawBot.font("Times") drawBot.text("a", (10, 10)) with TempFile(suffix=".svg") as tmp: drawBot.saveImage(tmp.path) self.assertEqual(readData(tmp.path), readData(expectedPath), "Files %r and %s are not the same" % (tmp.path, expectedPath))
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))
def test_export_SVG_mixin(self): expectedPath = os.path.join(testDataDir, "expected_svgMixin.svg") drawBot.newDrawing() drawBot.newPage(100, 100) path = drawBot.BezierPath() path.svgID = "hello" path.svgClass = "foo bar" path.svgLink = "drawbot.com" path.rect(0, 0, 20, 20) drawBot.drawPath(path) txt = drawBot.FormattedString() txt += "world" txt.svgID = "hello" txt.svgClass = "foo bar" txt.svgLink = "drawbot.com" drawBot.text(txt, (20, 20)) with TempFile(suffix=".svg") as tmp: drawBot.saveImage(tmp.path) self.assertEqual( readData(tmp.path), readData(expectedPath), "Files %r and %s are not the same" % (tmp.path, expectedPath))
def assertFilesEqual(self, path1, path2): self.assertEqual(readData(path1), readData(path2), "Files %r and %s are not the same" % (path1, path2))
def assertGenericFilesEqual(self, path1, path2): self.assertEqual(readData(path1), readData(path2))
def assertSVGFilesEqual(self, path1, path2): # compare the content by line self.assertTrue( readData(path1) == readData(path2), "SVG files %r and %r are not identical" % (path1, path2))
def assertImageFilesEqual(self, path1, path2): # compare the data and assert with a simple message # no use to show the complete diff of the binary file self.assertTrue( readData(path1) == readData(path2), "Images are not the same")
def assertSVGFilesEqual(self, path1, path2): # compare the content by line self.assertTrue(readData(path1) == readData(path2))
def assertImageFilesEqual(self, path1, path2): # compare the data and assert with a simple message # no use to show the complete diff of the binary file self.assertTrue(readData(path1) == readData(path2), "Images are not the same")