Fixing pip and easy_install, and getting colorful output from unittest

I’ve noticed in a lot of talks/ videos that people in the Ruby universe that work with tools like RSpec for writing unit tests/ doing TDD often have a nice colorful output. Aesthetics aside, I like the idea of the visual feedback – with red indicating your errors or failures and green or blue indicating your passing tests. It makes it much easier to use the sense of color to get feedback instead of having to actually carefully read the text scrolling on the terminal. There has to be a reason, after all, why TDD often has the moniker red-green-refactor. Searching on this matter, I rather quickly came across pyrg, which seems like an excelled tool.

However, since I kind of overwrote my existing Python installation (OS X 10.6) with the version from Macports, my easy_install and pip were still pointing toward one of my older Python installations. Ergo, pyrg wouldn’t run. After researching for a while I came across this excellent post on Stack Overflow, and followed the instructions to uninstall my easy_install and then reinstall using the distribute package mentioned on there, followed by reinstalling pip.

This by itself didn’t do anything, and I had to make sure in my shell’s rc file that the Macport version of Python was in the path before other, regular places like /usr/local/bin, etc. That fixed it. Run with $ pyrg python_file or $ python python_file |& pyrg. Colors can be easily customized as well. Hooray for going from the colorless test run output on the left to a proper visual feedback on the right!

Colorful

Colorful with pyrg

Colorless

Colorless without pyrg

Using NUnit and C# with Mono and MonoDevelop on OS X

This is a quick post highlighting how to use NUnit for unit testing your C# code on a Mac. Of course, we know C# code can be run on a Mac OS X environment, using Mono and MonoDevelop, and so my intuition was that I should be able to somehow use NUnit on it as well, perhaps with something as simple as

$ mono nunit-console.exe dll_file.dll

or something like that. I downloaded the latest version of the NUnit binaries and tried compiling and running my test code with

$ mcs file_a.cs file_a_test.cs -reference:/path/to/nunit.framework.dll

$ mono /path/to/nunit-console.exe file_a.exe

Of course it didn’t work. I don’t know why and I don’t know how I found it, but after tinkering around with it for a bit I discovered that when I had installed Mono on my Mac a long time ago, it had already installed NUnit on it. NUnit was pre-packaged with Mono and MonoDevelop! All I had to do then to successfully run what I wanted to run was:

$ mcs file_a.cs file_a_test.cs -reference:nunit.framework.dll

$ NUNIT-CONSOLE file_a.exe

Notice how I didn’t need the path anymore, and how NUNIT-CONSOLE is a symbolic link to nunit-console.exe that came with Mono.

Got rid of the freshly unzipped (and now superfluous) NUnit.