From c411cc843c6cb70620b16cbaf12a5a0610f27f21 Mon Sep 17 00:00:00 2001 From: Rodrigue Cloutier Date: Thu, 10 Dec 2015 10:22:06 -0500 Subject: Fix Windows support for multiprocessing monkey patch --HG-- branch : windows_multiprocessing_support --- coverage/monkey.py | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'coverage') diff --git a/coverage/monkey.py b/coverage/monkey.py index c4ec68c6..b896dbf5 100644 --- a/coverage/monkey.py +++ b/coverage/monkey.py @@ -11,6 +11,28 @@ import sys # monkey-patched. PATCHED_MARKER = "_coverage$patched" +if sys.version_info >= (3, 4): + + klass = multiprocessing.process.BaseProcess +else: + klass = multiprocessing.Process + +original_bootstrap = klass._bootstrap + + +class ProcessWithCoverage(klass): + """A replacement for multiprocess.Process that starts coverage.""" + def _bootstrap(self): + """Wrapper around _bootstrap to start coverage.""" + from coverage import Coverage + cov = Coverage(data_suffix=True) + cov.start() + try: + return original_bootstrap(self) + finally: + cov.stop() + cov.save() + def patch_multiprocessing(): """Monkey-patch the multiprocessing module. @@ -22,26 +44,6 @@ def patch_multiprocessing(): if hasattr(multiprocessing, PATCHED_MARKER): return - if sys.version_info >= (3, 4): - klass = multiprocessing.process.BaseProcess - else: - klass = multiprocessing.Process - - original_bootstrap = klass._bootstrap - - class ProcessWithCoverage(klass): - """A replacement for multiprocess.Process that starts coverage.""" - def _bootstrap(self): - """Wrapper around _bootstrap to start coverage.""" - from coverage import Coverage - cov = Coverage(data_suffix=True) - cov.start() - try: - return original_bootstrap(self) - finally: - cov.stop() - cov.save() - if sys.version_info >= (3, 4): klass._bootstrap = ProcessWithCoverage._bootstrap else: -- cgit v1.2.1 From 01ff52eba403dcfbd14c742ce1106931756469af Mon Sep 17 00:00:00 2001 From: Max Linke Date: Mon, 14 Dec 2015 11:27:12 +0100 Subject: Fix error with double occurence of encoding declaration If a file sets the encoding using both vim and emacs style we can't compile the source-code. This commit ensures that always both occurences are removed before we compile the source-code. --- coverage/phystokens.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'coverage') diff --git a/coverage/phystokens.py b/coverage/phystokens.py index b34b1c3b..5aa3402c 100644 --- a/coverage/phystokens.py +++ b/coverage/phystokens.py @@ -291,5 +291,5 @@ def compile_unicode(source, filename, mode): @contract(source='unicode', returns='unicode') def neuter_encoding_declaration(source): """Return `source`, with any encoding declaration neutered.""" - source = COOKIE_RE.sub("# (deleted declaration)", source, count=1) + source = COOKIE_RE.sub("# (deleted declaration)", source, count=2) return source -- cgit v1.2.1 From 26a49dc5ccb6465a3cdd7a2346c530ce4f88b0dd Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Thu, 24 Dec 2015 11:11:37 -0500 Subject: Non-ascii characters work again in config regexes. Fixes #455. --- coverage/parser.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'coverage') diff --git a/coverage/parser.py b/coverage/parser.py index 7b8a60f1..884d40cb 100644 --- a/coverage/parser.py +++ b/coverage/parser.py @@ -9,6 +9,7 @@ import re import token import tokenize +from coverage import env from coverage.backward import range # pylint: disable=redefined-builtin from coverage.backward import bytes_to_ints from coverage.bytecode import ByteCodes, CodeObjects @@ -95,7 +96,10 @@ class PythonParser(object): part of it. """ - regex_c = re.compile(join_regex(regexes)) + combined = join_regex(regexes) + if env.PY2: + combined = combined.decode("utf8") + regex_c = re.compile(combined) matches = set() for i, ltext in enumerate(self.lines, start=1): if regex_c.search(ltext): -- cgit v1.2.1