Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test suite when reading image file #47

Closed
deeplook opened this issue Dec 27, 2016 · 12 comments
Closed

Fix test suite when reading image file #47

deeplook opened this issue Dec 27, 2016 · 12 comments

Comments

@deeplook
Copy link
Owner

deeplook commented Dec 27, 2016

Looks like after moving the test suite one level up some images for the W3C SVG tests cannot be found anymore. Same on Py2 and 3.

svglib $ py.test -v -s tests/test_samples.py
[...]
============================================================= FAILURES =============================================================
___________________________________________________ TestW3CSVG.test_convert_pdf ____________________________________________________

self = <test_samples.TestW3CSVG object at 0x108d41a10>

    def test_convert_pdf(self):
        "Test converting W3C SVG files to PDF using svglib."

        exclude_list = [
            "paint-stroke-06-t.svg",
            "coords-trans-09-t.svg",  # renderPDF issue (div by 0)
            # ExpatError while parsing due to the ev namespace
            "interact-order-04-t.svg",
            "interact-order-05-t.svg",
            "media-video-220-t.svg",
            "script-listener-201-t.svg",
            # Unsupported 'transform="ref(svg, ...)"' expression
            "coords-constr-201-t.svg",
            "coords-constr-202-t.svg",
            "coords-constr-203-t.svg",
            "coords-constr-204-t.svg",
            # Errors to be investigated
            "udom-event-207-t.svg",
        ]

        paths = glob.glob("%s/svg/*.svg" % self.folder_path)
        msg = "Destination folder '%s/svg' not found." % self.folder_path
        assert len(paths) > 0, msg

        for i, path in enumerate(paths):
            print("working on [%d] %s" % (i, path))

            if basename(path) in exclude_list:
                print("excluded (to be tested later)")
                continue

            # convert
            drawing = svglib.svg2rlg(path)

            # save as PDF
            base = splitext(path)[0] + '-svglib.pdf'
>           renderPDF.drawToFile(drawing, base, showBoundary=0)

tests/test_samples.py:428:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/Users/dinu/miniconda2/lib/python2.7/site-packages/reportlab/graphics/renderPDF.py:288: in drawToFile
    draw(d, c, 0, 0, showBoundary=showBoundary)
/Users/dinu/miniconda2/lib/python2.7/site-packages/reportlab/graphics/renderPDF.py:29: in draw
    R.draw(renderScaledDrawing(drawing), canvas, x, y, showBoundary=showBoundary)
/Users/dinu/miniconda2/lib/python2.7/site-packages/reportlab/graphics/renderbase.py:199: in draw
    self.drawNode(drawing)
/Users/dinu/miniconda2/lib/python2.7/site-packages/reportlab/graphics/renderPDF.py:55: in drawNode
    self.drawNodeDispatcher(node)
/Users/dinu/miniconda2/lib/python2.7/site-packages/reportlab/graphics/renderbase.py:280: in drawNodeDispatcher
    self.drawGroup(node)
/Users/dinu/miniconda2/lib/python2.7/site-packages/reportlab/graphics/renderbase.py:309: in drawGroup
    self.drawNode(node)
/Users/dinu/miniconda2/lib/python2.7/site-packages/reportlab/graphics/renderPDF.py:55: in drawNode
    self.drawNodeDispatcher(node)
/Users/dinu/miniconda2/lib/python2.7/site-packages/reportlab/graphics/renderbase.py:280: in drawNodeDispatcher
    self.drawGroup(node)
/Users/dinu/miniconda2/lib/python2.7/site-packages/reportlab/graphics/renderbase.py:309: in drawGroup
    self.drawNode(node)
/Users/dinu/miniconda2/lib/python2.7/site-packages/reportlab/graphics/renderPDF.py:55: in drawNode
    self.drawNodeDispatcher(node)
/Users/dinu/miniconda2/lib/python2.7/site-packages/reportlab/graphics/renderbase.py:280: in drawNodeDispatcher
    self.drawGroup(node)
/Users/dinu/miniconda2/lib/python2.7/site-packages/reportlab/graphics/renderbase.py:309: in drawGroup
    self.drawNode(node)
/Users/dinu/miniconda2/lib/python2.7/site-packages/reportlab/graphics/renderPDF.py:55: in drawNode
    self.drawNodeDispatcher(node)
/Users/dinu/miniconda2/lib/python2.7/site-packages/reportlab/graphics/renderbase.py:264: in drawNodeDispatcher
    self.drawImage(node)
/Users/dinu/miniconda2/lib/python2.7/site-packages/reportlab/graphics/renderPDF.py:87: in drawImage
    image.width, image.height
/Users/dinu/miniconda2/lib/python2.7/site-packages/reportlab/pdfgen/canvas.py:852: in drawInlineImage
    img_obj = PDFImage(image, x,y, width, height)
/Users/dinu/miniconda2/lib/python2.7/site-packages/reportlab/pdfgen/pdfimages.py:40: in __init__
    self.getImageData()
/Users/dinu/miniconda2/lib/python2.7/site-packages/reportlab/pdfgen/pdfimages.py:156: in getImageData
    imagedata, imgwidth, imgheight = self.non_jpg_imagedata(image)  #try for normal kind of image
