Python Quibbles.

In PyUnit, self.assertRaises(TypeError, self.func(arg1, arg2)) fails as instead of passing a function object to test I’m passing the result of the function. It’s a little confusing as the function was raising the TypeError exception, and it appeared that PyUnit wasn’t doing it’s job.

Mostly, putting in the comma in the appropriate place fixes this: self.assertRaises(TypeError, self.func, (arg1, arg2)) but in one case I came across, for some reason the arguments weren’t getting passed properly and I had to flatten the argument list to: self.assertRaises(TypeError, self.func, arg1, arg); most unsatisfactory in terms of style I think.

The string.split() method takes a MAXSPLIT argument, the maximum number of times it will split the input string. I always think it’s the MAXSPLITS argument, that is, the maximum length of the tuple that will be returned. It’s annoying that I’ve stumbled over that off-by-one bug many times over the years, and will probably continue to do so.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: