[IPython-dev] What is the best way to write unit test for Magics Classes?

Aquil H. Abdullah aquil.abdullah@gmail....
Sun Mar 31 21:39:48 CDT 2013


Hello All,

I am working on an application that uses IPython for a user interface.
Basically, I need to interact with the results of a long running process.
 I've decided to use the InteracteShellEmbed class along with a Magics
subclass to make things a little bit easier for the users.

I like to write unit tests as I develop my code, but it isn't quite clear
to me how to unit tests classes that inherit from Magics and are decorated
by line_magic or needs_local_scope.

For example, let's say I have the following code:

@magics_class
class AppMagics(Magics):
    """
    Application magics to do stuff
    """
    @needs_local_scope
    @line_magic
    def peek_a_boo(self, line, local_ns=None):
        """
        In [Peek 2]: x = 10

        In [Peek 3]: %peek_a_boo x
        Out[Peek 3]: 420
        """
        var = local_ns.get(line)
        cool_stuff = 42 * int(var)
        return col_stuff

In this instance I can use a a doc-test, however after reading the Dev:
Testing page on github ,
https://github.com/ipython/ipython/wiki/Dev%3A-Testing.  It looks like I'll
have to make some modifications which I don't quite understand.

Can anyone provide me with some resources for a newb to figure out how to
right unit tests for Magics?


-- 
Aquil H. Abdullah
aquil.abdullah@gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-dev/attachments/20130331/b828a1ce/attachment.html 


More information about the IPython-dev mailing list