Skip to content

Commit cdbffad

Browse files
committed
Add tests
1 parent f5c04c2 commit cdbffad

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tests/testExport.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import glob
2+
import io
23
import os
34
import random
45
import sys
56
import unittest
67

78
import AppKit # type: ignore
89
import PIL
10+
from PIL import ImageCms
911
from testSupport import (
1012
DrawBotBaseTest,
1113
StdOutCollector,
@@ -444,6 +446,55 @@ def test_formattedStringURL_svg(self):
444446
readData(path), readData(expectedPath), "Files %r and %s are not the same" % (path, expectedPath)
445447
)
446448

449+
def test_export_color_space_cmyk(self):
450+
drawBot.newDrawing()
451+
drawBot.size(1000, 1000)
452+
drawBot.cmykFill(1, 0, 0, 0)
453+
drawBot.rect(0, 0, 250, 1000)
454+
drawBot.cmykFill(0, 1, 0, 0)
455+
drawBot.rect(250, 0, 250, 1000)
456+
drawBot.cmykFill(0, 0, 1, 0)
457+
drawBot.rect(500, 0, 250, 1000)
458+
drawBot.cmykFill(0, 0, 0, 1)
459+
drawBot.rect(750, 0, 250, 1000)
460+
461+
rgba_path = os.path.join(tempTestDataDir, "cmyk_export_default.tiff")
462+
cmyk_path = os.path.join(tempTestDataDir, "cmyk_export_with_color_space.tiff")
463+
cmyk_with_profile_path = os.path.join(tempTestDataDir, "cmyk_export_with_color_space_and_profile.tiff")
464+
465+
drawBot.saveImage(rgba_path)
466+
drawBot.saveImage(cmyk_path, colorSpace="CMYK")
467+
468+
icc_data = AppKit.NSData.dataWithContentsOfFile_("/System/Library/ColorSync/Profiles/Generic CMYK Profile.icc")
469+
drawBot.saveImage(cmyk_with_profile_path, colorSpace="CMYK", imageColorSyncProfileData=icc_data)
470+
471+
drawBot.endDrawing()
472+
473+
rgba_image = PIL.Image.open(rgba_path)
474+
self.assertEqual(rgba_image.mode, "RGBA")
475+
476+
rgba_image_profile = ImageCms.ImageCmsProfile(
477+
io.BytesIO(rgba_image.info.get("icc_profile"))
478+
)
479+
self.assertEqual(
480+
rgba_image_profile.profile.profile_description,
481+
"Generic RGB Profile"
482+
)
483+
484+
cmyk_image = PIL.Image.open(cmyk_path)
485+
self.assertEqual(cmyk_image.mode, "CMYK")
486+
self.assertIsNone(cmyk_image.info.get("icc_profile"))
487+
488+
cmyk_with_profile_image = PIL.Image.open(cmyk_with_profile_path)
489+
self.assertEqual(cmyk_with_profile_image.mode, "CMYK")
490+
cmyk_with_profile_image_profile = ImageCms.ImageCmsProfile(
491+
io.BytesIO(cmyk_with_profile_image.info.get("icc_profile"))
492+
)
493+
self.assertEqual(
494+
cmyk_with_profile_image_profile.profile.profile_description,
495+
"Generic CMYK Profile"
496+
)
497+
447498

448499
if __name__ == "__main__":
449500
import doctest

0 commit comments

Comments
 (0)