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.
Leave a Reply