Skip to content

Commit

Permalink
parametrize image export test
Browse files Browse the repository at this point in the history
  • Loading branch information
justvanrossum committed Oct 3, 2020
1 parent d20f67a commit 8369371
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,29 @@ def test_apitest(apiTestPath):
"""


def test_saveImage_multipage(tmpdir):
test_data_saveImage = [
("png", ['test_0.png', 'test_1.png', 'test_2.png']),
("jpg", ['test_0.jpg', 'test_1.jpg', 'test_2.jpg']),
("svg", ['test_0.svg', 'test_1.svg', 'test_2.svg']),
("pdf", ['test.pdf']),
("mp4", ['test.mp4']),
]


@pytest.mark.parametrize("image_type, expected_filenames", test_data_saveImage)
def test_saveImage_multipage(tmpdir, image_type, expected_filenames):
glob_pattern = f"*.{image_type}"
tmpdir = pathlib.Path(tmpdir)
db = Drawing()
namespace = makeDrawbotNamespace(db)
runScriptSource(multipageSource, "<string>", namespace)
assert [] == sorted(tmpdir.glob("*.png"))
outputPath = tmpdir / "test.png"
assert [] == sorted(tmpdir.glob(glob_pattern))
outputPath = tmpdir / f"test.{image_type}"
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"))]
assert expected_filenames == [p.name for p in sorted(tmpdir.glob(glob_pattern))]


def test_saveImage_mp4(tmpdir):
def test_saveImage_mp4_codec(tmpdir):
from drawbot_skia import ffmpeg
ffmpeg.FFMPEG_PATH = ffmpeg.getPyFFmpegPath() # Force ffmpeg from pyffmpeg
tmpdir = pathlib.Path(tmpdir)
Expand All @@ -64,18 +74,6 @@ def test_saveImage_mp4(tmpdir):
assert expected_filenames == [p.name for p in paths]


def test_saveImage_pdf(tmpdir):
tmpdir = pathlib.Path(tmpdir)
db = Drawing()
namespace = makeDrawbotNamespace(db)
runScriptSource(multipageSource, "<string>", namespace)
assert [] == sorted(tmpdir.glob("*.pdf"))
db.saveImage(tmpdir / "test.pdf")
expected_filenames = ['test.pdf']
paths = sorted(tmpdir.glob("*.pdf"))
assert expected_filenames == [p.name for p in paths]


def test_noFont(tmpdir):
db = Drawing()
# Ensure we don't get an error when font is not set
Expand Down

0 comments on commit 8369371

Please sign in to comment.