[MERGE] fixes for selftest on win32 (part 2)

Alexander Belchenko bialix at ukr.net
Tue Mar 13 13:08:52 GMT 2007

Hash: SHA1

Wouter van Heyst пишет:
> On Tue, Mar 13, 2007 at 01:15:35AM +0200, Alexander Belchenko wrote:
>> John Arbash Meinel пишет:
>>> Alexander Belchenko wrote:
>>>> Next portion of fixes for selftest on win32:
>>> === modified file bzrlib/errors.py
>>> --- bzrlib/errors.py
>>> +++ bzrlib/errors.py
>>> @@ -647,7 +647,7 @@
>>>  class LockError(BzrError):
>>> -    _fmt = "Lock error: %(message)s"
>>> +    _fmt = "Lock error: %(msg)s"
>>>      internal_error = True
>>> @@ -657,7 +657,7 @@
>>>      #
>>>      # New code should prefer to raise specific subclasses
>>>      def __init__(self, message):
>>> -        self.message = message
>>> +        self.msg = message
>>> ^- Was this specifically needed? You seem to just be changing the
>>> variable, without actually changing the effect. But then again, children
>>> might be doing something different.
>> Yes, this needed for Python 2.5.
>> It works OK on Python 2.4, but not on Python 2.5.
>> In Python 2.5 basic class of all our errors (StandardError)
>> has attribute .message, that don't reflected in __dict__.
>> I'm not sure why, but you can test it with simple code:
> How did you figure this out? It had me quite stumped when I looked at it
> yesterday. (So much for not reading mail first)

I'm not sure what you actually asking.  Sorry for my bad bad english.
How I figure out -- 'what' exactly?

If you're asking about 'how I found unprintable exception?' -- it's easy,
I simple run overall selftest suite on my laptop before Robert release 0.15rc1
and study the results. (very frustrating show, y'now).

If you're asking about 'how I found solution?' -- I dash against this rock
about hour and trying different results, that all they does not work.
When I added muter call immediately after statement self.message = message
and saw that self.__dict__ is really empty, I recall about new-type classes
and __slots__ and then I found attribute .message in base class StandardError.
After changing our LockError class I found solution.
Looking at 'whats new in python 2.5' document, I see section:

"9 PEP 352: Exceptions as New-Style Classes"

I think this change in Python 2.5 is the root of problem.
In 2.4 all exception is old-style classes. In 2.5 they derived from object.
So probably we need to check our error classes.

BTW: I saw in the past recipe from Ned Batchelder to actually check
error message of exception (as extension to unittest's self.assertRaises):

    def assertRaisesMsg(self, excClass, msg, callableObj, *args, **kwargs):
        """Just like unittest.TestCase.assertRaises,
        but checks that the message is right too.

        Borrowed from Ned Batchelder Blog.
        See: http://www.nedbatchelder.com/blog/200609.html#e20060905T064418

        Typical usage:
            self.assertRaisesMsg(MyException, "Exception message", my_function, (arg1, arg2))
            callableObj(*args, **kwargs)
        except excClass, exc:
            excMsg = str(exc)
            if not msg:
                # No message provided: any message is fine.
            elif excMsg == msg:
                # Message provided, and we got the right message: it passes.
                # Message provided, and it didn't match: fail!
                raise self.failureException(
                    "Right exception, wrong message: got '%s' expected '%s'" %
                    (excMsg, msg)
            if hasattr(excClass, '__name__'):
                excName = excClass.__name__
                excName = str(excClass)
            raise self.failureException(
                "Expected to raise %s, didn't get an exception at all" %

I successfully use this method in my IntelHex project.


Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org


More information about the bazaar mailing list