11 Feb 2003 follower   » (Journeyer)

Work
Be happy for me, I have a job I enjoy... :-) (For at least the next month and a bit anyway.)

Development continues on the uncaught exceptions handler for Python, although mostly on the unit testing side which leads to:

  • A (possibly) interesting question: How do you unit test a replacement for the system exception handler? If you use the unittest module as it is, it always traps exceptions, so if you want to check whether your exception handler captures uncaught exceptions you can't, because they're not uncaught, 'cos unittest's exception handler captures them... Got it? :-) My answer was to run the tests outside the standard unittest framework and somehow link them into it. Which leads to...
  • External unit tests I'm probably reimplementing the wheel here but I now have a new ExternalUnitTestMixin class which allows the standard unittest framework to run an outside command and testing its output against the "correct" output (using os.popen4()). In my situation the command is simply running a Python script which tests that the exception handler prints the correct results. (e.g. nothing, an incident id or a traceback depending on the debug mode and where the exception occurred.) (Of course when you're capturing exceptions the line numbers can change if you're editing the code, my comparison checker optionally filters out line number references to avoid this issue.)

    The kinda nifty thing about this implementation is that the external unit tests are performed by running the same Python file that contains the "normal" unit tests as a script instead of importing it into the test runner. The external tests are all functions within the module which are extracted dynamically by a customised TestSuite class. I like it being done this way because it reduces the number of places you have to look for test code.

    Unfortunately I discovered that the unittest module's loadTestsFromModule() function doesn't automatically load TestSuites only TestCases, which leads us to...

  • Importing test suites I came up with a two line patch to loadTestsFromModule() to make it import TestSuite subclasses it finds in addition to TestCases. This means you can use "tricky" custom TestsSuites but they're imported automatically, and treated as just another TestCase. Admittedly this is all a somewhat vague description, but hopefully the code's clearer, and it'll be better when/if I can put up some example somewhere.

  • All of this is being controlled by our unit test runner which helpfully searches, loads and runs all our unit tests with just one command, which is handy, although not that original, hopefully I'll be able to put this up somewhere too.

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!