Commits

Ned Batchelder committed 1e7fb99

We only run on 2.6, 2.7, 3.2, 3.3 now.

Comments (0)

Files changed (12)

coverage/phystokens.py

     # invalid charset, raise a SyntaxError.  Note that if a utf-8 bom is found,
     # 'utf-8-sig' is returned.
 
-    # If no encoding is specified, then the default will be returned.  The
-    # default varied with version.
-
-    if sys.version_info <= (2, 4):
-        default = 'iso-8859-1'
-    else:
-        default = 'ascii'
+    # If no encoding is specified, then the default will be returned.
+    default = 'ascii'
 
     bom_found = False
     encoding = None
 the code analysis tools and tracing hooks provided in the Python standard
 library to determine which lines are executable, and which have been executed.
 
-Coverage.py runs on Pythons 2.3 through 3.3, and PyPy 1.9.
+Coverage.py runs on Pythons 2.6, 2.7, 3.2, 3.3, and PyPy 1.9.
 
 Documentation is at `nedbatchelder.com <%s>`_.  Code repository and issue
 tracker are on `Bitbucket <http://bitbucket.org/ned/coveragepy>`_, with a
     errors.DistutilsExecError,
     errors.DistutilsPlatformError,
 )
-if sys.platform == 'win32' and sys.version_info > (2, 6):
-    # 2.6's distutils.msvc9compiler can raise an IOError when failing to
+if sys.platform == 'win32':
+    # distutils.msvc9compiler can raise an IOError when failing to
     # find the compiler
     ext_errors += (IOError,)
 

tests/farm/html/run_partial.py

 contains("html_partial/index.html",
     "<a href='partial.html'>partial</a>",
     )
-if sys.version_info >= (2, 4):
-    contains("html_partial/index.html",
-        "<span class='pc_cov'>100%</span>"
-        )
+contains("html_partial/index.html",
+    "<span class='pc_cov'>100%</span>"
+    )
 
 clean("html_partial")
 
 import sys
 
-if sys.version_info >= (2, 5) and sys.platform == 'win32':
+if sys.platform == 'win32':
     # Windows implementation
     def process_ram():
         """How much RAM is this process using? (Windows)"""

tests/test_arcs.py

             arcz=".1 14 45 5.  .2 2. 23 3.", arcz_missing="23 3.")
 
     def test_multiline(self):
-        # The firstlineno of the a assignment below differs among Python
-        # versions.
-        if sys.version_info >= (2, 5):
-            arcz = ".1 15 5-2"
-        else:
-            arcz = ".1 15 5-1"
         self.check_coverage("""\
             a = (
                 2 +
             b = \\
                 6
             """,
-            arcz=arcz, arcz_missing="")
+            arcz=".1 15 5-2", arcz_missing="")
 
     def test_if_return(self):
         self.check_coverage("""\
                 )
 
 
-if sys.version_info >= (2, 6):
-    class WithTest(CoverageTest):
-        """Arc-measuring tests involving context managers."""
+class WithTest(CoverageTest):
+    """Arc-measuring tests involving context managers."""
 
-        def test_with(self):
-            self.check_coverage("""\
-                def example():
-                    with open("test", "w") as f: # exit
-                        f.write("")
-                        return 1
+    def test_with(self):
+        self.check_coverage("""\
+            def example():
+                with open("test", "w") as f: # exit
+                    f.write("")
+                    return 1
 
-                example()
-                """,
-                arcz=".1 .2 23 34 4. 16 6."
-                )
+            example()
+            """,
+            arcz=".1 .2 23 34 4. 16 6."
+            )
 
-        def test_bug_146(self):
-            # https://bitbucket.org/ned/coveragepy/issue/146
-            self.check_coverage("""\
-                for i in range(2):
-                    with open("test", "w") as f:
-                        print(3)
-                    print(4)
-                print(5)
-                """,
-                arcz=".1 12 23 34 41 15 5."
-                )
+    def test_bug_146(self):
+        # https://bitbucket.org/ned/coveragepy/issue/146
+        self.check_coverage("""\
+            for i in range(2):
+                with open("test", "w") as f:
+                    print(3)
+                print(4)
+            print(5)
+            """,
+            arcz=".1 12 23 34 41 15 5."
+            )
 
 
 class LoopArcTest(CoverageTest):
             arcz=".1 12 23 35 56 61 17 7.",
             arcz_missing="", arcz_unpredicted="")
 
-    # Run this test only on 2.6 and 2.7 for now.  I hope to fix it on Py3
+    # Run this test only on Py2 for now.  I hope to fix it on Py3
     # eventually...
-    if (2, 6) <= sys.version_info < (3,):
+    if sys.version_info < (3, 0):
         # "except Exception as e" is crucial here.
         def test_bug_212(self):
             self.check_coverage("""\
                 arcz=".1 .2 1A 23 34 56 67 68 8. AB BC C. DE E.",
                 arcz_missing="C.", arcz_unpredicted="45 7. CD")
 
