Commits

Ned Batchelder  committed d7a4311

Make everything work on py2.3 again (for the last time).

  • Participants
  • Parent commits 65d7ca4

Comments (0)

Files changed (5)

File coverage/phystokens.py

             raise SyntaxError("unknown encoding: " + encoding)
 
         if bom_found:
-            if codec.name != 'utf-8':
+            # codecs in 2.3 were raw tuples of functions, assume the best.
+            codec_name = getattr(codec, 'name', encoding)
+            if codec_name != 'utf-8':
                 # This behaviour mimics the Python interpreter
                 raise SyntaxError('encoding problem: utf-8')
             encoding += '-sig'

File tests/coveragetest.py

 """Base test case class for coverage testing."""
 
 import glob, imp, os, random, shlex, shutil, sys, tempfile, textwrap
-import atexit, collections
+import atexit
 
 import coverage
 from coverage.backward import sorted, StringIO      # pylint: disable=W0622
             self.test_method_made_any_files = False
 
     # Map from class to info about how it ran.
-    class_behaviors = collections.defaultdict(ClassBehavior)
+    class_behaviors = {}
 
-    @classmethod
     def report_on_class_behavior(cls):
         """Called at process exit to report on class behavior."""
         for test_class, behavior in cls.class_behaviors.items():
                         where,
                     )
                 )
+    report_on_class_behavior = classmethod(report_on_class_behavior)
 
     def class_behavior(self):
         """Get the ClassBehavior instance for this test."""
-        return self.class_behaviors[self.__class__]
+        cls = self.__class__
+        if cls not in self.class_behaviors:
+            self.class_behaviors[cls] = self.ClassBehavior()
+        return self.class_behaviors[cls]
 
 
 # When the process ends, find out about bad classes.

File tests/test_collector.py

 
 import coverage
 from coverage.backward import StringIO
+from coverage.backward import set                   # pylint: disable=W0622
 
 from tests.coveragetest import CoverageTest
 

File tests/test_phystokens.py

         if sys.version_info >= (2,4):
             default_encoding = 'ascii'
         else:
-            default_encoding = 'iso8859-1'
+            default_encoding = 'iso-8859-1'
 
         def test_detect_source_encoding(self):
             # Various forms from http://www.python.org/dev/peps/pep-0263/

File tests/test_testing.py

         # "environment: COV_FOOBAR = XYZZY" or "COV_FOOBAR = XYZZY"
         executable = [l for l in out if "executable:" in l][0]
         executable = executable.split(":", 1)[1].strip()
-        self.assertEqual(executable, sys.executable)
+        self.assertTrue(same_python_executable(executable, sys.executable))
         environ = [l for l in out if "COV_FOOBAR" in l][0]
         _, _, environ = rpartition(environ, ":")
         self.assertEqual(environ.strip(), "COV_FOOBAR = XYZZY")
+
+
+def same_python_executable(e1, e2):
+    """Determine if `e1` and `e2` refer to the same Python executable.
+
+    Either path could include symbolic links.  The two paths might not refer
+    to the exact same file, but if they are in the same directory and their
+    numeric suffixes aren't different, they are the same executable.
+
+    """
+    e1 = os.path.abspath(os.path.realpath(e1))
+    e2 = os.path.abspath(os.path.realpath(e2))
+
+    if os.path.dirname(e1) != os.path.dirname(e2):
+        return False
+
+    e1 = os.path.basename(e1)
+    e2 = os.path.basename(e2)
+
+    if e1 == "python" or e2 == "python" or e1 == e2:
+        # python and python2.3: ok
+        # python2.3 and python: ok
+        # python and python: ok
+        # python2.3 and python2.3: ok
+        return True
+
+    return False