Merge lp:~gz/pyjunitxml/source_compat_python_3 into lp:pyjunitxml

Proposed by Martin Packman
Status: Merged
Approved by: Robert Collins
Approved revision: 20
Merged at revision: 19
Proposed branch: lp:~gz/pyjunitxml/source_compat_python_3
Merge into: lp:pyjunitxml
Diff against target: 82 lines (+15/-7)
2 files modified
junitxml/__init__.py (+9/-4)
junitxml/tests/test_junitxml.py (+6/-3)
To merge this branch: bzr merge lp:~gz/pyjunitxml/source_compat_python_3
Reviewer Review Type Date Requested Status
Robert Collins Pending
Review via email: mp+34037@code.launchpad.net

Description of the change

Branch to restore Python 3 compatibility. In doing so, needed to back out Vincent's addition of an encode call, but as this was breaking on babune anyway in some circumstances we want a proper fix there anyway (bug 625589 I'll get you soon...) Also does Python 3 style stripping of module name from front of builtin exceptions, as they all moved from 'exceptions' to 'builtins' and that was making the tests cry.

To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

Please be editing NEWS.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'junitxml/__init__.py'
2--- junitxml/__init__.py 2010-01-12 10:26:29 +0000
3+++ junitxml/__init__.py 2010-08-29 21:57:42 +0000
4@@ -39,6 +39,12 @@
5 return None
6
7
8+def _error_name(eclass):
9+ module = eclass.__module__
10+ if module not in ("__main__", "builtins", "exceptions"):
11+ return ".".join([module, eclass.__name__])
12+ return eclass.__name__
13+
14
15 class JUnitXmlResult(unittest.TestResult):
16 """A TestResult which outputs JUnit compatible XML."""
17@@ -89,7 +95,6 @@
18 delta = self._now() - from_datetime
19 except TypeError:
20 n = self._now()
21- print n, self._set_time, from_datetime
22 delta = datetime.timedelta(-1)
23 seconds = delta.days * 3600*24 + delta.seconds
24 return seconds + 0.000001 * delta.microseconds
25@@ -116,20 +121,20 @@
26 self._stream.write('<testsuite errors="%d" failures="%d" name="" '
27 'tests="%d" time="%0.3f">\n' % (len(self.errors),
28 len(self.failures), self.testsRun, duration))
29- self._stream.write((''.join(self._results)).encode('utf8'))
30+ self._stream.write(''.join(self._results))
31 self._stream.write('</testsuite>\n')
32
33 def addError(self, test, error):
34 self.__super.addError(test, error)
35 self._test_case_string(test)
36 self._results.append('>\n')
37- self._results.append('<error type="%s.%s">%s</error>\n</testcase>\n'% (escape(error[0].__module__), escape(error[0].__name__), escape(self._exc_info_to_string(error, test))))
38+ self._results.append('<error type="%s">%s</error>\n</testcase>\n'% (escape(_error_name(error[0])), escape(self._exc_info_to_string(error, test))))
39
40 def addFailure(self, test, error):
41 self.__super.addFailure(test, error)
42 self._test_case_string(test)
43 self._results.append('>\n')
44- self._results.append('<failure type="%s.%s">%s</failure>\n</testcase>\n'% (escape(error[0].__module__), escape(error[0].__name__), escape(self._exc_info_to_string(error, test))))
45+ self._results.append('<failure type="%s">%s</failure>\n</testcase>\n'% (escape(_error_name(error[0])), escape(self._exc_info_to_string(error, test))))
46
47 def addSuccess(self, test):
48 self.__super.addSuccess(test)
49
50=== modified file 'junitxml/tests/test_junitxml.py'
51--- junitxml/tests/test_junitxml.py 2009-12-12 06:42:03 +0000
52+++ junitxml/tests/test_junitxml.py 2010-08-29 21:57:42 +0000
53@@ -5,7 +5,10 @@
54 # Copying permitted under the LGPL-3 licence, included with this library.
55
56
57-from cStringIO import StringIO
58+try:
59+ from cStringIO import StringIO
60+except ImportError:
61+ from io import StringIO
62 import datetime
63 import re
64 import unittest
65@@ -96,7 +99,7 @@
66 self.result.stopTestRun()
67 self.assertEqual("""<testsuite errors="1" failures="0" name="" tests="1" time="0.000">
68 <testcase classname="junitxml.tests.test_junitxml.Errors" name="test_me" time="0.000">
69-<error type="exceptions.ZeroDivisionError">error</error>
70+<error type="ZeroDivisionError">error</error>
71 </testcase>
72 </testsuite>
73 """, self.get_output())
74@@ -110,7 +113,7 @@
75 self.result.stopTestRun()
76 self.assertEqual("""<testsuite errors="0" failures="1" name="" tests="1" time="0.000">
77 <testcase classname="junitxml.tests.test_junitxml.Fails" name="test_me" time="0.000">
78-<failure type="exceptions.AssertionError">failure</failure>
79+<failure type="AssertionError">failure</failure>
80 </testcase>
81 </testsuite>
82 """, self.get_output())

Subscribers

People subscribed via source and target branches

to all changes: