[merge] python 2.5 fixes

Marien Zwart marienz at gentoo.org
Fri Sep 22 01:28:18 BST 2006


Attached is a bundle with the following fixes:

- Make the testrunner finish its run and report results if a doctest fails.
- Make bzr almost pass its selftest with python 2.5.

Most of the python 2.5 changes are to the tests, and all should be
straightforward.

There is one remaining selftest issue I do not know how to fix:

----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/marienz/tmp/bzr.dev/bzrlib/tests/test_command.py", line 53, in test_unicode_option
    commands.run_bzr, ['log', u'--option\xb5'])
  File "/usr/lib/python2.5/unittest.py", line 320, in failUnlessRaises
    callableObj(*args, **kwargs)
  File "/home/marienz/tmp/bzr.dev/bzrlib/commands.py", line 573, in run_bzr
    ret = run(*run_argv)
  File "/home/marienz/tmp/bzr.dev/bzrlib/commands.py", line 266, in run_argv_aliases
    args, opts = parse_args(self, argv, alias_argv)
  File "/home/marienz/tmp/bzr.dev/bzrlib/commands.py", line 365, in parse_args
    options, args = parser.parse_args(args)
  File "/usr/lib/python2.5/optparse.py", line 1380, in parse_args
    self.error(str(err))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xb5' in position 24: ordinal not in range(128)

----------------------------------------------------------------------

The problem is that this problem is entirely inside optparse. The
"self.error(str(err))" at the end of the traceback is
"self.error(err)" in python 2.4's optparse, and "err" is an instance
of optparse.BadOptionError that was initialized with the unicode
string from the test, causing its __str__ method to return unicode.
The only way I can think of to fix this inside bzr would be to copy
the python 2.4 version of "parse_args" into bzr's OptionParser
subclass, which is not exactly pretty.

I think it would be nice if this could be merged for bzr 0.11.

-- 
Marien.
-------------- next part --------------
# Bazaar revision bundle v0.8
#
# message:
#   Fix another python 2.5 issue.
# committer: Marien Zwart <marienz at gentoo.org>
# date: Fri 2006-09-22 02:17:08.542000055 +0200

=== modified file bzrlib/commands.py
--- bzrlib/commands.py
+++ bzrlib/commands.py
@@ -611,7 +611,7 @@
         return run_bzr(argv)
         # do this here inside the exception wrappers to catch EPIPE
         sys.stdout.flush()
-    except Exception, e:
+    except (KeyboardInterrupt, Exception), e:
         # used to handle AssertionError and KeyboardInterrupt
         # specially here, but hopefully they're handled ok by the logger now
         bzrlib.trace.report_exception(sys.exc_info(), sys.stderr)

=== modified file bzrlib/errors.py // last-changed:marienz at gentoo.org-200609212
... 30654-77cb3d28e97ffb9f
--- bzrlib/errors.py
+++ bzrlib/errors.py
@@ -44,7 +44,7 @@
 >>> try:
 ...   raise NotBranchError(path='/foo/bar')
 ... except:
-...   print sys.exc_type
+...   print '%s.%s' % (sys.exc_type.__module__, sys.exc_type.__name__)
 ...   print sys.exc_value
 ...   path = getattr(sys.exc_value, 'path', None)
 ...   if path is not None:
@@ -283,8 +283,7 @@
 
     def __init__(self, msg, base, args):
         PathError.__init__(self, base, msg)
-        self.args = [base]
-        self.args.extend(args)
+        self.args = [base] + list(args)
 
 
 class UnsupportedProtocol(PathError):

=== modified file bzrlib/plugins/launchpad/test_register.py // last-changed:mar
... ienz at gentoo.org-20060921230654-77cb3d28e97ffb9f
--- bzrlib/plugins/launchpad/test_register.py
+++ bzrlib/plugins/launchpad/test_register.py
@@ -71,6 +71,9 @@
 
 class InstrumentedXMLRPCTransport(xmlrpclib.Transport):
 
+    # Python 2.5's xmlrpclib looks for this.
+    _use_datetime = False
+
     def __init__(self, testcase):
         self.testcase = testcase
 

=== modified file bzrlib/tests/__init__.py // last-changed:marienz at gentoo.org-2
... 0060921230619-910d2ec258cba83d
--- bzrlib/tests/__init__.py
+++ bzrlib/tests/__init__.py
@@ -242,7 +242,11 @@
         if isinstance(err[1], TestSkipped):
             return self.addSkipped(test, err)    
         unittest.TestResult.addError(self, test, err)
