Skip to content

Commit

Permalink
Ignore certain PyCharm warnings in tests
Browse files Browse the repository at this point in the history
This patch makes the test files easier to edit by disabling false
positive warnings in PyCharm.
  • Loading branch information
mristin committed Jun 1, 2021
1 parent 5b409a4 commit 32f6ddf
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions tests/strategy_inference/test_strategy_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
SOME_GLOBAL_CONST = 0


# noinspection PyUnusedLocal,PyPep8Naming
class TestWithInferredStrategies(unittest.TestCase):
def test_fail_without_type_hints(self) -> None:
@icontract.require(lambda x: x > 0)
Expand All @@ -42,7 +43,7 @@ def some_func(x) -> None: # type: ignore
self.assertTrue(
re.match(
r"No search strategy could be inferred for the function: <function .*>; "
r"the following arguments are missing the type annotations: \['x'\]",
r"the following arguments are missing the type annotations: \['x']",
str(type_error),
),
str(type_error),
Expand Down Expand Up @@ -73,13 +74,13 @@ def some_func(x: float) -> None:
def test_resorting_to_from_type(self) -> None:
# We can not handle ``.startswith`` at the moment, so we expect
# ``from_type`` Hypothesis strategy followed by a filter.
@icontract.require(lambda x: x.startswith("oioi"))
@icontract.require(lambda x: x.startswith("something"))
def some_func(x: str) -> None:
pass

strategy = icontract_hypothesis.infer_strategy(some_func)
self.assertEqual(
"fixed_dictionaries({'x': text().filter(lambda x: x.startswith(\"oioi\"))})",
"fixed_dictionaries({'x': text().filter(lambda x: x.startswith(\"something\"))})",
str(strategy),
)

Expand Down Expand Up @@ -252,6 +253,7 @@ def some_func(x: int, y: int) -> None:
icontract_hypothesis.test_with_inferred_strategy(some_func)


# noinspection PyUnusedLocal
class TestWithInferredStrategiesOnClasses(unittest.TestCase):
def test_no_preconditions_and_no_argument_init(self) -> None:
class A:
Expand Down Expand Up @@ -283,8 +285,6 @@ def some_func(a: A) -> None:
icontract_hypothesis.test_with_inferred_strategy(some_func)

def test_map_snippet(self) -> None:
import hypothesis.strategies as st

class A(icontract.DBC):
def __init__(self, x: int, y: int):
self.x = x
Expand Down Expand Up @@ -476,6 +476,7 @@ class A(icontract.DBC):
def do_something(self) -> None:
pass

# noinspection PyUnusedLocal
class B(A):
@icontract.require(lambda x: x > 0)
def __init__(self, x: int):
Expand Down Expand Up @@ -563,6 +564,7 @@ def __init__(self, x: int):
def __repr__(self) -> str:
return "A(x={})".format(self.x)

# noinspection PyTypedDict
class B(TypedDict):
a: A

Expand Down Expand Up @@ -660,6 +662,7 @@ def some_func(a_or_b: Union[A, B]) -> None:
icontract_hypothesis.test_with_inferred_strategy(some_func)


# noinspection PyUnusedLocal
class TestRepresentationOfCondition(unittest.TestCase):
def test_that_a_single_line_condition_renders_correctly(self) -> None:
# This test case was adapted from a solution for Advent of Code, day 8.
Expand Down Expand Up @@ -742,6 +745,7 @@ class TestSequence(unittest.TestCase):
"""

def test_sequence_int(self) -> None:
# noinspection PyUnusedLocal
def some_func(xs: Sequence[int]) -> None:
pass

Expand Down Expand Up @@ -779,6 +783,7 @@ class A(icontract.DBC):
def __init__(self) -> None:
self.min_x = 0

# noinspection PyShadowingNames
@icontract.require(lambda self, x: self.min_x < x)
def some_func(self, x: int) -> None:
pass
Expand All @@ -803,6 +808,7 @@ class A(icontract.DBC):
def __init__(self) -> None:
self.x = 0

# noinspection PyShadowingNames
@icontract.require(lambda self: self.x >= 0)
def some_func(self) -> None:
pass
Expand All @@ -828,6 +834,7 @@ def __init__(self) -> None:
# This will make the pre-condition of ``some_func`` unsatisfiable.
self.x = -1

# noinspection PyShadowingNames
@icontract.require(lambda number: number > 0)
@icontract.require(lambda self: self.x >= 0)
def some_func(self, number: int) -> None:
Expand Down Expand Up @@ -862,6 +869,7 @@ class A:
def __init__(self) -> None:
self.x = 1

# noinspection PyShadowingNames,PyUnusedLocal
@icontract.require(lambda self: self.x > 10)
def some_func(self: A) -> None:
pass
Expand Down Expand Up @@ -889,6 +897,7 @@ class A(icontract.DBC):
def __init__(self) -> None:
self.x = 1

# noinspection PyShadowingNames
@icontract.require(lambda number: number > 0)
@icontract.require(lambda self: self.x >= 0)
def some_func(self, number: int) -> None:
Expand Down Expand Up @@ -919,6 +928,7 @@ def __init__(self) -> None:

# We need to annotate ``self`` explicitly as we can not figure out the class from
# an unbound method.
# noinspection PyShadowingNames
@icontract.require(lambda number: number > 0)
@icontract.require(lambda self: self.x >= 0)
def some_func(self: "A", number: int) -> None:
Expand Down

0 comments on commit 32f6ddf

Please sign in to comment.