Farm Development

Live doctest in TextMate (IPython + Twisted?)

I use TextMate for all python dev and I've had this idea to make typing doctests yield live results. In other words, when you are editing a module, if you were in a doctest you would type a line of code and the next line of your module would contain the result.

Just imagine typing and getting back...

This is how you use the class::

    >>> foo = Barbaz()
    >>> if foo.babulated:
    ...     foo.unbabulate()
    ... 
    'foo is now unbabulated'
    >>>

...I dunno about you, but I think that'd be slick!

The implementation is pretty simple with IPython :

from IPython.iplib import InteractiveShell
s = InteractiveShell('shell', user_global_ns=globals())
s.push('class foo(object):')
s.push('    pass')
s.push('')
s.push('foo')
# <class '__main__.foo'>

...huzzah. In TextMate, you can execute a script on the <return> key and the script would get $TM_CURRENT_LINE, full text of the line you're on. However, the current framework would execute the script once each time you pressed return so there is a problem with shared memory (no record of the previous lines you fed into it).

This is the part I'm still trying to figure out. I could fork another process and make some kind of interface (REST, pyro?) for feeding it new lines. The shared namespaces could be hashed per file, using $TM_FILENAME, and could simply use timeouts to do cleanup. It would need some security—maybe a block of all non-local IPs + some kind of permission check per user, but this is all I can think of. Anyone know of a better way? Anyone interested in this kind of thing? I am getting a heavy feeling that I need to learn Twisted! Can anyone point me in a good direction for how to do this in Twisted?

  • Re: Live doctest in TextMate (IPython + Twisted?)

    This is a great idea...I have no advice, just encouragement. Dozens of people using TextMate made me switch back from Emacs...at least for now. Auto-doctest completion would be a pretty damn cool thing.

  • Re: Live doctest in TextMate (IPython + Twisted?)

    Well, it sounds interesting, but it seems limited to regression testing since the code would need to pass each test before you write it. This seems like it would get annoying if you're trying to do test-driven development since your tests will fail when you first write them. Getting stack-traces in the output every time you write a test would get frustrating quickly.

  • Re: Live doctest in TextMate (IPython + Twisted?)

    damn, that's a really good point. hmm. I think I can only determine whether or not it's useful once I get it working. Even if it turns out to be useless, my current proof is a fun exploration of unix domain sockets!

Note: HTML tags will be stripped. Hit enter twice for a new paragraph.

Recent Projects

  • JSTestNet

    Like botnet but for JS tests in CI.

  • Nose Nicedots

    Nose plugin that prints nicer dots.

  • Fudge

    Mock objects for testing.

  • Fixture

    Loading and referencing test data.

  • NoseJS

    Nose plugin that runs JavaScript tests for a Python project.

  • Wikir

    converts reST to various Wiki formats.