summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/helpers.py11
-rw-r--r--tests/test_arcs.py21
-rw-r--r--tests/test_concurrency.py8
-rw-r--r--tests/test_context.py15
-rw-r--r--tests/test_coverage.py15
-rw-r--r--tests/test_html.py2
-rw-r--r--tests/test_oddball.py1
-rw-r--r--tests/test_parser.py2
-rw-r--r--tests/test_phystokens.py5
-rw-r--r--tests/test_process.py17
-rw-r--r--tests/test_summary.py9
11 files changed, 11 insertions, 95 deletions
diff --git a/tests/helpers.py b/tests/helpers.py
index daed3d1a..93583b8b 100644
--- a/tests/helpers.py
+++ b/tests/helpers.py
@@ -10,13 +10,10 @@ import os
import os.path
import re
import subprocess
-import sys
import textwrap
import mock
-from coverage import env
-from coverage.backward import unicode_class
from coverage.misc import output_encoding
@@ -26,9 +23,6 @@ def run_command(cmd):
Returns the exit status code and the combined stdout and stderr.
"""
- if env.PY2 and isinstance(cmd, unicode_class):
- cmd = cmd.encode(sys.getfilesystemencoding())
-
# In some strange cases (PyPy3 in a virtualenv!?) the stdout encoding of
# the subprocess is set incorrectly to ascii. Use an environment variable
# to force the encoding to be the same as ours.
@@ -76,10 +70,7 @@ def make_file(filename, text="", bytes=b"", newline=None):
text = textwrap.dedent(text)
if newline:
text = text.replace("\n", newline)
- if env.PY3:
- data = text.encode('utf8')
- else:
- data = text
+ data = text.encode('utf8')
# Make sure the directories are available.
dirs, _ = os.path.split(filename)
diff --git a/tests/test_arcs.py b/tests/test_arcs.py
index 83e9e6b1..3f634a85 100644
--- a/tests/test_arcs.py
+++ b/tests/test_arcs.py
@@ -294,10 +294,8 @@ class LoopArcTest(CoverageTest):
arcz = ".1 12 23 34 45 36 62 57 7."
elif env.PYBEHAVIOR.nix_while_true:
arcz = ".1 13 34 45 36 63 57 7."
- elif env.PY3:
- arcz = ".1 12 23 34 45 36 63 57 7."
else:
- arcz = ".1 12 23 34 45 36 62 57 7."
+ arcz = ".1 12 23 34 45 36 63 57 7."
self.check_coverage("""\
a, i = 1, 0
while True:
@@ -338,10 +336,8 @@ class LoopArcTest(CoverageTest):
arcz = ".1 12 23 34 45 52 46 67 7."
elif env.PYBEHAVIOR.nix_while_true:
arcz = ".1 13 34 45 53 46 67 7."
- elif env.PY3:
- arcz = ".1 12 23 34 45 53 46 67 7."
else:
- arcz = ".1 12 23 34 45 52 46 67 7."
+ arcz = ".1 12 23 34 45 53 46 67 7."
self.check_coverage("""\
up = iter('ta')
while True:
@@ -413,11 +409,6 @@ class LoopArcTest(CoverageTest):
)
def test_confusing_for_loop_bug_175(self):
- if env.PY3:
- # Py3 counts the list comp as a separate code object.
- arcz = ".1 -22 2-2 12 23 34 45 53 3."
- else:
- arcz = ".1 12 23 34 45 53 3."
self.check_coverage("""\
o = [(1,2), (3,4)]
o = [a for a in o]
@@ -425,19 +416,15 @@ class LoopArcTest(CoverageTest):
x = tup[0]
y = tup[1]
""",
- arcz=arcz,
+ arcz=".1 -22 2-2 12 23 34 45 53 3.",
)
- if env.PY3:
- arcz = ".1 12 -22 2-2 23 34 42 2."
- else:
- arcz = ".1 12 23 34 42 2."
self.check_coverage("""\
o = [(1,2), (3,4)]
for tup in [a for a in o]:
x = tup[0]
y = tup[1]
""",
- arcz=arcz,
+ arcz=".1 12 -22 2-2 23 34 42 2.",
)
def test_generator_expression(self):
diff --git a/tests/test_concurrency.py b/tests/test_concurrency.py
index 54e50014..fa482f91 100644
--- a/tests/test_concurrency.py
+++ b/tests/test_concurrency.py
@@ -146,13 +146,7 @@ PRINT_SUM_RANGE = """
"""
# Import the things to use threads.
-if env.PY2:
- THREAD = """
- import threading
- import Queue as queue
- """
-else:
- THREAD = """
+THREAD = """
import threading
import queue
"""
diff --git a/tests/test_context.py b/tests/test_context.py
index f51befae..688d5cce 100644
--- a/tests/test_context.py
+++ b/tests/test_context.py
@@ -6,10 +6,7 @@
import inspect
import os.path
-import pytest
-
import coverage
-from coverage import env
from coverage.context import qualname_from_frame
from coverage.data import CoverageData
@@ -237,13 +234,6 @@ def fake_out(self):
def patch_meth(self):
return get_qualname()
-class OldStyle:
- def meth(self):
- return get_qualname()
-
-class OldChild(OldStyle):
- pass
-
# pylint: enable=missing-class-docstring, missing-function-docstring, unused-argument
@@ -281,11 +271,6 @@ class QualnameTest(CoverageTest):
c.meth = patch_meth
assert c.meth(c) == "tests.test_context.patch_meth"
- @pytest.mark.skipif(not env.PY2, reason="Old-style classes are only in Python 2")
- def test_oldstyle(self):
- assert OldStyle().meth() == "tests.test_context.OldStyle.meth"
- assert OldChild().meth() == "tests.test_context.OldStyle.meth"
-
def test_bug_829(self):
# A class with a name like a function shouldn't confuse qualname_from_frame.
class test_something(object): # pylint: disable=unused-variable
diff --git a/tests/test_coverage.py b/tests/test_coverage.py
index 6cec3dd7..559c42a6 100644
--- a/tests/test_coverage.py
+++ b/tests/test_coverage.py
@@ -343,20 +343,6 @@ class SimpleStatementTest(CoverageTest):
""",
[1,2,3,6,9], "")
- @pytest.mark.skipif(env.PY3, reason="No more print statement in Python 3.")
- def test_print(self):
- self.check_coverage("""\
- print "hello, world!"
- print ("hey: %d" %
- 17)
- print "goodbye"
- print "hello, world!",
- print ("hey: %d" %
- 17),
- print "goodbye",
- """,
- [1,2,4,5,6,8], "")
-
def test_raise(self):
self.check_coverage("""\
try:
@@ -484,7 +470,6 @@ class SimpleStatementTest(CoverageTest):
""",
lines=lines, missing=missing)
- @pytest.mark.skipif(env.PY2, reason="Expected failure: peephole optimization of jumps to jumps")
def test_strange_unexecuted_continue(self):
# Peephole optimization of jumps to jumps can mean that some statements
# never hit the line tracer. The behavior is different in different
diff --git a/tests/test_html.py b/tests/test_html.py
index 5b0e0345..c0413c5a 100644
--- a/tests/test_html.py
+++ b/tests/test_html.py
@@ -1041,8 +1041,6 @@ assert len(math) == 18
def test_unicode(self):
surrogate = u"\U000e0100"
- if env.PY2:
- surrogate = surrogate.encode('utf-8')
self.make_file("unicode.py", """\
# -*- coding: utf-8 -*-
diff --git a/tests/test_oddball.py b/tests/test_oddball.py
index da0531f1..a63719ea 100644
--- a/tests/test_oddball.py
+++ b/tests/test_oddball.py
@@ -550,7 +550,6 @@ class ExecTest(CoverageTest):
assert statements == [31]
assert missing == []
- @pytest.mark.skipif(env.PY2, reason="Python 2 can't seem to compile the file.")
def test_unencodable_filename(self):
# https://github.com/nedbat/coveragepy/issues/891
self.make_file("bug891.py", r"""exec(compile("pass", "\udcff.py", "exec"))""")
diff --git a/tests/test_parser.py b/tests/test_parser.py
index f49c9900..64839572 100644
--- a/tests/test_parser.py
+++ b/tests/test_parser.py
@@ -22,8 +22,6 @@ class PythonParserTest(CoverageTest):
def parse_source(self, text):
"""Parse `text` as source, and return the `PythonParser` used."""
- if env.PY2:
- text = text.decode("ascii")
text = textwrap.dedent(text)
parser = PythonParser(text=text, exclude="nocover")
parser.parse_source()
diff --git a/tests/test_phystokens.py b/tests/test_phystokens.py
index 86b1fdbe..76b545e1 100644
--- a/tests/test_phystokens.py
+++ b/tests/test_phystokens.py
@@ -104,10 +104,7 @@ class PhysTokensTest(CoverageTest):
# The default encoding is different in Python 2 and Python 3.
-if env.PY3:
- DEF_ENCODING = "utf-8"
-else:
- DEF_ENCODING = "ascii"
+DEF_ENCODING = "utf-8"
ENCODING_DECLARATION_SOURCES = [
diff --git a/tests/test_process.py b/tests/test_process.py
index 9b451228..a73c650f 100644
--- a/tests/test_process.py
+++ b/tests/test_process.py
@@ -22,7 +22,6 @@ import coverage
from coverage import env
from coverage.data import line_counts
from coverage.files import abs_file, python_reported_file
-from coverage.misc import output_encoding
from tests.coveragetest import CoverageTest, TESTS_DIR
from tests.helpers import change_dir, make_file, nice_file, re_lines, run_command
@@ -734,7 +733,6 @@ class ProcessTest(CoverageTest):
@pytest.mark.expensive
@pytest.mark.skipif(env.METACOV, reason="Can't test fullcoverage when measuring ourselves")
- @pytest.mark.skipif(env.PY2, reason="fullcoverage doesn't work on Python 2.")
@pytest.mark.skipif(not env.C_TRACER, reason="fullcoverage only works with the C tracer.")
def test_fullcoverage(self):
# fullcoverage is a trick to get stdlib modules measured from
@@ -899,15 +897,8 @@ class EnvironmentTest(CoverageTest):
expected = self.run_command("python -m with_main")
actual = self.run_command("coverage run -m with_main")
- if env.PY2:
- assert expected.endswith("No module named with_main\n")
- assert actual.endswith("No module named with_main\n")
- else:
- self.assert_tryexecfile_output(expected, actual)
+ self.assert_tryexecfile_output(expected, actual)
- @pytest.mark.skipif(env.PY2,
- reason="Python 2 runs __main__ twice, I can't be bothered to make it work."
- )
def test_coverage_run_dashm_dir_with_init_is_like_python(self):
with open(TRY_EXECFILE) as f:
self.make_file("with_main/__main__.py", f.read())
@@ -1313,9 +1304,6 @@ class UnicodeFilePathsTest(CoverageTest):
u"TOTAL 1 0 100%\n"
)
- if env.PY2:
- report_expected = report_expected.encode(output_encoding())
-
out = self.run_command("coverage report")
assert out == report_expected
@@ -1359,9 +1347,6 @@ class UnicodeFilePathsTest(CoverageTest):
u"TOTAL 1 0 100%%\n"
) % os.sep
- if env.PY2:
- report_expected = report_expected.encode(output_encoding())
-
out = self.run_command("coverage report")
assert out == report_expected
diff --git a/tests/test_summary.py b/tests/test_summary.py
index 13daca14..b6405bff 100644
--- a/tests/test_summary.py
+++ b/tests/test_summary.py
@@ -13,11 +13,11 @@ import re
import pytest
import coverage
-from coverage import env
from coverage.backward import StringIO
+from coverage import env
from coverage.control import Coverage
from coverage.data import CoverageData
-from coverage.misc import CoverageException, output_encoding
+from coverage.misc import CoverageException
from coverage.summary import SummaryReporter
from tests.coveragetest import CoverageTest, TESTS_DIR, UsingModulesMixin
@@ -585,8 +585,6 @@ class SummaryTest(UsingModulesMixin, CoverageTest):
# The actual error message varies version to version
errmsg = re.sub(r": '.*' at", ": 'error' at", errmsg)
expected = u"Couldn't parse 'accented\xe2.py' as Python source: 'error' at line 1"
- if env.PY2:
- expected = expected.encode(output_encoding())
assert expected == errmsg
def test_dotpy_not_python_ignored(self):
@@ -745,7 +743,6 @@ class SummaryTest(UsingModulesMixin, CoverageTest):
report = self.get_report(cov).splitlines()
assert "mod.py 1 0 100%" in report
- @pytest.mark.skipif(env.PYPY2, reason="PyPy2 doesn't run bare .pyc files")
def test_missing_py_file_during_run(self):
# Create two Python files.
self.make_file("mod.py", "a = 1\n")
@@ -758,7 +755,7 @@ class SummaryTest(UsingModulesMixin, 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 env.PY3 and not env.JYTHON:
+ if not env.JYTHON:
pycs = glob.glob("__pycache__/mod.*.pyc")
assert len(pycs) == 1
os.rename(pycs[0], "mod.pyc")