-        test.setKeepLogfile()
+        # We can only do this if we have one of our TestCases, not if
+        # we have a doctest.
+        setKeepLogFile = getattr(test, 'setKeepLogFile', None)
+        if setKeepLogFile is not None:
+            setKeepLogfile()
         self.extractBenchmarkTime(test)
         if self.showAll:
             self.stream.writeln("ERROR %s" % self._testTimeString())
@@ -259,7 +263,11 @@
 
     def addFailure(self, test, err):
         unittest.TestResult.addFailure(self, test, err)
-        test.setKeepLogfile()
+        # We can only do this if we have one of our TestCases, not if
+        # we have a doctest.
+        setKeepLogFile = getattr(test, 'setKeepLogFile', None)
+        if setKeepLogFile is not None:
+            setKeepLogfile()
         self.extractBenchmarkTime(test)
         if self.showAll:
             self.stream.writeln(" FAIL %s" % self._testTimeString())

=== modified file bzrlib/trace.py // last-changed:marienz at gentoo.org-2006092123
... 0654-77cb3d28e97ffb9f
--- bzrlib/trace.py
+++ bzrlib/trace.py
@@ -288,7 +288,8 @@
     """Report an exception that probably indicates a bug in bzr"""
     import traceback
     exc_type, exc_object, exc_tb = exc_info
-    print >>err_file, "bzr: ERROR: %s: %s" % (exc_type, exc_object)
+    print >>err_file, "bzr: ERROR: %s.%s: %s" % (
+        exc_type.__module__, exc_type.__name__, exc_object)
     print >>err_file
     traceback.print_exception(exc_type, exc_object, exc_tb, file=err_file)
     print >>err_file

# revision id: marienz at gentoo.org-20060922001708-b5db1381393a1f0a
# sha1: 92ee23c425becf3e3dc52dd879af43f5331308c7
# inventory sha1: 42cf057b40d074277ecaefa39702eb733a937605
# parent ids:
#   marienz at gentoo.org-20060921230654-77cb3d28e97ffb9f
# base id: pqm at pqm.ubuntu.com-20060921170000-615159606ef6289f
# properties:
#   branch-nick: bzr.dev

# message:
#   Fixes for python 2.5.
# committer: Marien Zwart <marienz at gentoo.org>
# date: Fri 2006-09-22 01:06:54.134000063 +0200

=== modified file bzrlib/errors.py // encoding:base64
LS0tIGJ6cmxpYi9lcnJvcnMucHkKKysrIGJ6cmxpYi9lcnJvcnMucHkKQEAgLTQ0LDcgKzQ0LDcg
QEAKID4+PiB0cnk6CiAuLi4gICByYWlzZSBOb3RCcmFuY2hFcnJvcihwYXRoPScvZm9vL2Jhcicp
CiAuLi4gZXhjZXB0OgotLi4uICAgcHJpbnQgc3lzLmV4Y190eXBlCisuLi4gICBwcmludCAnJXMu
JXMnICUgKHN5cy5leGNfdHlwZS5fX21vZHVsZV9fLCBzeXMuZXhjX3R5cGUuX19uYW1lX18pCiAu
Li4gICBwcmludCBzeXMuZXhjX3ZhbHVlCiAuLi4gICBwYXRoID0gZ2V0YXR0cihzeXMuZXhjX3Zh
bHVlLCAncGF0aCcsIE5vbmUpCiAuLi4gICBpZiBwYXRoIGlzIG5vdCBOb25lOgpAQCAtMjgzLDgg
KzI4Myw3IEBACiAKICAgICBkZWYgX19pbml0X18oc2VsZiwgbXNnLCBiYXNlLCBhcmdzKToKICAg
ICAgICAgUGF0aEVycm9yLl9faW5pdF9fKHNlbGYsIGJhc2UsIG1zZykKLSAgICAgICAgc2VsZi5h
cmdzID0gW2Jhc2VdCi0gICAgICAgIHNlbGYuYXJncy5leHRlbmQoYXJncykKKyAgICAgICAgc2Vs
Zi5hcmdzID0gW2Jhc2VdICsgbGlzdChhcmdzKQogCiAKIGNsYXNzIFVuc3VwcG9ydGVkUHJvdG9j
b2woUGF0aEVycm9yKToKCg==

