tests/test_pdfgen_general.py
changeset 3447 70d7f0450df0
parent 3326 ce725978d11c
child 3456 3143bbebbefe
--- a/tests/test_pdfgen_general.py	Fri Sep 17 13:40:59 2010 +0000
+++ b/tests/test_pdfgen_general.py	Fri Sep 17 13:41:44 2010 +0000
@@ -990,6 +990,47 @@
         canv.showPage()
         canv.save()
 
+    def test4(self):
+        sc = colors.CMYKColorSep
+        rgb = ['red','green','blue', 'black']
+        cmykb = [(0,0,0,1)]
+        cmyk = [(1,0,0,0),(0,1,0,0),(0,0,1,0)]+cmykb
+        seps = [sc(1,1,0,0,spotName='sep0'),sc(0,1,1,0,spotName='sep1')]
+        sepb = [sc(0,0,0,1,spotName='sepb')]
+        #these should all work
+        trySomeColors(rgb+cmyk+seps)
+        trySomeColors(rgb,'rgb')
+        trySomeColors(cmyk,'cmyk')
+        trySomeColors(seps+cmyk,'sep_cmyk')
+        trySomeColors(seps+sepb,'sep')  #we need a fake black for now
+        trySomeColors(seps+['black']+cmykb,'sep_black')
+        self.assertRaises(ValueError,trySomeColors,rgb+cmyk+seps,'rgb')
+        self.assertRaises(ValueError,trySomeColors,rgb+cmyk,'rgb')
+        self.assertRaises(ValueError,trySomeColors,rgb+seps,'rgb')
+        trySomeColors(rgb+sepb,'rgb')   #should work because blacks are convertible 
+        trySomeColors(rgb+cmykb,'rgb')
+        self.assertRaises(ValueError,trySomeColors,cmyk+rgb+seps,'cmyk')
+        trySomeColors(cmyk+['black']+seps,'cmyk')   #OK because black & seps are convertible
+        
+
+def trySomeColors(C,enforceColorSpace=None):
+    from StringIO import StringIO
+    out=StringIO()
+    canv = canvas.Canvas(out,enforceColorSpace=enforceColorSpace)
+    canv.setFont('Helvetica',10)
+    x = 0
+    y = 0
+    w,h = canv._pagesize
+    for c in C:
+        if y+10>h:
+            y = 0
+            x += 10
+        canv.setFillColor(c)
+        canv.rect(x,y,10,10,fill=1,stroke=0)
+        y += 10
+    canv.showPage()
+    canv.save()
+
 def makeSuite():
     return makeSuiteForClasses(PdfgenTestCase)