def test_saveImage_multipage(tmpdir, script, imageType, expectedFilenames): glob_pattern = f"*.{imageType}" tmpdir = pathlib.Path(tmpdir) db = Drawing() namespace = makeDrawbotNamespace(db) runScriptSource(script, "<string>", namespace) assert [] == sorted(tmpdir.glob(glob_pattern)) outputPath = tmpdir / f"test.{imageType}" db.saveImage(outputPath) assert expectedFilenames == [p.name for p in sorted(tmpdir.glob(glob_pattern))]
def test_saveImage_multipage(tmpdir): tmpdir = pathlib.Path(tmpdir) db = Drawing() namespace = makeDrawbotNamespace(db) runScriptSource(multipageSource, "<string>", namespace) assert [] == sorted(tmpdir.glob("*.png")) outputPath = tmpdir / "test.png" db.saveImage(outputPath) expected_filenames = ['test_0.png', 'test_1.png', 'test_2.png'] assert expected_filenames == [p.name for p in sorted(tmpdir.glob("*.png"))]
def test_apitest(apiTestPath): db = Drawing() namespace = makeDrawbotNamespace(db) runScript(apiTestPath, namespace) if not apiTestsOutputDir.exists(): apiTestsOutputDir.mkdir() outputPath = apiTestsOutputDir / (apiTestPath.stem + ".png") expectedOutputPath = apiTestsExpectedOutputDir / (apiTestPath.stem + ".png") db.saveImage(outputPath) same, reason = compareImages(outputPath, expectedOutputPath) assert same, reason
def test_apitest(apiTestPath, imageType): apiTestPath = pathlib.Path(apiTestPath) db = Drawing() namespace = makeDrawbotNamespace(db) runScript(apiTestPath, namespace) if not apiTestsOutputDir.exists(): apiTestsOutputDir.mkdir() fileName = (apiTestPath.stem + f".{imageType}") outputPath = apiTestsOutputDir / fileName expectedOutputPath = apiTestsExpectedOutputDir / fileName db.saveImage(outputPath) if (apiTestPath.stem, imageType, sys.platform) in expectedFailures: # Skip late, so we can still inspect the output pytest.skip(f"Skipping expected failure {apiTestPath.stem}.{imageType}") same, reason = compareImages(outputPath, expectedOutputPath) assert same, f"{reason} {apiTestPath.name} {imageType}"
def test_newPage_newGState(): # Test a bug with the delegate properties of Drawing: they should # not return the delegate method itself, but a wrapper that calls the # delegate method, as the delegate object does not have a fixed # identity db = Drawing() fill = db.fill # Emulate a db namespace: all methods are retrieved once db.newPage(50, 50) with db.savedState(): fill(0.5) assert (255, 128, 128, 128) == db._gstate.fillPaint.color db.newPage(50, 50) fill(1) assert (255, 255, 255, 255) == db._gstate.fillPaint.color
def test_saveImage_mp4_codec(tmpdir): from drawbot_skia import ffmpeg ffmpeg.FFMPEG_PATH = ffmpeg.getPyFFmpegPath() # Force ffmpeg from pyffmpeg tmpdir = pathlib.Path(tmpdir) db = Drawing() namespace = makeDrawbotNamespace(db) runScriptSource(multipageSource, "<string>", namespace) assert [] == sorted(tmpdir.glob("*.png")) db.saveImage(tmpdir / "test.mp4") db.saveImage(tmpdir / "test2.mp4", codec="mpeg4") expectedFilenames = ['test.mp4', 'test2.mp4'] paths = sorted(tmpdir.glob("*.mp4")) assert paths[0].stat().st_size < paths[1].stat().st_size assert expectedFilenames == [p.name for p in paths]
def test_line_args(): db = Drawing() db.line([0, 0], [0, 100])
def test_polygon_args(): db = Drawing() db.polygon([0, 0], [0, 100], [100, 0])
def test_multipleDocuments(tmpdir): tmpdir = pathlib.Path(tmpdir) db = Drawing() db.newPage(100, 100) db.newPage(100, 100) db.saveImage(tmpdir / "test1.png") db.newDrawing() db.newPage(100, 100) db.newPage(100, 100) db.saveImage(tmpdir / "test2.png") fileNames = sorted(p.name for p in tmpdir.glob("*.png")) expectedFileNames = ["test1_0.png", "test1_1.png", "test2_0.png", "test2_1.png"] assert expectedFileNames == fileNames
def test_noFont(tmpdir): db = Drawing() # Ensure we don't get an error when font is not set db.text("Hallo", (0, 0))
def test_newPage_dimensions_arguments(): from drawbot_skia.drawing import DEFAULT_CANVAS_DIMENSIONS db = Drawing() db.rect(0, 0, 300, 300) # the dimensions are set only after drawing starts assert (db.width(), db.height()) == DEFAULT_CANVAS_DIMENSIONS db.newPage(600, 450) db.rect(0, 0, 300, 300) assert (db.width(), db.height()) == (600, 450) db.newPage() db.rect(0, 0, 300, 300) assert (db.width(), db.height()) == (600, 450) with pytest.raises(TypeError): db.newPage(10) with pytest.raises(TypeError): db.newPage(width=10) with pytest.raises(TypeError): db.newPage(height=10)