-    if sys.version_info >= (2, 5):
-        # Try-except-finally was new in 2.5
-        def test_except_finally(self):
-            self.check_coverage("""\
-                a, b, c = 1, 1, 1
-                try:
-                    a = 3
-                except:
-                    b = 5
-                finally:
-                    c = 7
-                assert a == 3 and b == 1 and c == 7
-                """,
-                arcz=".1 12 23 45 37 57 78 8.", arcz_missing="45 57")
-            self.check_coverage("""\
-                a, b, c = 1, 1, 1
-                def oops(x):
-                    if x % 2: raise Exception("odd")
-                try:
-                    a = 5
-                    oops(1)
-                    a = 7
-                except:
-                    b = 9
-                finally:
-                    c = 11
-                assert a == 5 and b == 9 and c == 11
-                """,
-                arcz=".1 12 .3 3-2 24 45 56 67 7B 89 9B BC C.",
-                arcz_missing="67 7B", arcz_unpredicted="68")
+    def test_except_finally(self):
+        self.check_coverage("""\
+            a, b, c = 1, 1, 1
+            try:
+                a = 3
+            except:
+                b = 5
+            finally:
+                c = 7
+            assert a == 3 and b == 1 and c == 7
+            """,
+            arcz=".1 12 23 45 37 57 78 8.", arcz_missing="45 57")
+        self.check_coverage("""\
+            a, b, c = 1, 1, 1
+            def oops(x):
+                if x % 2: raise Exception("odd")
+            try:
+                a = 5
+                oops(1)
+                a = 7
+            except:
+                b = 9
+            finally:
+                c = 11
+            assert a == 5 and b == 9 and c == 11
+            """,
+            arcz=".1 12 .3 3-2 24 45 56 67 7B 89 9B BC C.",
+            arcz_missing="67 7B", arcz_unpredicted="68")
 
 
 class MiscArcTest(CoverageTest):

tests/test_config.py

             'other': ['other', '/home/ned/other', 'c:\\Ned\\etc']
             })
 
-    if sys.version_info[:2] != (3,1):
-        def test_one(self):
-            # This sample file tries to use lots of variation of syntax...
-            self.make_file(".coveragerc", """\
-                [html]
-                title = tabblo & «ταБЬℓσ» # numbers
-                """)
-            cov = coverage.coverage()
+    def test_one(self):
+        # This sample file tries to use lots of variation of syntax...
+        self.make_file(".coveragerc", """\
+            [html]
+            title = tabblo & «ταБЬℓσ» # numbers
+            """)
+        cov = coverage.coverage()
 
-            self.assertEqual(cov.config.html_title,
-                "tabblo & «ταБЬℓσ» # numbers"
-                )
+        self.assertEqual(cov.config.html_title,
+            "tabblo & «ταБЬℓσ» # numbers"
+            )

tests/test_coverage.py

             """,
             [1,2,4,5,7,9,10], "4, 7")
 
-    if sys.version_info >= (2, 4):
-        # In 2.4 and up, constant if's were compiled away.
-        def test_constant_if(self):
-            self.check_coverage("""\
-                if 1:
-                    a = 2
-                assert a == 2
-                """,
-                [2,3], "")
+    def test_constant_if(self):
+        self.check_coverage("""\
+            if 1:
+                a = 2
+            assert a == 2
+            """,
+            [2,3], "")
 
     def test_while(self):
         self.check_coverage("""\
             [8,9], "", excludes=['#pragma: NO COVER'])
 
 
-if sys.version_info >= (2, 4):
-    class Py24Test(CoverageTest):
-        """Tests of new syntax in Python 2.4."""
+class Py24Test(CoverageTest):
+    """Tests of new syntax in Python 2.4."""
 
-        def test_function_decorators(self):
-            self.check_coverage("""\
-                def require_int(func):
+    def test_function_decorators(self):
+        self.check_coverage("""\
+            def require_int(func):
+                def wrapper(arg):
+                    assert isinstance(arg, int)
+                    return func(arg)
+
+                return wrapper
+
+            @require_int
+            def p1(arg):
+                return arg*2
+
+            assert p1(10) == 20
+            """,
+            [1,2,3,4,6,8,10,12], "")
+
+    def test_function_decorators_with_args(self):
+        self.check_coverage("""\
+            def boost_by(extra):
+                def decorator(func):
                     def wrapper(arg):
-                        assert isinstance(arg, int)
-                        return func(arg)
+                        return extra*func(arg)
+                    return wrapper
+                return decorator
 
+            @boost_by(10)
+            def boosted(arg):
+                return arg*2
+
+            assert boosted(10) == 200
+            """,
+            [1,2,3,4,5,6,8,10,12], "")
+
+    def test_double_function_decorators(self):
+        self.check_coverage("""\
+            def require_int(func):
+                def wrapper(arg):
+                    assert isinstance(arg, int)
+                    return func(arg)
+                return wrapper
+
+            def boost_by(extra):
+                def decorator(func):
+                    def wrapper(arg):
+                        return extra*func(arg)
                     return wrapper
+                return decorator
 
-                @require_int
-                def p1(arg):
-                    return arg*2
+            @require_int
+            @boost_by(10)
+            def boosted1(arg):
+                return arg*2
 
-                assert p1(10) == 20
-                """,
-                [1,2,3,4,6,8,10,12], "")
+            assert boosted1(10) == 200
 
-        def test_function_decorators_with_args(self):
-            self.check_coverage("""\
-                def boost_by(extra):
-                    def decorator(func):
-                        def wrapper(arg):
-                            return extra*func(arg)
-                        return wrapper
-                    return decorator
+            @boost_by(10)
+            @require_int
+            def boosted2(arg):
+                return arg*2
 
-                @boost_by(10)
-                def boosted(arg):
-                    return arg*2
+            assert boosted2(10) == 200
+            """,
+            ([1,2,3,4,5,7,8,9,10,11,12,14,15,17,19,21,22,24,26],
+                [1,2,3,4,5,7,8,9,10,11,12,14,   17,19,21,   24,26]), "")
 
-                assert boosted(10) == 200
-                """,
-                [1,2,3,4,5,6,8,10,12], "")
 
-        def test_double_function_decorators(self):
-            self.check_coverage("""\
-                def require_int(func):
-                    def wrapper(arg):
-                        assert isinstance(arg, int)
-                        return func(arg)
-                    return wrapper
+class Py25Test(CoverageTest):
+    """Tests of new syntax in Python 2.5."""
 
-                def boost_by(extra):
-                    def decorator(func):
-                        def wrapper(arg):
-                            return extra*func(arg)
-                        return wrapper
-                    return decorator
+    def test_with_statement(self):
+        self.check_coverage("""\
+            from __future__ import with_statement
 
-                @require_int
-                @boost_by(10)
-                def boosted1(arg):
-                    return arg*2
+            class Managed:
+                def __enter__(self):
+                    desc = "enter"
 
-                assert boosted1(10) == 200
+                def __exit__(self, type, value, tb):
+                    desc = "exit"
 
-                @boost_by(10)
-                @require_int
-                def boosted2(arg):
-                    return arg*2
+            m = Managed()
+            with m:
+                desc = "block1a"
+                desc = "block1b"
 
-                assert boosted2(10) == 200
-                """,
-                ([1,2,3,4,5,7,8,9,10,11,12,14,15,17,19,21,22,24,26],
-                 [1,2,3,4,5,7,8,9,10,11,12,14,   17,19,21,   24,26]), "")
+            try:
+                with m:
+                    desc = "block2"
+                    raise Exception("Boo!")
+            except:
+                desc = "caught"
+            """,
+            [1,3,4,5,7,8,10,11,12,13,15,16,17,18,19,20], "")
 
-
-if sys.version_info >= (2, 5):
-    class Py25Test(CoverageTest):
-        """Tests of new syntax in Python 2.5."""
-
-        def test_with_statement(self):
-            self.check_coverage("""\
-                from __future__ import with_statement
-
-                class Managed:
-                    def __enter__(self):
-                        desc = "enter"
-
-                    def __exit__(self, type, value, tb):
-                        desc = "exit"
-
-                m = Managed()
-                with m:
-                    desc = "block1a"
-                    desc = "block1b"
-
-                try:
-                    with m:
-                        desc = "block2"
-                        raise Exception("Boo!")
-                except:
-                    desc = "caught"
-                """,
-                [1,3,4,5,7,8,10,11,12,13,15,16,17,18,19,20], "")
-
-        def test_try_except_finally(self):
-            self.check_coverage("""\
-                a = 0; b = 0
-                try:
-                    a = 1
-                except:
-                    a = 99
-                finally:
-                    b = 2
-                assert a == 1 and b == 2
-                """,
-                [1,2,3,4,5,7,8], "4-5")
-            self.check_coverage("""\
-                a = 0; b = 0
-                try:
-                    a = 1
-                    raise Exception("foo")
-                except:
-                    a = 99
-                finally:
-                    b = 2
-                assert a == 99 and b == 2
-                """,
-                [1,2,3,4,5,6,8,9], "")
-            self.check_coverage("""\
-                a = 0; b = 0
-                try:
-                    a = 1
-                    raise Exception("foo")
-                except ImportError:
-                    a = 99
-                except:
-                    a = 123
-                finally:
-                    b = 2
-                assert a == 123 and b == 2
-                """,
-                [1,2,3,4,5,6,7,8,10,11], "6")
-            self.check_coverage("""\
-                a = 0; b = 0
-                try:
-                    a = 1
-                    raise IOError("foo")
-                except ImportError:
-                    a = 99
-                except IOError:
-                    a = 17
-                except:
-                    a = 123
-                finally:
-                    b = 2
-                assert a == 17 and b == 2
-                """,
-                [1,2,3,4,5,6,7,8,9,10,12,13], "6, 9-10")
-            self.check_coverage("""\
-                a = 0; b = 0
-                try:
-                    a = 1
-                except:
-                    a = 99
-                else:
-                    a = 123
-                finally:
-                    b = 2
-                assert a == 123 and b == 2
-                """,
-                [1,2,3,4,5,7,9,10], "4-5")
-            self.check_coverage("""\
-                a = 0; b = 0
-                try:
-                    a = 1
-                    raise Exception("foo")
-                except:
-                    a = 99
-                else:
-                    a = 123
-                finally:
-                    b = 2
-                assert a == 99 and b == 2
-                """,
-                [1,2,3,4,5,6,8,10,11], "8")
+    def test_try_except_finally(self):
+        self.check_coverage("""\
+            a = 0; b = 0
+            try:
+                a = 1
+            except:
+                a = 99
+            finally:
+                b = 2
+            assert a == 1 and b == 2
+            """,
+            [1,2,3,4,5,7,8], "4-5")
+        self.check_coverage("""\
+            a = 0; b = 0
+            try:
+                a = 1
+                raise Exception("foo")
+            except:
+                a = 99
+            finally:
+                b = 2
+            assert a == 99 and b == 2
+            """,
+            [1,2,3,4,5,6,8,9], "")
+        self.check_coverage("""\
+            a = 0; b = 0
+            try:
+                a = 1
+                raise Exception("foo")
+            except ImportError:
+                a = 99
+            except:
+                a = 123
+            finally:
+                b = 2
+            assert a == 123 and b == 2
+            """,
+            [1,2,3,4,5,6,7,8,10,11], "6")
+        self.check_coverage("""\
+            a = 0; b = 0
+            try:
+                a = 1
+                raise IOError("foo")
+            except ImportError:
+                a = 99
+            except IOError:
+                a = 17
+            except:
+                a = 123
+            finally:
+                b = 2
+            assert a == 17 and b == 2
+            """,
+            [1,2,3,4,5,6,7,8,9,10,12,13], "6, 9-10")
+        self.check_coverage("""\
+            a = 0; b = 0
+            try:
+                a = 1
+            except:
+                a = 99
+            else:
+                a = 123
+            finally:
+                b = 2
+            assert a == 123 and b == 2
+            """,
+            [1,2,3,4,5,7,9,10], "4-5")
+        self.check_coverage("""\
+            a = 0; b = 0
+            try:
+                a = 1
+                raise Exception("foo")
+            except:
+                a = 99
+            else:
+                a = 123
+            finally:
+                b = 2
+            assert a == 99 and b == 2
+            """,
+            [1,2,3,4,5,6,8,10,11], "8")
 
 
 class ModuleTest(CoverageTest):

