Wednesday, September 30, 2009

Testing in Django and Python in gerenal

When I've been programming in Java I got used to write various tests. It's good to be able to play with the API you just wrote and tests save you a lot of time as programmed tests take less time than manual testing. Especially it's handy when you have some external service your app talks to and this service is not very fast, e.g. a response could take several minutes. So if you're testing stuff manually, it can take you several minutes, and the other approach to stub this service out and use this stub in tests to test the logic and stuff.

So, returning back to Java, I must admit that Java world has a plenty of great testing/mocking/etc frameworks. And the situation in the Python world really disheartens me. First of all, testing frameworks. Maybe I've missed something, but looks like the only used frameworks are doctest and unittest, both from standard library.

I don't get this doctest framework at all. Putting code in the comments to your code seems to be awkward to me. I don't think inline code documentation is a good place to place some examples, if your code requires examples, it's better to write up a tutorial and place all the examples here. So, it's not the way to go (IMHO).

The other framework is unittest -- a clone of some old JUnit with very limited feature set. Misses lots of vital features that could be found in TestNG for example. Specifically, I miss the following features:

* Test groups/dependencies. I want to make one test depend on other. It's clear that if some basic thing fails (e.g. user auth) it makes no sense at all to test all the stuff on top of that (e.g. actions for logged in user). And all these 'EEEEE' for lots of failed tests just make it harder the reason of error

* Lack of beforeSuite etc methods

... and many more, lazy to recall right now.

Testing in Django itself is also quite cumbersome. First of all, the concept of keeping tests in app/tests.py is not very flexible. This app-centric approach is probably good when your project consists only from Django, but I really doubt it's possible in real life: most likely you will have some kind of helpers, misc. classes that don't fit into apps and so on, and all of them require to be tested. What's the good place to place these tests? If you won't place them into tests.py of one of the apps, you will most likely have to implement your own test runner.

More examples:

* You cannot run an individual test using django test runner. Imagine you managed to write, say, 100 tests and it takes about 3 minutes to run all of them. Then you find that one of the tests failed. Instead of 'try to fix -> run failing test' iterations you will have 'try to fix -> run all the tests -> wait N minutes'.

* To plug some simple things, like code coverage reports, you have to override/implement own test runner.

Now it's time to get back to stubbing again. Django doesn't provide any easy way to replace real libs with the stubbed ones. The only good thing about it is that it's quite easy to get separate database instance for tests and automatically upload fixtures into it.

But I don't see a clean way to stub out an external lib, the trick with overriding sys.modules['modulename'] doesn't work if you do it in setUp, because the lib could be already improted, etc.

Tuesday, September 1, 2009

sendxmpp!!

sendxmpp tools is actually the worst and the most buggy program I've ever seen (considering its simplicity and size).

Sunday, August 2, 2009

Jet Lag

... gets me more serious than the last time. Fall asleep at 4pm yesterday and got up now at 2am. I don't think I will be able to sleep anymore this morning and looks like I'll be having hard times this evening trying to cope with sleep.

Friday, July 24, 2009

US Trip is almost over

My US trip is almost over - I fly back in the very early morning on Monday. Final accord would be driving to Hollywood for the weekend, then go back on the Sunday night, grab luggage and go to the airport. This trip was kinda fun and a lot of stuff happened so it wasn't boring by any means, and I feel tired and miss a lot of people I haven't seen for one month. So I look forward the Hollywood trip and getting back home then.

Thursday, July 16, 2009

paramiko vs scp

I had a task to benchmark a server by measuring how much time would it take to downloaded file via ftp. It was boring to script that up in shell since the server to be benchmarked didn't support key-based auth, so I'd had to pass password to ssh and I don't know a clean way to do it. Just for fun I decided to try doing it in Python using Paramiko module, which is a pure-python implementation of SSH protocol. I though it would be slower than native scp tool, but anyway I could use it to track the dynamics of performance changes.

Imagine my surprise when tests results showed that Paramiko performance is nearly equals to native 'scp' performance! I have to say it was a really pleasant surprise and makes Paramiko even more useful in my eyes.

Lenovo X61S

... is just CRAP!!! At least for a *nix user. First of all, it has some clit instead of a touchpad. I don't like the idea to place a clitoris in a middle of laptop's keyboard. OK, since almost all apps I use are command line and I also use stuff like vimperator for non-cli apps, I don't need to use mouse often. BUT BUT BUT. The keyboard is HORRIBLE! It's totally non standard and offset between rows are not usual as well because I always type stuff with offset of 1 symbol to the left or to the right. Moreover, the Escape key is placed in a very strange place, to the top of F1 key, so I often confuse esc with f1. It has function key as a very left button of bottom row, so I confuse it with control key. It has sleep key bound to fn + f4. So if I want to switch to 4th virtual desktop I risk to press fn-f4 instead of ctrl-f4 and suspend the laptop.

I don't know how much time will I need to get used to it and I see no point at all to make such a non traditional controls. I wish I just could throw it into the window...

Wednesday, July 8, 2009

Las Vegas pwnz!

I've been in Las Vegas last weekend. Well, what can I say, it's impressive!

I've attended only two shows: Blue Man Group show and KA Theatre. Both shows are really great. I'd probably visit them both again. Unfortunately, I was kinda short on money and time and haven't had a chance to try out more shows or try girls ;]

By the way, there are really lots of guys who offer girls on the Strip. They stay there any time, though there are less of them in the morning. But in the evening they stay in a row (literally) and there are LOTS of them. I wonder if that's effective, because they seem to give people all the same slides. I guess the efficiency would not change if their could would be reduced 5-10 times.

Anyway, I really liked Las Vegas. That's the first place in US where I'd agree to live. Probably it would get annoying after some time though.