=== modified file bzrlib/plugins/launchpad/test_register.py // encoding:base64
LS0tIGJ6cmxpYi9wbHVnaW5zL2xhdW5jaHBhZC90ZXN0X3JlZ2lzdGVyLnB5CisrKyBienJsaWIv
cGx1Z2lucy9sYXVuY2hwYWQvdGVzdF9yZWdpc3Rlci5weQpAQCAtNzEsNiArNzEsOSBAQAogCiBj
bGFzcyBJbnN0cnVtZW50ZWRYTUxSUENUcmFuc3BvcnQoeG1scnBjbGliLlRyYW5zcG9ydCk6CiAK
KyAgICAjIFB5dGhvbiAyLjUncyB4bWxycGNsaWIgbG9va3MgZm9yIHRoaXMuCisgICAgX3VzZV9k
YXRldGltZSA9IEZhbHNlCisKICAgICBkZWYgX19pbml0X18oc2VsZiwgdGVzdGNhc2UpOgogICAg
ICAgICBzZWxmLnRlc3RjYXNlID0gdGVzdGNhc2UKIAoK

=== modified file bzrlib/trace.py // encoding:base64
LS0tIGJ6cmxpYi90cmFjZS5weQorKysgYnpybGliL3RyYWNlLnB5CkBAIC0yODgsNyArMjg4LDgg
QEAKICAgICAiIiJSZXBvcnQgYW4gZXhjZXB0aW9uIHRoYXQgcHJvYmFibHkgaW5kaWNhdGVzIGEg
YnVnIGluIGJ6ciIiIgogICAgIGltcG9ydCB0cmFjZWJhY2sKICAgICBleGNfdHlwZSwgZXhjX29i
amVjdCwgZXhjX3RiID0gZXhjX2luZm8KLSAgICBwcmludCA+PmVycl9maWxlLCAiYnpyOiBFUlJP
UjogJXM6ICVzIiAlIChleGNfdHlwZSwgZXhjX29iamVjdCkKKyAgICBwcmludCA+PmVycl9maWxl
LCAiYnpyOiBFUlJPUjogJXMuJXM6ICVzIiAlICgKKyAgICAgICAgZXhjX3R5cGUuX19tb2R1bGVf
XywgZXhjX3R5cGUuX19uYW1lX18sIGV4Y19vYmplY3QpCiAgICAgcHJpbnQgPj5lcnJfZmlsZQog
ICAgIHRyYWNlYmFjay5wcmludF9leGNlcHRpb24oZXhjX3R5cGUsIGV4Y19vYmplY3QsIGV4Y190
YiwgZmlsZT1lcnJfZmlsZSkKICAgICBwcmludCA+PmVycl9maWxlCgo=

# revision id: marienz at gentoo.org-20060921230654-77cb3d28e97ffb9f
# sha1: 79c00d37da729d2fc5dff110e521ea2786f36a2c
# inventory sha1: a151c6f2cd5b7e8ec46be0beda779bd0488bef49
# parent ids:
#   marienz at gentoo.org-20060921230619-910d2ec258cba83d
# properties:
#   branch-nick: bzr.dev

# message:
#   Make the test runner finish running if a doctest fails.
# committer: Marien Zwart <marienz at gentoo.org>
# date: Fri 2006-09-22 01:06:19.480999947 +0200

=== modified file bzrlib/tests/__init__.py // encoding:base64
LS0tIGJ6cmxpYi90ZXN0cy9fX2luaXRfXy5weQorKysgYnpybGliL3Rlc3RzL19faW5pdF9fLnB5
CkBAIC0yNDIsNyArMjQyLDExIEBACiAgICAgICAgIGlmIGlzaW5zdGFuY2UoZXJyWzFdLCBUZXN0
U2tpcHBlZCk6CiAgICAgICAgICAgICByZXR1cm4gc2VsZi5hZGRTa2lwcGVkKHRlc3QsIGVycikg
ICAgCiAgICAgICAg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yAgICAgICAgICAgIHNldEtlZXBMb2dmaWxlKCkKICAgICAgICAg
c2VsZi5leHRyYWN0QmVuY2htYXJrVGltZSh0ZXN0KQogICAgICAgICBpZiBzZWxmLnNob3dBbGw6
CiAgICAgICAgICAgICBzZWxmLnN0cmVhbS53cml0ZWxuKCIgRkFJTCAlcyIgJSBzZWxmLl90ZXN0
VGltZVN0cmluZygpKQoK

# revision id: marienz at gentoo.org-20060921230619-910d2ec258cba83d
# sha1: 89034a660e8b0668462ce6f996a8c86ea7ed86f7
# inventory sha1: 572173b5b60b1e661227ac0f0e3f758c7a15d3c9
# parent ids:
#   pqm at pqm.ubuntu.com-20060921170000-615159606ef6289f
# properties:
#   branch-nick: bzr.dev

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060922/94ecaea4/attachment.pgp 


More information about the bazaar mailing list