/Users/dinu/miniconda2/lib/python2.7/site-packages/reportlab/pdfgen/pdfimages.py:138: in non_jpg_imagedata
    imagedata = pdfutils.cacheImageFile(image,returnInMemory=1)
/Users/dinu/miniconda2/lib/python2.7/site-packages/reportlab/pdfbase/pdfutils.py:95: in cacheImageFile
    code = makeA85Image(filename,IMG)
/Users/dinu/miniconda2/lib/python2.7/site-packages/reportlab/pdfbase/pdfutils.py:38: in makeA85Image
    raw = img.getRGBData()
/Users/dinu/miniconda2/lib/python2.7/site-packages/reportlab/lib/utils.py:883: in getRGBData
    annotateException('\nidentity=%s'%self.identity())
/Users/dinu/miniconda2/lib/python2.7/site-packages/reportlab/lib/utils.py:1387: in annotateException
    rl_reraise(t,v,b)
/Users/dinu/miniconda2/lib/python2.7/site-packages/reportlab/lib/utils.py:880: in getRGBData
    self._data = (im.tobytes if hasattr(im, 'tobytes') else im.tostring)()  #make pillow and PIL both happy, for now
/Users/dinu/miniconda2/lib/python2.7/site-packages/PIL/Image.py:678: in tobytes
    self.load()
/Users/dinu/miniconda2/lib/python2.7/site-packages/PIL/ImageFile.py:235: in load
    raise_ioerror(e)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

error = -2

    def raise_ioerror(error):
        try:
            message = Image.core.getcodecstatus(error)
        except AttributeError:
            message = ERRORS.get(error)
        if not message:
            message = "decoder error %d" % error
>       raise IOError(message + " when reading image file")
E       IOError: broken data stream when reading image file
E       identity=[ImageReader@0x1099eaad0 filename=u'/Users/dinu/repos/github/deeplook/svglib/tests/samples/W3C_SVG_12_TinyTestSuite/svg/../images/cloudqllo.jpg']

/Users/dinu/miniconda2/lib/python2.7/site-packages/PIL/ImageFile.py:59: IOError
========================================== 1 failed, 3 passed, 4 skipped in 40.64 seconds ==========================================
@claudep
Copy link
Collaborator

claudep commented Dec 28, 2016

I can't open that image (cloudqllo.jpg) in my image viewers (Gimp cannot open it either). So I'm rather surprised the test passed before! We might have to find a way to know if the image is valid before rendering.

@deeplook
Copy link
Owner Author

Same here, and this image is not even referenced explicitly in any of the SVG files in W3C_SVG_12_TinyTestSuite/svg. So maybe it's used in some kind of loop...

@claudep
Copy link
Collaborator

claudep commented Dec 28, 2016

I'm working on convertImage now, several things need updating.

claudep added a commit to claudep/svglib that referenced this issue Dec 28, 2016
claudep added a commit to claudep/svglib that referenced this issue Dec 28, 2016
@claudep
Copy link
Collaborator

claudep commented Dec 28, 2016

With the above commits, the tests run fine on Python 2, however on Python 3, I'm confronted with https://bitbucket.org/rptlab/reportlab/issues/98/

@deeplook
Copy link
Owner Author

deeplook commented Dec 28, 2016

Funny error. Especially since the reportlab.graphics.renderbase.Renderer class has neither a drawImage method nor a superclass...

@deeplook
Copy link
Owner Author

@claudep I suggest you send a message on the RL mailing list, which is what they observe more thoroughly than some issue tracker. And tell Robin this is kind of a late X-mas gift from me. ;-)

@claudep
Copy link
Collaborator

claudep commented Dec 28, 2016

I don't know if this is really a gift or not for RL, as I don't know the capabilities of their closed-source PLUS version.

@claudep
Copy link
Collaborator

claudep commented Jan 3, 2017

ReportLab 3.3.26 solves this issue. Now should we still add some workaround code with Python 3/ReportLab < 3.3.26, considering that such combinations might be used in the next two years at least? (next Debian will have 3.3.0, as has Ubuntu 16.04).

@claudep
Copy link
Collaborator

claudep commented Jan 3, 2017

However, I'm not sure we can do anything, as we cannot know whether the drawing we are building will be used to render an image or a PDF or anything else.

@deeplook
Copy link
Owner Author

deeplook commented Jan 3, 2017

Assuming reportlab 3.3.26 can be installed flawlessly, I'd opt for adding a note to the testsuite's README and the respective code line where the PNGs are created to use this with reportlab 3.3.36, rather than pin this version in the requirements, since I believe typical reportlab users are not jumping on new versions automatically. Does that make sense?

@claudep
Copy link
Collaborator

claudep commented Jan 3, 2017

+1 to not require this version and to a note in the README.
I don't think converting to PNG is a much used ability of svglib, considering ImageMagick does it too.

@deeplook
Copy link
Owner Author

deeplook commented Jan 4, 2017

Done in d122b5b.

@deeplook deeplook closed this as completed Jan 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants