summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2017-01-18 22:52:10 -0500
committerNed Batchelder <ned@nedbatchelder.com>2017-01-18 22:52:10 -0500
commit8dba481b188f4df23074816f9fa8c32a488482e6 (patch)
tree94df16d98906e0574277b670a6454d04af9a5ff0
parent1a6b57d7d181ba4d8eb6098aab7c58670db69ea9 (diff)
downloadpython-coveragepy-git-8dba481b188f4df23074816f9fa8c32a488482e6.tar.gz
No test failures on Jython
One or two of these are questionable accommodations, but there are no failures.
-rw-r--r--tests/test_arcs.py7
-rw-r--r--tests/test_concurrency.py3
-rw-r--r--tests/test_oddball.py10
-rw-r--r--tests/test_process.py22
-rw-r--r--tests/test_summary.py16
-rw-r--r--tox.ini2
6 files changed, 48 insertions, 12 deletions
diff --git a/tests/test_arcs.py b/tests/test_arcs.py
index c1fd35b6..de59bf21 100644
--- a/tests/test_arcs.py
+++ b/tests/test_arcs.py
@@ -143,10 +143,17 @@ class SimpleArcTest(CoverageTest):
)
def test_what_is_the_sound_of_no_lines_clapping(self):
+ if env.JYTHON:
+ # Jython reports no lines for an empty file.
+ arcz_missing=".1 1." # pragma: only jython
+ else:
+ # Other Pythons report one line.
+ arcz_missing=""
self.check_coverage("""\
# __init__.py
""",
arcz=".1 1.",
+ arcz_missing=arcz_missing,
)
diff --git a/tests/test_concurrency.py b/tests/test_concurrency.py
index f2aa7977..0a9fca0d 100644
--- a/tests/test_concurrency.py
+++ b/tests/test_concurrency.py
@@ -49,6 +49,9 @@ def measurable_line(l):
return False
if l.startswith('else:'):
return False
+ if env.JYTHON and l.startswith(('try:', 'except:', 'except ', 'break', 'with ')):
+ # Jython doesn't measure these statements.
+ return False # pragma: only jython
return True
diff --git a/tests/test_oddball.py b/tests/test_oddball.py
index c617cf42..fe841bd5 100644
--- a/tests/test_oddball.py
+++ b/tests/test_oddball.py
@@ -231,6 +231,9 @@ class PyexpatTest(CoverageTest):
"""Pyexpat screws up tracing. Make sure we've counter-defended properly."""
def test_pyexpat(self):
+ if env.JYTHON:
+ self.skipTest("Pyexpat isn't a problem on Jython")
+
# pyexpat calls the trace function explicitly (inexplicably), and does
# it wrong for exceptions. Parsing a DOCTYPE for some reason throws
# an exception internally, and triggers its wrong behavior. This test
@@ -381,6 +384,13 @@ class ExceptionTest(CoverageTest):
lines = data.lines(abs_file(filename))
clean_lines[filename] = sorted(lines)
+ if env.JYTHON: # pragma: only jython
+ # Jython doesn't report on try or except lines, so take those
+ # out of the expected lines.
+ invisible = [202, 206, 302, 304]
+ for lines in lines_expected.values():
+ lines[:] = [l for l in lines if l not in invisible]
+
self.assertEqual(clean_lines, lines_expected)
diff --git a/tests/test_process.py b/tests/test_process.py
index debd0d79..6c5be713 100644
--- a/tests/test_process.py
+++ b/tests/test_process.py
@@ -1095,7 +1095,7 @@ class UnicodeFilePathsTest(CoverageTest):
def setUp(self):
super(UnicodeFilePathsTest, self).setUp()
if env.JYTHON:
- self.skipTest("Jython 2 doesn't like accented file names")
+ self.skipTest("Jython doesn't like accented file names")
def test_accented_dot_py(self):
# Make a file with a non-ascii character in the filename.
@@ -1237,8 +1237,9 @@ class ProcessStartupTest(ProcessCoverageMixin, CoverageTest):
""")
# sub.py will write a few lines.
self.make_file("sub.py", """\
- with open("out.txt", "w") as f:
- f.write("Hello, world!\\n")
+ f = open("out.txt", "w")
+ f.write("Hello, world!\\n")
+ f.close()
""")
def test_subprocess_with_pth_files(self): # pragma: not covered
@@ -1266,7 +1267,7 @@ class ProcessStartupTest(ProcessCoverageMixin, CoverageTest):
self.assert_exists(".mycovdata")
data = coverage.CoverageData()
data.read_file(".mycovdata")
- self.assertEqual(data.line_counts()['sub.py'], 2)
+ self.assertEqual(data.line_counts()['sub.py'], 3)
def test_subprocess_with_pth_files_and_parallel(self): # pragma: not covered
# https://bitbucket.org/ned/coveragepy/issues/492/subprocess-coverage-strange-detection-of
@@ -1290,7 +1291,7 @@ class ProcessStartupTest(ProcessCoverageMixin, CoverageTest):
self.assert_exists(".coverage")
data = coverage.CoverageData()
data.read_file(".coverage")
- self.assertEqual(data.line_counts()['sub.py'], 2)
+ self.assertEqual(data.line_counts()['sub.py'], 3)
# assert that there are *no* extra data files left over after a combine
data_files = glob.glob(os.getcwd() + '/.coverage*')
@@ -1347,14 +1348,17 @@ class ProcessStartupWithSourceTest(ProcessCoverageMixin, CoverageTest):
# Main will run sub.py.
self.make_file(path("main.py"), """\
import %s
- if True: pass
+ a = 2
+ b = 3
""" % fullname('sub'))
if package:
self.make_file(path("__init__.py"), "")
# sub.py will write a few lines.
self.make_file(path("sub.py"), """\
- with open("out.txt", "w") as f:
- f.write("Hello, world!")
+ # Avoid 'with' so Jython can play along.
+ f = open("out.txt", "w")
+ f.write("Hello, world!")
+ f.close()
""")
self.make_file("coverage.ini", """\
[run]
@@ -1379,7 +1383,7 @@ class ProcessStartupWithSourceTest(ProcessCoverageMixin, CoverageTest):
data.read_file(".coverage")
summary = data.line_counts()
print(summary)
- self.assertEqual(summary[source + '.py'], 2)
+ self.assertEqual(summary[source + '.py'], 3)
self.assertEqual(len(summary), 1)
def test_dashm_main(self):
diff --git a/tests/test_summary.py b/tests/test_summary.py
index 5ba00389..53ecc9d6 100644
--- a/tests/test_summary.py
+++ b/tests/test_summary.py
@@ -13,6 +13,7 @@ import sys
import coverage
from coverage import env
+from coverage.backunittest import unittest
from coverage.backward import StringIO
from coverage.config import CoverageConfig
from coverage.control import Coverage
@@ -418,6 +419,9 @@ class SummaryTest(CoverageTest):
)
def test_accenteddotpy_not_python(self):
+ if env.JYTHON:
+ self.skipTest("Jython doesn't like accented file names")
+
# We run a .py file with a non-ascii name, and when reporting, we can't
# parse it as Python. We should get an error message in the report.
@@ -585,7 +589,7 @@ class SummaryTest(CoverageTest):
# Python 3 puts the .pyc files in a __pycache__ directory, and will
# not import from there without source. It will import a .pyc from
# the source location though.
- if not os.path.exists("mod.pyc"):
+ if env.PY3 and not env.JYTHON:
pycs = glob.glob("__pycache__/mod.*.pyc")
self.assertEqual(len(pycs), 1)
os.rename(pycs[0], "mod.pyc")
@@ -774,4 +778,12 @@ class TestSummaryReporterConfiguration(CoverageTest):
opts.from_args(sort='Xyzzy')
msg = "Invalid sorting option: 'Xyzzy'"
with self.assertRaisesRegex(CoverageException, msg):
- self.get_summary_text(data, opts)
+ try:
+ self.get_summary_text(data, opts)
+ except unittest.SkipTest:
+ # This is weird: it's because StopEverything derives from
+ # SkipTest and CoverageException. When we throw StopEverything,
+ # it's caught by the assertRaisesRegex, but the message is
+ # wrong. By catching SkipTest, and raising SkipTest, we get
+ # the behavior we wanted.
+ self.skipTest("No, really, skip...")
diff --git a/tox.ini b/tox.ini
index 4e0b9edd..b568d2db 100644
--- a/tox.ini
+++ b/tox.ini
@@ -2,7 +2,7 @@
# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
[tox]
-envlist = py{26,27,33,34,35,36}, pypy{2,3}, doc,lint
+envlist = py{26,27,33,34,35,36}, pypy{2,3}, jython, doc, lint
skip_missing_interpreters = True
[testenv]