From 3240e331e8e6fb5cf56991d28c5279138df2466e Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Wed, 13 Jun 2018 07:57:18 -0400 Subject: Make version checking more uniform --- coverage/config.py | 4 ++-- coverage/execfile.py | 9 +++++---- coverage/multiproc.py | 6 +++--- tests/test_farm.py | 2 +- tests/test_parser.py | 2 +- tests/test_process.py | 4 ++-- 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/coverage/config.py b/coverage/config.py index 285cb21..effa382 100644 --- a/coverage/config.py +++ b/coverage/config.py @@ -6,8 +6,8 @@ import collections import os import re -import sys +from coverage import env from coverage.backward import configparser, iitems, string_class from coverage.misc import contract, CoverageException, isolate_module @@ -33,7 +33,7 @@ class HandyConfigParser(configparser.RawConfigParser): def read(self, filenames): """Read a file name as UTF-8 configuration data.""" kwargs = {} - if sys.version_info >= (3, 2): + if env.PYVERSION >= (3, 2): kwargs['encoding'] = "utf-8" return configparser.RawConfigParser.read(self, filenames, **kwargs) diff --git a/coverage/execfile.py b/coverage/execfile.py index a72cb71..68417f8 100644 --- a/coverage/execfile.py +++ b/coverage/execfile.py @@ -9,6 +9,7 @@ import struct import sys import types +from coverage import env from coverage.backward import BUILTINS from coverage.backward import PYC_MAGIC_NUMBER, imp, importlib_util_find_spec from coverage.misc import CoverageException, ExceptionDuringRun, NoCode, NoSource, isolate_module @@ -115,7 +116,7 @@ def run_python_module(modulename, args): # used to be an empty string (meaning the current directory). It changed # to be the actual path to the current directory, so that os.chdir wouldn't # affect the outcome. - if sys.version_info >= (3, 7, 0, 'beta', 3): + if env.PYVERSION >= (3, 7, 0, 'beta', 3): path0 = os.getcwd() else: path0 = "" @@ -136,7 +137,7 @@ def run_python_file(filename, args, package=None, modulename=None, path0=None): function will decide on a value. """ - if modulename is None and sys.version_info >= (3, 3): + if modulename is None and env.PYVERSION >= (3, 3): modulename = '__main__' # Create a module to serve as __main__ @@ -263,7 +264,7 @@ def make_code_from_pyc(filename): raise NoCode("Bad magic number in .pyc file") date_based = True - if sys.version_info >= (3, 7, 0, 'alpha', 4): + if env.PYVERSION >= (3, 7, 0, 'alpha', 4): flags = struct.unpack('= (3, 3): + if env.PYVERSION >= (3, 3): # 3.3 added another long to the header (size), skip it. fpyc.read(4) diff --git a/coverage/multiproc.py b/coverage/multiproc.py index 93b3155..bbc88fb 100644 --- a/coverage/multiproc.py +++ b/coverage/multiproc.py @@ -6,8 +6,8 @@ import multiprocessing import multiprocessing.process import os -import sys +from coverage import env from coverage.misc import contract # An attribute that will be set on the module to indicate that it has been @@ -15,7 +15,7 @@ from coverage.misc import contract PATCHED_MARKER = "_coverage$patched" -if sys.version_info >= (3, 4): +if env.PYVERSION >= (3, 4): OriginalProcess = multiprocessing.process.BaseProcess else: OriginalProcess = multiprocessing.Process @@ -70,7 +70,7 @@ def patch_multiprocessing(rcfile): if hasattr(multiprocessing, PATCHED_MARKER): return - if sys.version_info >= (3, 4): + if env.PYVERSION >= (3, 4): OriginalProcess._bootstrap = ProcessWithCoverage._bootstrap else: multiprocessing.Process = ProcessWithCoverage diff --git a/tests/test_farm.py b/tests/test_farm.py index 8368126..4fc0ea5 100644 --- a/tests/test_farm.py +++ b/tests/test_farm.py @@ -36,7 +36,7 @@ def test_farm(filename): # "rU" was deprecated in 3.4 -READ_MODE = "rU" if sys.version_info < (3, 4) else "r" +READ_MODE = "rU" if env.PYVERSION < (3, 4) else "r" class FarmTestCase(ModuleAwareMixin, SysPathAwareMixin, unittest.TestCase): diff --git a/tests/test_parser.py b/tests/test_parser.py index 034e9aa..169319f 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -200,7 +200,7 @@ class PythonParserTest(CoverageTest): expected_arcs = set(self.arcz_to_arcs(".1 14 48 8. .2 2. -8A A-8")) expected_exits = {1: 1, 2: 1, 4: 1, 8: 1, 10: 1} if env.PYVERSION >= (3, 7, 0, 'beta', 5): - # 3.7 changed how functions with only docstrings were numbered. + # 3.7 changed how functions with only docstrings are numbered. expected_arcs.update(set(self.arcz_to_arcs("-46 6-4"))) expected_exits.update({6: 1}) self.assertEqual(parser.arcs(), expected_arcs) diff --git a/tests/test_process.py b/tests/test_process.py index f0b1cde..7e55c77 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -659,7 +659,7 @@ class ProcessTest(CoverageTest): self.assertGreater(data.line_counts()['os.py'], 50) def test_lang_c(self): - if env.PY3 and sys.version_info < (3, 4): + if env.PY3 and env.PYVERSION < (3, 4): # Python 3.3 can't compile the non-ascii characters in the file name. self.skipTest("3.3 can't handle this test") if env.JYTHON: @@ -768,7 +768,7 @@ class EnvironmentTest(CoverageTest): self.assert_tryexecfile_output(out_cov, out_py) def test_coverage_run_dir_is_like_python_dir(self): - if sys.version_info == (3, 5, 4, 'final', 0): # pragma: obscure + if env.PYVERSION == (3, 5, 4, 'final', 0): # pragma: obscure self.skipTest("3.5.4 broke this: https://bugs.python.org/issue32551") with open(TRY_EXECFILE) as f: self.make_file("with_main/__main__.py", f.read()) -- cgit v1.2.1