summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2022-12-27 07:04:26 -0500
committerNed Batchelder <ned@nedbatchelder.com>2022-12-27 07:24:44 -0500
commit9f7d19540e8a716279284f19a6a324311649b98e (patch)
tree6563c3360f24a0945b8bac7e6bc22ba16e99918e
parent5af6270dd72f2a217823a32bf7141d3f7c1a2a92 (diff)
downloadpython-coveragepy-git-9f7d19540e8a716279284f19a6a324311649b98e.tar.gz
refactor: remove more of the PyContracts stuff
-rw-r--r--coverage/env.py1
-rw-r--r--coverage/misc.py10
-rw-r--r--coverage/parser.py3
-rw-r--r--tests/test_misc.py55
4 files changed, 7 insertions, 62 deletions
diff --git a/coverage/env.py b/coverage/env.py
index 96143dc7..19eb5530 100644
--- a/coverage/env.py
+++ b/coverage/env.py
@@ -135,7 +135,6 @@ METACOV = os.getenv('COVERAGE_COVERAGE', '') != ''
# test-specific behavior like contracts.
TESTING = os.getenv('COVERAGE_TESTING', '') == 'True'
-USE_CONTRACTS = False
def debug_info():
"""Return a list of (name, value) pairs for printing debug information."""
diff --git a/coverage/misc.py b/coverage/misc.py
index 34b743dc..fe59ef6d 100644
--- a/coverage/misc.py
+++ b/coverage/misc.py
@@ -91,18 +91,16 @@ def import_third_party(modname):
return None
-def dummy_decorator_with_args(*args_unused, **kwargs_unused):
+# We don't use PyContracts anymore, but the @contracts decorators will be
+# useful info when it comes time to add type annotations, so keep them as
+# dummies for now.
+def contract(*args_unused, **kwargs_unused):
"""Dummy no-op implementation of a decorator with arguments."""
def _decorator(func):
return func
return _decorator
-# We aren't using real PyContracts, so just define our decorators as
-# stunt-double no-ops.
-contract = dummy_decorator_with_args
-one_of = dummy_decorator_with_args
-
def new_contract(*args_unused, **kwargs_unused):
"""Dummy no-op implementation of `new_contract`."""
pass
diff --git a/coverage/parser.py b/coverage/parser.py
index 1bf1951a..044839d8 100644
--- a/coverage/parser.py
+++ b/coverage/parser.py
@@ -14,7 +14,7 @@ from coverage import env
from coverage.bytecode import code_objects
from coverage.debug import short_stack
from coverage.exceptions import NoSource, NotPython, _StopEverything
-from coverage.misc import contract, join_regex, new_contract, nice_pair, one_of
+from coverage.misc import contract, join_regex, new_contract, nice_pair
from coverage.phystokens import generate_tokens
@@ -778,7 +778,6 @@ class AstArcAnalyzer:
# Default for simple statements: one exit from this node.
return {ArcStart(self.line_for_node(node))}
- @one_of("from_start, prev_starts")
@contract(returns='ArcStarts')
def add_body_arcs(self, body, from_start=None, prev_starts=None):
"""Add arcs for the body of a compound statement.
diff --git a/tests/test_misc.py b/tests/test_misc.py
index bdee2b50..4fd3f7c7 100644
--- a/tests/test_misc.py
+++ b/tests/test_misc.py
@@ -7,10 +7,9 @@ import sys
import pytest
-from coverage import env
from coverage.exceptions import CoverageException
-from coverage.misc import contract, dummy_decorator_with_args, file_be_gone
-from coverage.misc import Hasher, one_of, substitute_variables, import_third_party
+from coverage.misc import file_be_gone
+from coverage.misc import Hasher, substitute_variables, import_third_party
from coverage.misc import human_sorted, human_sorted_items
from tests.coveragetest import CoverageTest
@@ -80,56 +79,6 @@ class RemoveFileTest(CoverageTest):
file_be_gone(".")
-@pytest.mark.skipif(not env.USE_CONTRACTS, reason="Contracts are disabled, can't test them")
-class ContractTest(CoverageTest):
- """Tests of our contract decorators."""
-
- run_in_temp_dir = False
-
- def test_bytes(self):
- @contract(text='bytes|None')
- def need_bytes(text=None):
- return text
-
- assert need_bytes(b"Hey") == b"Hey"
- assert need_bytes() is None
- with pytest.raises(Exception):
- need_bytes("Oops")
-
- def test_unicode(self):
- @contract(text='unicode|None')
- def need_unicode(text=None):
- return text
-
- assert need_unicode("Hey") == "Hey"
- assert need_unicode() is None
- with pytest.raises(Exception):
- need_unicode(b"Oops")
-
- def test_one_of(self):
- @one_of("a, b, c")
- def give_me_one(a=None, b=None, c=None):
- return (a, b, c)
-
- assert give_me_one(a=17) == (17, None, None)
- assert give_me_one(b=set()) == (None, set(), None)
- assert give_me_one(c=17) == (None, None, 17)
- with pytest.raises(AssertionError):
- give_me_one(a=17, b=set())
- with pytest.raises(AssertionError):
- give_me_one()
-
- def test_dummy_decorator_with_args(self):
- @dummy_decorator_with_args("anything", this=17, that="is fine")
- def undecorated(a=None, b=None):
- return (a, b)
-
- assert undecorated() == (None, None)
- assert undecorated(17) == (17, None)
- assert undecorated(b=23) == (None, 23)
- assert undecorated(b=42, a=3) == (3, 42)
-
-
VARS = {
'FOO': 'fooey',
'BAR': 'xyzzy',