diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2012-12-19 21:20:29 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2012-12-19 21:20:29 -0500 |
commit | fc38bf8526cb1717968a1958439da5fae4768375 (patch) | |
tree | 60a2a5097868dbe63196b349ec222e92a9003f03 | |
parent | 05dd78ed22cc997d7481683cab012b73bf5d710a (diff) | |
download | python-coveragepy-git-fc38bf8526cb1717968a1958439da5fae4768375.tar.gz |
Retro-fit onto 2.3 and 2.4 again.
-rw-r--r-- | CHANGES.txt | 2 | ||||
-rw-r--r-- | coverage/backward.py | 16 | ||||
-rw-r--r-- | coverage/control.py | 11 | ||||
-rw-r--r-- | coverage/xmlreport.py | 4 | ||||
-rw-r--r-- | setup.py | 6 | ||||
-rw-r--r-- | test/test_process.py | 12 | ||||
-rw-r--r-- | test/test_testing.py | 4 |
7 files changed, 38 insertions, 17 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index ef15a0cc..be5531a1 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -5,6 +5,8 @@ Change history for Coverage.py 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. diff --git a/coverage/backward.py b/coverage/backward.py index 6347501a..2c015af2 100644 --- a/coverage/backward.py +++ b/coverage/backward.py @@ -24,6 +24,22 @@ except NameError: 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 diff --git a/coverage/control.py b/coverage/control.py index 80495ef4..dafd0143 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -642,11 +642,12 @@ class coverage(object): 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() diff --git a/coverage/xmlreport.py b/coverage/xmlreport.py index 4344488d..301bc865 100644 --- a/coverage/xmlreport.py +++ b/coverage/xmlreport.py @@ -4,7 +4,7 @@ import os, sys, time 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): @@ -92,7 +92,7 @@ class XmlReporter(Reporter): # 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]) @@ -42,9 +42,9 @@ import os, sys from setuptools import setup from distutils.core import Extension # pylint: disable=E0611,F0401 from distutils.command import build_ext # pylint: disable=E0611,F0401 -from distutils.errors import ( # pylint: disable=E0611,F0401 - CCompilerError, DistutilsExecError, DistutilsPlatformError - ) +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. diff --git a/test/test_process.py b/test/test_process.py index 6d1e1fd0..524d793e 100644 --- a/test/test_process.py +++ b/test/test_process.py @@ -462,17 +462,19 @@ class ProcessStartupTest(CoverageTest): 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 diff --git a/test/test_testing.py b/test/test_testing.py index c8672e49..fcbffcde 100644 --- a/test/test_testing.py +++ b/test/test_testing.py @@ -3,7 +3,7 @@ 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 @@ -189,5 +189,5 @@ class CoverageTestTest(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") |