On Wed, Nov 2, 2011 at 5:43 PM, Wes McKinney <wesmck...@gmail.com> wrote:
> On Wed, Nov 2, 2011 at 5:20 PM, John Hunter <jdh2...@gmail.com> wrote:
>> On Wed, Nov 2, 2011 at 4:16 PM, Wes McKinney <wesmck...@gmail.com> wrote:
>>> Hi guys,
>>>
>>> Is there a common practice for unit testing code that creates
>>> matplotlib plots? I'm mainly just interested in code coverage versus
>>> correctness (making sure the code *works*) for now. I guess one way
>>> would be to disable the GUI backend so GUI elements don't get created
>>> (if the user is running the test suite from inside IPython in pylab
>>> mode, for example). Any tips or pointers to projects that do this
>>> would be very helpful.
>>
>> We have a unit testing framework for comparing images against baseline
>> images using PIL to compare "approximately close" at the rendering
>> level.  The code lives in matplotlib.testing and is triggered by
>> matplotlib.test.
>>
>> It might be heavyweight for what you want, so if all you want to do is
>> insure "it runs" just create some figures using the agg backend and
>> call savefig.  You can use the pyplot.switch_backends to switch
>> backends if you are concerned about a user calling it from ipython in
>> an interactive session.
>>
>> JDH
>>
>> JDH
>>
>
> Cool, I think then just using switch_backends is what I want-- switch
> to Agg in setUpClass and switch back to whatever backend was in use
> before in tearDownClass. Will report back with any problems.
>
> thanks,
> Wes
>

switch_backends appears to have no effect on OS X / mpl 1.0.1. Has
this been worked on in matplotlib 1.1.0? I can always just skip MPL
unit tests if the user if IPython is running and call mpl.use('Agg')
otherwise.

------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to