summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2017-01-13 07:11:04 -0500
committerNed Batchelder <ned@nedbatchelder.com>2017-01-13 07:11:04 -0500
commitd2e93d4f93373065230ae5f2d1b58338e5ba6819 (patch)
tree8b5173a76f2fe103f200b24d4377253bddaad41e
parentd82cef5f0bc3b56bb3dd4d473f098fa562b575e5 (diff)
downloadpython-coveragepy-d2e93d4f93373065230ae5f2d1b58338e5ba6819.tar.gz
Jython has no multiprocessing module
-rw-r--r--coverage/control.py11
-rw-r--r--metacov.ini1
-rw-r--r--tests/coveragetest.py3
-rw-r--r--tests/test_api.py2
-rw-r--r--tests/test_concurrency.py16
-rw-r--r--tox.ini4
6 files changed, 32 insertions, 5 deletions
diff --git a/coverage/control.py b/coverage/control.py
index 992ca58..037fc6d 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -24,7 +24,6 @@ from coverage.files import ModuleMatcher, abs_file
from coverage.html import HtmlReporter
from coverage.misc import CoverageException, bool_or_none, join_regex
from coverage.misc import file_be_gone, isolate_module
-from coverage.multiproc import patch_multiprocessing
from coverage.plugin import FileReporter
from coverage.plugin_support import Plugins
from coverage.python import PythonFileReporter
@@ -32,6 +31,12 @@ from coverage.results import Analysis, Numbers
from coverage.summary import SummaryReporter
from coverage.xmlreport import XmlReporter
+try:
+ from coverage.multiproc import patch_multiprocessing
+except ImportError: # pragma: only jython
+ # Jython has no multiprocessing module.
+ patch_multiprocessing = None
+
os = isolate_module(os)
# Pypy has some unusual stuff in the "stdlib". Consider those locations
@@ -229,6 +234,10 @@ class Coverage(object):
concurrency = self.config.concurrency or []
if "multiprocessing" in concurrency:
+ if not patch_multiprocessing:
+ raise CoverageException( # pragma: only jython
+ "multiprocessing is not supported on this Python"
+ )
patch_multiprocessing(rcfile=self.config_file)
# Multi-processing uses parallel for the subprocesses, so also use
# it for the main process.
diff --git a/metacov.ini b/metacov.ini
index 8170d6d..a16c6d6 100644
--- a/metacov.ini
+++ b/metacov.ini
@@ -19,6 +19,7 @@ exclude_lines =
raise AssertionError
pragma: debugging
pragma: only failure
+ pragma: only jython
partial_branches =
pragma: part covered
diff --git a/tests/coveragetest.py b/tests/coveragetest.py
index 539dd59..7ec623b 100644
--- a/tests/coveragetest.py
+++ b/tests/coveragetest.py
@@ -6,6 +6,7 @@
import contextlib
import datetime
import glob
+import itertools
import os
import random
import re
@@ -73,7 +74,7 @@ class CoverageTest(
# Also have to clean out the .pyc file, since the timestamp
# resolution is only one second, a changed file might not be
# picked up.
- for pyc in glob.glob('*.pyc'):
+ for pyc in itertools.chain(glob.glob('*.pyc'), glob.glob('*$py.class')):
os.remove(pyc)
if os.path.exists("__pycache__"):
shutil.rmtree("__pycache__")
diff --git a/tests/test_api.py b/tests/test_api.py
index 6f14210..9de83fb 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -35,7 +35,7 @@ class ApiTest(CoverageTest):
def assertFiles(self, files):
"""Assert that the files here are `files`, ignoring the usual junk."""
here = os.listdir(".")
- here = self.clean_files(here, ["*.pyc", "__pycache__"])
+ here = self.clean_files(here, ["*.pyc", "__pycache__", "*$py.class"])
self.assertCountEqual(here, files)
def test_unexecuted_file(self):
diff --git a/tests/test_concurrency.py b/tests/test_concurrency.py
index e36db30..b441909 100644
--- a/tests/test_concurrency.py
+++ b/tests/test_concurrency.py
@@ -3,7 +3,6 @@
"""Tests for concurrency libraries."""
-import multiprocessing
import threading
import coverage
@@ -16,6 +15,11 @@ from tests.coveragetest import CoverageTest
# These libraries aren't always available, we'll skip tests if they aren't.
try:
+ import multiprocessing
+except ImportError: # pragma: only jython
+ multiprocessing = None
+
+try:
import eventlet
except ImportError:
eventlet = None
@@ -25,7 +29,10 @@ try:
except ImportError:
gevent = None
-import greenlet
+try:
+ import greenlet
+except ImportError: # pragma: only jython
+ greenlet = None
def measurable_line(l):
@@ -345,6 +352,11 @@ MULTI_CODE = """
class MultiprocessingTest(CoverageTest):
"""Test support of the multiprocessing module."""
+ def setUp(self):
+ if not multiprocessing:
+ self.skip("No multiprocessing in this Python") # pragma: only jython
+ super(MultiprocessingTest, self).setUp()
+
def try_multiprocessing_code(
self, code, expected_out, the_module, concurrency="multiprocessing"
):
diff --git a/tox.ini b/tox.ini
index 46fb47f..fb8be65 100644
--- a/tox.ini
+++ b/tox.ini
@@ -28,6 +28,7 @@ install_command = python -m pip install -U {opts} {packages}
passenv = *
setenv =
pypy,pypy{2,3}: COVERAGE_NO_CTRACER=no C extension under PyPy
+ jython: COVERAGE_NO_CTRACER=no C extension under Jython
commands =
python setup.py --quiet clean develop
@@ -58,6 +59,9 @@ basepython = pypy2
[testenv:pypy3]
basepython = pypy3
+[testenv:jython]
+basepython = jython
+
[testenv:doc]
# Build the docs so we know if they are successful. We build twice: once with
# -q to get all warnings, and once with -QW to get a success/fail status