alan

twisted

I had some hard time when testing Twisted protocols. Although they should be decoupled from factories, most examples I could find, including those from the official doc, were just too noisy and suggested using a factory.

I don't like that approach – I should not be forced to use a factory – that creates an unnecessary coupling – let's just pretend a factory existed and creates a connections, that's all our protocol should need.

Of course sometimes a protocol is bound to a very specific factory since it needs to invoke methods on it for non protocol-specific data (remember, there's just one factory, while there's one protocol per connection). I don't like that behaviour, since it creates an unnecessary coupling and makes factories huge and not cohesive, and I think protocols should just be injected whatever peers they need during the buildProtocol() invocation – but I'll talk about that in another post. In the meantime, I reccommend just creating a mock factory and setting it manually on the protocol.

So, here it is the solution I baked:



What do you think about this solution?

#Ollivander #python #twisted #testing

I've found a good way to launch tests using Twisted Trial in a zc.buildout enabled project. I was in fear of needing a full-fledged recipe – which I didn't have the time nor the will to code.

Luckily, zc.recipe.egg seems good enough to satisfy my needs; I wanted a recipe that could launch all unit tests if no parameter was passed, while retaining the ability to choose which specific unit test was launched on command line.


Here it is:



That's filled in for pydenji

#Ollivander #python #twisted #ZcBuildout