tests/test_html.py

         self.assertIn("<title>Metrics &amp; stuff!</title>", index)
         self.assertIn("<h1>Metrics &amp; stuff!:", index)
 
-    if sys.version_info[:2] != (3,1):
-        def test_non_ascii_title_set_in_config_file(self):
-            self.create_initial_files()
-            self.make_file(".coveragerc",
-                "[html]\ntitle = «ταБЬℓσ» numbers"
-                )
-            self.run_coverage()
-            index = open("htmlcov/index.html").read()
-            self.assertIn(
-                "<title>&#171;&#964;&#945;&#1041;&#1068;&#8467;&#963;&#187;"
-                " numbers", index
-                )
-            self.assertIn(
-                "<h1>&#171;&#964;&#945;&#1041;&#1068;&#8467;&#963;&#187;"
-                " numbers", index
-                )
+    def test_non_ascii_title_set_in_config_file(self):
+        self.create_initial_files()
+        self.make_file(".coveragerc",
+            "[html]\ntitle = «ταБЬℓσ» numbers"
+            )
+        self.run_coverage()
+        index = open("htmlcov/index.html").read()
+        self.assertIn(
+            "<title>&#171;&#964;&#945;&#1041;&#1068;&#8467;&#963;&#187;"
+            " numbers", index
+            )
+        self.assertIn(
+            "<h1>&#171;&#964;&#945;&#1041;&#1068;&#8467;&#963;&#187;"
+            " numbers", index
+            )
 
     def test_title_set_in_args(self):
         self.create_initial_files()

tests/test_oddball.py

             self.assertEqual(clean_lines, lines_expected)
 
 
-if sys.version_info >= (2, 5):
-    class DoctestTest(CoverageTest):
-        """Tests invoked with doctest should measure properly."""
+class DoctestTest(CoverageTest):
+    """Tests invoked with doctest should measure properly."""
 
-        def setUp(self):
-            super(DoctestTest, self).setUp()
+    def setUp(self):
+        super(DoctestTest, self).setUp()
 
-            # Oh, the irony!  This test case exists because Python 2.4's
-            # doctest module doesn't play well with coverage.  But nose fixes
-            # the problem by monkeypatching doctest.  I want to undo the
-            # monkeypatch to be sure I'm getting the doctest module that users
-            # of coverage will get.  Deleting the imported module here is
-            # enough: when the test imports doctest again, it will get a fresh
-            # copy without the monkeypatch.
-            del sys.modules['doctest']
+        # Oh, the irony!  This test case exists because Python 2.4's
+        # doctest module doesn't play well with coverage.  But nose fixes
+        # the problem by monkeypatching doctest.  I want to undo the
+        # monkeypatch to be sure I'm getting the doctest module that users
+        # of coverage will get.  Deleting the imported module here is
+        # enough: when the test imports doctest again, it will get a fresh
+        # copy without the monkeypatch.
+        del sys.modules['doctest']
 
