Wednesday, December 17, 2008

Adding unittest in python with TestSuite

Unittest is an important fundamental for solid software development. At the same time, maintaining proper unittests is also a burden. Managing good unittest is always a challenge.

One of the challenge in python comes when unittest.TestSuite is needed. Generally, each class will split out to each of unittest.TestCase class. But, to teach TestSuite what TestCase to load, we have to pass a list of TestCases, and writing a list manually like this isn't fun.

suite = unittest.TestSuite([
unittest.TestLoader().loadTestsFromTestCase(FirstTest),
unittest.TestLoader().loadTestsFromTestCase(SecondTest),
unittest.TestLoader().loadTestsFromTestCase(ThirdTest),
.....
])

It is error prone. More annoyingly, if I add a new test case, I have to modify suite, also. Using this driver will auto discover test classes in the current module.


moduleList = [ globals()[mod] for mod in globals().keys() if mod.endswith('Test') ]
suite = unittest.TestSuite([
unittest.TestLoader().loadTestsFromTestCase(i) for i in moduleList
])
unittest.TextTestRunner(verbosity=1).run(suite)


This uses naming convention of "SomethingTest" as a test case for class "Something".
Keeping this convention will be a keystroke save.

Friday, December 5, 2008

Tools for these days

I adapted two major changes in my tool set.

1. fish instead of zsh/bash
Most linux ships bash. I have used bash mostly. zsh was okay. But after I found fish, settled in fish. It is different but not difficult to migrate from bash. Nice color coding with good completion like zsh. Its script syntax resembles to tcl. I don't like tcl, but I could handle fish okay. Another unusual, but eventually more useful thing is the lack of history expansion. !! or !$ in bash does not exist in fish. Instead of them, fish simplifies all history recall with Up/Down and Alt-Up/Alt-Down. Action oriented :)
fish is very useful in many aspects. One useful thing is its history keeps not only history of the commands, but also keeps the timestamp when it ran.

2. screen instead of multiple xterm
Spreading xterms all around desktop looked sloppy. So, I tried to pack them into one screen session. At first, the environment was not familiar, but later I got used to it and navigated fine. So, mostly my dual screen is one emacs session plus one konsole with screen. These look more elegant than patching desktop with many xterms.

Tuesday, November 18, 2008

Best Python debugger

I don't use pdb often, but today, I needed one. I suspected that there should be a pdb module for emacs. Although GUD requires separate wrapper to PUD, there is a built-in module in Emacs. I just realized that GUD is a wrapper for another process instance. Not a big deal.
Create this file in somewhere PATHable and name it pdb.

#!/bin/sh
exec python2.6 /usr/lib/python2.6/pdb.py $1 $2 $3 $4 $5 $6 $7 $8 $9

And then, you are good to go. Someone mentioned that backtracing does not work across modules. I didn't test that because his/her post was dated long time ago with emacs 21.
With pdb, 'C-x +' (balance-windows) will be very useful.

Friday, November 14, 2008

Emacs pinky problem

I am not talking about L-CTRL sitting on a lower left corner. I already switched CAPS and L-CTRL. However, as Emacs still requires so many CTRL key strokes, my left pinky is getting tired. Now I am using R-CTRL and R-ALT. This works in my work desktop, but several problems await me.

1. Some machines don't understand R-ALT and R-CTRL.
2. Laptop and Desktop keyboard layout make me confused for these keys.

Intentionally, xmodmaps are turned off these days to remind myself to use Right side.

Friday, November 7, 2008

Nehalem architecture

Intel took a new approach to resolve the bandwidth problem, traditionally Intel suffered. If Intel Core 2 duo was focused on more efficient computation, this is major replacement of architecture design. As a programmer, we can just enjoy more clock cycles on less power consumption :)

Here is an article about a very nice overview.

Friday, October 3, 2008

Like a stone, Audioslave

This morning, I ran a random list in amarok, and this song was played. I purchased this song from Rhapsody several years ago. Once again, I felt touched when listening to this. Another song that I like is Cochise.
Not his song, but he is very special to my life. I loved rock music when I was young. I loved to play guitar. When I was early 20's, Korea was not ready for Rock. There were people who love rock music, but popularity came from dance music mostly. Also, the media didn't carry much of rocks. So, I was thirsty about rock culture. Only way to access was spending money on CD.
The fall of 1994, I came to US. Luckily, I happened to have a chance to watch M-TV. And I enjoyed ROCK music all night long. For the first time in my life in the first night in the US. I remember there were "interstate lovesong" from 'Stone Temple Pilots', something from 'REM', "When I come around" from 'Green day'. But most amazing songs were from Sound Garden. "Spoon man", "Fell on black days", and "Black hole Sun". I think I watched "Fell on black days" on that night and amazed. The vocalist of Sound Garden is the one in Audioslave...

Just a memory, 14 years ago...

Thursday, October 2, 2008

KDE4.1 on Fedora Core 9

It is pretty busy days. I can't find time for a technical post. But, I want to mention that I am happy with new KDE 4.1 update with FC9.
I generally don't follow updating my work desktop. Recently, I did it and required rebooting for kernel 2.6.23 update. After logging in, I found KDE is updated to 4.1. It had enhanced look, and I updated my nvidia card from livna, and OpenGL based theme worked. It looks much cooler.