diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2017-01-14 10:01:03 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2017-01-14 10:01:03 -0500 |
commit | e5c5b0eda9c000987ecafaa914ff1d0513b342ac (patch) | |
tree | df1bf4876796c426515009d4d42287abcd70c2d8 /coverage | |
parent | c9aa6917e8ae67640f14dcd302b30d2cbe234fa8 (diff) | |
download | python-coveragepy-git-e5c5b0eda9c000987ecafaa914ff1d0513b342ac.tar.gz |
Reporting doesn't work on Jython, so don't run reporting tests there.
--HG--
extra : amend_source : 144fd0ffb49fdef1139ae3f0085831ece14de43f
Diffstat (limited to 'coverage')
-rw-r--r-- | coverage/env.py | 5 | ||||
-rw-r--r-- | coverage/misc.py | 16 | ||||
-rw-r--r-- | coverage/parser.py | 8 | ||||
-rw-r--r-- | coverage/summary.py | 7 |
4 files changed, 29 insertions, 7 deletions
diff --git a/coverage/env.py b/coverage/env.py index 6db3b857..528c774a 100644 --- a/coverage/env.py +++ b/coverage/env.py @@ -4,6 +4,7 @@ """Determine facts about the environment.""" import os +import platform import sys # Operating systems. @@ -11,10 +12,12 @@ WINDOWS = sys.platform == "win32" LINUX = sys.platform == "linux2" # Python implementations. -PYPY = '__pypy__' in sys.builtin_module_names +PYPY = (platform.python_implementation() == 'PyPy') if PYPY: PYPYVERSION = sys.pypy_version_info +JYTHON = (platform.python_implementation() == 'Jython') + # Python versions. PYVERSION = sys.version_info PY2 = PYVERSION < (3, 0) diff --git a/coverage/misc.py b/coverage/misc.py index 5d330c6d..270c1468 100644 --- a/coverage/misc.py +++ b/coverage/misc.py @@ -10,6 +10,7 @@ import locale import os import sys import types +import unittest from coverage import env from coverage.backward import to_bytes, unicode_class @@ -264,3 +265,18 @@ class ExceptionDuringRun(CoverageException): """ pass + + +class StopEverything(unittest.SkipTest): + """An exception that means everything should stop. + + This derives from SkipTest so that tests that spring this trap will be + skipped automatically, without a lot of boilerplate all over the place. + + """ + pass + + +class IncapablePython(CoverageException, StopEverything): + """An operation is attempted that this version of Python cannot do.""" + pass diff --git a/coverage/parser.py b/coverage/parser.py index 540ad098..54603bf3 100644 --- a/coverage/parser.py +++ b/coverage/parser.py @@ -16,7 +16,7 @@ from coverage.backward import bytes_to_ints, string_class from coverage.bytecode import CodeObjects from coverage.debug import short_stack from coverage.misc import contract, new_contract, nice_pair, join_regex -from coverage.misc import CoverageException, NoSource, NotPython +from coverage.misc import NoSource, IncapablePython, NotPython from coverage.phystokens import compile_unicode, generate_tokens, neuter_encoding_declaration @@ -371,11 +371,11 @@ class ByteParser(object): # Alternative Python implementations don't always provide all the # attributes on code objects that we need to do the analysis. - for attr in ['co_lnotab', 'co_firstlineno', 'co_consts']: + for attr in ['co_lnotab', 'co_firstlineno']: if not hasattr(self.code, attr): - raise CoverageException( + raise IncapablePython( # pragma: only jython "This implementation of Python doesn't support code analysis.\n" - "Run coverage.py under CPython for this command." + "Run coverage.py under another Python for this command." ) def child_parsers(self): diff --git a/coverage/summary.py b/coverage/summary.py index d94ce8b2..271b648a 100644 --- a/coverage/summary.py +++ b/coverage/summary.py @@ -8,7 +8,7 @@ import sys from coverage import env from coverage.report import Reporter from coverage.results import Numbers -from coverage.misc import NotPython, CoverageException, output_encoding +from coverage.misc import NotPython, CoverageException, output_encoding, StopEverything class SummaryReporter(Reporter): @@ -55,13 +55,16 @@ class SummaryReporter(Reporter): skipped_count += 1 continue fr_analysis.append((fr, analysis)) + except StopEverything: + # Don't report this on single files, it's a systemic problem. + raise except Exception: report_it = not self.config.ignore_errors if report_it: typ, msg = sys.exc_info()[:2] # NotPython is only raised by PythonFileReporter, which has a # should_be_python() method. - if typ is NotPython and not fr.should_be_python(): + if issubclass(typ, NotPython) and not fr.should_be_python(): report_it = False if report_it: writeout(fmt_err % (fr.relative_filename(), typ.__name__, msg)) |