-        def test_doctest(self):
-            self.check_coverage('''\
-                def return_arg_or_void(arg):
-                    """If <arg> is None, return "Void"; otherwise return <arg>
+    def test_doctest(self):
+        self.check_coverage('''\
+            def return_arg_or_void(arg):
+                """If <arg> is None, return "Void"; otherwise return <arg>
 
-                    >>> return_arg_or_void(None)
-                    'Void'
-                    >>> return_arg_or_void("arg")
-                    'arg'
-                    >>> return_arg_or_void("None")
-                    'None'
-                    """
-                    if arg is None:
-                        return "Void"
-                    else:
-                        return arg
+                >>> return_arg_or_void(None)
+                'Void'
+                >>> return_arg_or_void("arg")
+                'arg'
+                >>> return_arg_or_void("None")
+                'None'
+                """
+                if arg is None:
+                    return "Void"
+                else:
+                    return arg
 
-                import doctest, sys
-                doctest.testmod(sys.modules[__name__])  # we're not __main__ :(
-                ''',
-                [1,11,12,14,16,17], "")
+            import doctest, sys
+            doctest.testmod(sys.modules[__name__])  # we're not __main__ :(
+            ''',
+            [1,11,12,14,16,17], "")
 
 
 if hasattr(sys, 'gettrace'):

tests/test_phystokens.py

 
         run_in_temp_dir = False
 
-        if sys.version_info >= (2,4):
-            default_encoding = 'ascii'
-        else:
-            default_encoding = 'iso-8859-1'
-
         def test_detect_source_encoding(self):
             # Various forms from http://www.python.org/dev/peps/pep-0263/
             source = "# coding=cp850\n\n"
         def test_dont_detect_source_encoding_on_third_line(self):
             # A coding declaration doesn't count on the third line.
             source = "\n\n# coding=cp850\n\n"
-            self.assertEqual(source_encoding(source), self.default_encoding)
+            self.assertEqual(source_encoding(source), 'ascii')
 
         def test_detect_source_encoding_of_empty_file(self):
             # An important edge case.
-            self.assertEqual(source_encoding(""), self.default_encoding)
+            self.assertEqual(source_encoding(""), 'ascii')
 
         def test_bom(self):
             # A BOM means utf-8.

tests/test_process.py

         out_py = self.run_command("python run_me.py")
         self.assertMultiLineEqual(out_cov, out_py)
 
-    if sys.version_info >= (2, 6):
-        # Doesn't work in 2.5, and I don't care! For some reason, python -m
-        # in 2.5 has __builtins__ as a dictionary instead of a module?
-        def test_coverage_run_dashm_is_like_python_dashm(self):
-            # These -m commands assume the coverage tree is on the path.
-            out_cov = self.run_command("coverage run -m tests.try_execfile")
-            out_py = self.run_command("python -m tests.try_execfile")
-            self.assertMultiLineEqual(out_cov, out_py)
+    def test_coverage_run_dashm_is_like_python_dashm(self):
+        # These -m commands assume the coverage tree is on the path.
+        out_cov = self.run_command("coverage run -m tests.try_execfile")
+        out_py = self.run_command("python -m tests.try_execfile")
+        self.assertMultiLineEqual(out_cov, out_py)
 
-        def test_coverage_run_dashm_is_like_python_dashm_off_path(self):
-            # https://bitbucket.org/ned/coveragepy/issue/242
-            tryfile = os.path.join(here, "try_execfile.py")
-            self.make_file("sub/__init__.py", "")
-            self.make_file("sub/run_me.py", open(tryfile).read())
-            out_cov = self.run_command("coverage run -m sub.run_me")
-            out_py = self.run_command("python -m sub.run_me")
-            self.assertMultiLineEqual(out_cov, out_py)
+    def test_coverage_run_dashm_is_like_python_dashm_off_path(self):
+        # https://bitbucket.org/ned/coveragepy/issue/242
+        tryfile = os.path.join(here, "try_execfile.py")
+        self.make_file("sub/__init__.py", "")
+        self.make_file("sub/run_me.py", open(tryfile).read())
+        out_cov = self.run_command("coverage run -m sub.run_me")
+        out_py = self.run_command("python -m sub.run_me")
+        self.assertMultiLineEqual(out_cov, out_py)
 
     if sys.version_info >= (2, 7):
         # Coverage isn't bug-for-bug compatible in the behavior of -m for
 # and then run "tox" from this directory.
 
 [tox]
-envlist = py25, py26, py27, py31, py32, py33, pypy
+envlist = py26, py27, py32, py33, pypy
 
 [testenv]
 commands =