Commits

Ned Batchelder committed e0c9022 Merge

Merged

  • Participants
  • Parent commits 2fb014b, d138c7d

Comments (0)

Files changed (7)

 Version 3.6b2
 -------------
 
+- Coverage.py runs on Python 2.3 and 2.4 again.
+
 - The C extension is optionally compiled using a different more widely-used
   technique, taking another stab at fixing ``issue 80``_ once and for all.
 

File coverage/backward.py

         lst.sort()
         return lst
 
+# rpartition is new in 2.5
+try:
+    "".rpartition
+except AttributeError:
+    def rpartition(s, sep):
+        """Implement s.rpartition(sep) for old Pythons."""
+        i = s.rfind(sep)
+        if i == -1:
+            return ('', '', s)
+        else:
+            return (s[:i], sep, s[i+len(sep):])
+else:
+    def rpartition(s, sep):
+        """A common interface for new Pythons."""
+        return s.rpartition(sep)
+
 # Pythons 2 and 3 differ on where to get StringIO
 try:
     from cStringIO import StringIO

File coverage/control.py

                 outfile = open(self.config.xml_output, "w")
                 file_to_close = outfile
         try:
-            reporter = XmlReporter(self, self.config)
-            return reporter.report(morfs, outfile=outfile)
-        except CoverageException:
-            delete_file = True
-            raise
+            try:
+                reporter = XmlReporter(self, self.config)
+                return reporter.report(morfs, outfile=outfile)
+            except CoverageException:
+                delete_file = True
+                raise
         finally:
             if file_to_close:
                 file_to_close.close()

File coverage/xmlreport.py

 import xml.dom.minidom
 
 from coverage import __url__, __version__
-from coverage.backward import sorted            # pylint: disable=W0622
+from coverage.backward import sorted, rpartition    # pylint: disable=W0622
 from coverage.report import Reporter
 
 def rate(hit, num):
 
         # Create the 'lines' and 'package' XML elements, which
         # are populated later.  Note that a package == a directory.
-        package_name = cu.name.rpartition(".")[0]
+        package_name = rpartition(cu.name, ".")[0]
         className = cu.name
 
         package = self.packages.setdefault(package_name, [{}, 0, 0, 0, 0])
 import os, sys
 
 from setuptools import setup
-from distutils.core import Extension    # pylint: disable=E0611,F0401
-from distutils.command.build_ext import build_ext
-from distutils.errors import (
-    CCompilerError, DistutilsExecError, DistutilsPlatformError
-    )
+from distutils.core import Extension            # pylint: disable=E0611,F0401
+from distutils.command import build_ext         # pylint: disable=E0611,F0401
+from distutils.errors import CCompilerError         # pylint: disable=E0611,F0401,C0301
+from distutils.errors import DistutilsExecError     # pylint: disable=E0611,F0401,C0301
+from distutils.errors import DistutilsPlatformError # pylint: disable=E0611,F0401,C0301
 
 # Get or massage our metadata.  We exec coverage/version.py so we can avoid
 # importing the product code into setup.py.
 
 ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError)
 if sys.platform == 'win32' and sys.version_info > (2, 6):
-   # 2.6's distutils.msvc9compiler can raise an IOError when failing to
-   # find the compiler
-   ext_errors += (IOError,)
+    # 2.6's distutils.msvc9compiler can raise an IOError when failing to
+    # find the compiler
+    ext_errors += (IOError,)
 
 class BuildFailed(Exception):
     """Raise this to indicate the C extension wouldn't build."""
     def __init__(self):
+        Exception.__init__()
         self.cause = sys.exc_info()[1] # work around py 2/3 different syntax
 
-class ve_build_ext(build_ext):
+class ve_build_ext(build_ext.build_ext):
     """Build C extensions, but fail with a straightforward exception."""
 
     def run(self):
         """Wrap `run` with `BuildFailed`."""
         try:
-            build_ext.run(self)
+            build_ext.build_ext.run(self)
         except DistutilsPlatformError:
             raise BuildFailed()
 
     def build_extension(self, ext):
         """Wrap `build_extension` with `BuildFailed`."""
         try:
-            build_ext.build_extension(self, ext)
+            build_ext.build_ext.build_extension(self, ext)
         except ext_errors:
             raise BuildFailed()
         except ValueError:

File test/test_process.py

     def setUp(self):
         super(ProcessStartupTest, self).setUp()
         # Find a place to put a .pth file.
+        pth_contents = "import coverage; coverage.process_startup()\n"
         for d in sys.path:                          # pragma: part covered
             g = glob.glob(os.path.join(d, "*.pth"))
             if g:
                 pth_path = os.path.join(d, "subcover.pth")
                 pth = open(pth_path, "w")
                 try:
-                    pth.write("import coverage; coverage.process_startup()\n")
-                    self.pth_path = pth_path
-                    break
-                except (IOError, OSError):          # pragma: not covered
-                    pass
+                    try:
+                        pth.write(pth_contents)
+                        self.pth_path = pth_path
+                        break
+                    except (IOError, OSError):          # pragma: not covered
+                        pass
                 finally:
                     pth.close()
         else:                                       # pragma: not covered

File test/test_testing.py

 
 import os, sys
 sys.path.insert(0, os.path.split(__file__)[0]) # Force relative import for Py3k
-from coverage.backward import to_bytes
+from coverage.backward import to_bytes, rpartition
 from backunittest import TestCase
 from coveragetest import CoverageTest
 
         executable = executable.split(":", 1)[1].strip()
         self.assertEqual(executable, sys.executable)
         environ = [l for l in out if "COV_FOOBAR" in l][0]
-        _, _, environ = environ.rpartition(":")
+        _, _, environ = rpartition(environ, ":")
         self.assertEqual(environ.strip(), "COV_FOOBAR = XYZZY")