TinyMail testing

TinyMail is a project I started a while ago. It was inspired by discussion around the Letters project: to build an open-source email client for MacOS, lighter and better and more flexible than Apple's Mail.app.

In the initial implementation, the backend code (tinymail.maildata) was warped and tangled, a real mess. So I rewrote all of it, this time with tests (thank you Mock!) and clean separation of responsibilities between classes. The async code is more readable because of Monocle – no more callback functions – and a simple IMAP worker that lives in its own thread.

Now it's time for the front-end code to be reorganized and, hopefully, unit tested. I still want to use Nose, and a lot of code needs to run on the main thread (because it talks to Cocoa UI classes). At some point it will surely need to do async stuff, and Nose will need to run on a different thread (so it can block while the main thread event loop keeps running), so I hacked together this slightly crazy Nose plugin that "teleports" every test on the main thread and runs it over there. So far, all the tests can happily run synchronously, but it's good to be able to inject a "sleep for 5 seconds" in the middle of a test, and manually interact with the UI.

Also of note: Monocle plays nicely with the Cocoa event loop. callAfter and callLater from PyObjCTools.AppHelper will schedule callables to run on the main thread and they will happily take a monocle Callback argument.