Skip to content

Attribute error when testing on system without ghostscript #3259

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

Closed
matthew-brett opened this issue Jul 14, 2014 · 16 comments
Closed

Attribute error when testing on system without ghostscript #3259

matthew-brett opened this issue Jul 14, 2014 · 16 comments
Milestone

Comments

@matthew-brett
Copy link
Contributor

This was the meat of issue #3152, but there were other failures attached to that ticket, so it got confusing. Reopening with the main issue here:

I'm getting a confusing test error when testing on OSX where ghostscript is not installed.

I am not sure what the right approach is, to avoiding this test when there is no 'gs' binary or equivalent - any advice from the experts?

https://api.travis-ci.org/jobs/28506496/log.txt?deansi=true

======================================================================
ERROR: matplotlib.tests.test_backend_ps.test_savefig_to_stringio_with_distiller
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/nose-1.3.3-py3.3.egg/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/matplotlib-1.4.x-py3.3-macosx-10.6-intel.egg/matplotlib/testing/decorators.py", line 110, in wrapped_function
    func(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/matplotlib-1.4.x-py3.3-macosx-10.6-intel.egg/matplotlib/tests/test_backend_ps.py", line 53, in test_savefig_to_stringio_with_distiller
    _test_savefig_to_stringio()
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/matplotlib-1.4.x-py3.3-macosx-10.6-intel.egg/matplotlib/tests/test_backend_ps.py", line 27, in _test_savefig_to_stringio
    plt.savefig(buffer, format=format)
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/matplotlib-1.4.x-py3.3-macosx-10.6-intel.egg/matplotlib/pyplot.py", line 571, in savefig
    res = fig.savefig(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/matplotlib-1.4.x-py3.3-macosx-10.6-intel.egg/matplotlib/figure.py", line 1470, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/matplotlib-1.4.x-py3.3-macosx-10.6-intel.egg/matplotlib/backend_bases.py", line 2192, in print_figure
    **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/matplotlib-1.4.x-py3.3-macosx-10.6-intel.egg/matplotlib/backends/backend_ps.py", line 985, in print_ps
    return self._print_ps(outfile, 'ps', *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/matplotlib-1.4.x-py3.3-macosx-10.6-intel.egg/matplotlib/backends/backend_ps.py", line 1016, in _print_ps
    **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/matplotlib-1.4.x-py3.3-macosx-10.6-intel.egg/matplotlib/backends/backend_ps.py", line 1218, in _print_figure
    gs_distill(tmpfile, isEPSF, ptype=papertype, bbox=bbox)
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/matplotlib-1.4.x-py3.3-macosx-10.6-intel.egg/matplotlib/backends/backend_ps.py", line 1520, in gs_distill
    if ps_backend_helper.supports_ps2write: # gs version >= 9
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/matplotlib-1.4.x-py3.3-macosx-10.6-intel.egg/matplotlib/backends/backend_ps.py", line 109, in supports_ps2write
    return self.gs_version[0] >= 9
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/matplotlib-1.4.x-py3.3-macosx-10.6-intel.egg/matplotlib/backends/backend_ps.py", line 99, in gs_version
    gs_version = tuple(map(int, ver.strip().split(".")))
ValueError: invalid literal for int() with base 10: ''

The error arises because ver in the code above is the empty string, and this is so because Popen execute of gs --version returns the empty string when there there is no gs binary (around line 93 of lib/matplotlib/backends/backend_ps.py). I guess this Popen call should raise an error (check of returncode), but I guess we also need to make sure this version check doesn't get called when gs is not present, and I'm not sure of the cleanest way to achieve that.

@tacaswell tacaswell added this to the v1.4.0 milestone Jul 14, 2014
@tacaswell
Copy link
Member

@matthew-brett Sorry for the confusion.

@matthew-brett
Copy link
Contributor Author

No problem, sorry for mixing issues ...

@tacaswell
Copy link
Member

What do you get if you try to import the modules with the AttributeError from a prompt? Those look like nose is snarfing errors during import.

@tacaswell
Copy link
Member

@matthew-brett I am confused, are those AttributeErrors the same as from the other thread (which were addressed by fixing mock) or are they new?

@jenshnielsen
Copy link
Member

I think that the real bug is that that code even runs if gs is not installed. The code in checkdep_ghostscript in init.py should not have this issue since it correctly checks the return code. I have been touching some of this code in #3235 to silence some warnings.

Perhaps the backend tests need to be wrapped with checkdep_ghostscript == true and it looks like this method is redundant anyway since checkdep_ghostscript returns the version anyway.

@matthew-brett
Copy link
Contributor Author

Sorry Thomas - I am fool and I left some of the previous errors at the top of the issue. I was rushing with the bad internet here. I removed them, sorry to keep confusing...

@tacaswell
Copy link
Member

@matthew-brett No worries!

@matthew-brett
Copy link
Contributor Author

Error on current v1.4.x is now:

======================================================================
ERROR: matplotlib.tests.test_backend_ps.test_savefig_to_stringio_with_distiller
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/testing/decorators.py", line 110, in wrapped_function
    func(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/tests/test_backend_ps.py", line 55, in test_savefig_to_stringio_with_distiller
    _test_savefig_to_stringio()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/tests/test_backend_ps.py", line 27, in _test_savefig_to_stringio
    plt.savefig(buffer, format=format)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/pyplot.py", line 576, in savefig
    res = fig.savefig(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/figure.py", line 1470, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 2192, in print_figure
    **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_ps.py", line 989, in print_ps
    return self._print_ps(outfile, 'ps', *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_ps.py", line 1020, in _print_ps
    **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_ps.py", line 1222, in _print_figure
    gs_distill(tmpfile, isEPSF, ptype=papertype, bbox=bbox)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_ps.py", line 1539, in gs_distill
    your image.\nHere is the full report generated by ghostscript:\n\n' + fh.read())
RuntimeError: ghostscript was not able to process     your image.
Here is the full report generated by ghostscript:


https://s3.amazonaws.com/archive.travis-ci.org/jobs/30794968/log.txt

@jenshnielsen
Copy link
Member

I guess that the test should be wrapped with something like the test_savefig_to_stringio_with_usetex test does for tex.

if not matplotlib.checkdep_ghostscript():
        raise SkipTest("This test requires a GS installation")

@jenshnielsen
Copy link
Member

I think that #3302 should resolve this issue.

@jenshnielsen
Copy link
Member

But gs_distill and xpdf_distill in backend_ps should still probably check that gs / pstopdf are available and fail with some more usefull error messages if not. I also don't think that gs_exe should just return gs if gs is not found.

@tacaswell
Copy link
Member

@matthew-brett Closing this, can you confirm it is really fixed?

@matthew-brett
Copy link
Contributor Author

It isn't fixed, same error as previously, testing on current 1.4.x branch...

https://s3.amazonaws.com/archive.travis-ci.org/jobs/30794968/log.txt

I think the ghostscript dependency check was subtly wrong - suggest : #3312

@tacaswell tacaswell reopened this Jul 27, 2014
@matthew-brett
Copy link
Contributor Author

With PR 3312, and switching to single-thread tests (#3314) and increasing the ulimit for Python 3.3 (#3315) - the matplotlib OSX grid is finally all green on v1.4.x:

https://travis-ci.org/matthew-brett/mpl_mac_testing/builds/30950971

@tacaswell
Copy link
Member

@matthew-brett Are there any further changes to mpl needed to close this or are all the remaining changes in the mac testing grid?

@matthew-brett
Copy link
Contributor Author

​No more changes needed thanks - please do close.

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

3 participants