Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pytest and mypy #133

Merged
merged 2 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions deal/_runtime/_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def pre(
exception=exception or _exceptions.PreContractError,
)
func = partial(Contracts.attach, 'pres', contract)
return func # type: ignore[return-value]
return func


def post(
Expand Down Expand Up @@ -107,7 +107,7 @@ def post(
exception=exception or _exceptions.PostContractError,
)
func = partial(Contracts.attach, 'posts', contract)
return func # type: ignore[return-value]
return func


def ensure(
Expand Down Expand Up @@ -155,7 +155,7 @@ def ensure(
exception=exception or _exceptions.PostContractError,
)
func = partial(Contracts.attach, 'ensures', contract)
return func # type: ignore[return-value]
return func


def raises(
Expand Down Expand Up @@ -204,7 +204,7 @@ def raises(
exception=exception or _exceptions.RaisesContractError,
)
func = partial(Contracts.attach, 'raises', contract)
return func # type: ignore[return-value]
return func


def has(
Expand Down Expand Up @@ -248,7 +248,7 @@ def has(
exception=exception,
)
func = partial(Contracts.attach_has, patcher)
return func # type: ignore[return-value]
return func


def reason(
Expand Down Expand Up @@ -303,7 +303,7 @@ def reason(
exception=exception or _exceptions.ReasonContractError,
)
func = partial(Contracts.attach, 'reasons', contract)
return func # type: ignore[return-value]
return func


def inv(
Expand Down Expand Up @@ -394,7 +394,7 @@ def example(validator: Callable[[], bool]) -> Callable[[C], C]:
exception=_exceptions.ExampleContractError,
)
func = partial(Contracts.attach, 'examples', contract)
return func # type: ignore[return-value]
return func


@overload
Expand Down
4 changes: 2 additions & 2 deletions deal/_runtime/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@


if TYPE_CHECKING:
Args = tuple[object, ...] # type: ignore[misc]
Kwargs = dict[str, object] # type: ignore[misc]
Args = tuple[object, ...]
Kwargs = dict[str, object]


@lru_cache(maxsize=16)
Expand Down
2 changes: 2 additions & 0 deletions deal/_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def _collect_trace_results(t: Trace, func, file_name: str, func_result) -> Trace
last_line = max(all_lines)

covered_lines: set[int] = set()
fname: str
lineno: int
for fname, lineno in t.counts: # type: ignore
assert fname == file_name
if lineno < first_line:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ has-astroid = "not is_installed('astroid')"

[tool.mypy]
files = ["deal"]
python_version = 3.8
python_version = "3.9"
plugins = ["deal.mypy"]
ignore_missing_imports = true
show_error_codes = true
Expand Down
27 changes: 15 additions & 12 deletions tests/test_state.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import warnings

import pytest

Expand Down Expand Up @@ -138,18 +139,19 @@ def set_env_vars():
def test_enable__warnings(restore_state, env_vars, set_env_vars, expected):
os.environ.clear()
set_env_vars(env_vars)
ewarn = RuntimeWarning if expected else None
with pytest.warns(ewarn) as warns:
deal.enable()
if expected:
with pytest.warns(RuntimeWarning) as warns:
deal.enable()
assert len(warns) == 1
assert str(warns[0].message) == f'{expected}. Is it intentional?'
else:
assert len(warns) == 0
with warnings.catch_warnings():
warnings.simplefilter('error')
deal.enable()

with pytest.warns(None) as warns:
with warnings.catch_warnings():
warnings.simplefilter('error')
deal.enable(warn=False)
assert len(warns) == 0


@pytest.mark.parametrize('env_vars, expected', [
Expand All @@ -162,15 +164,16 @@ def test_enable__warnings(restore_state, env_vars, set_env_vars, expected):
def test_disable__warnings(restore_state, env_vars, set_env_vars, expected):
os.environ.clear()
set_env_vars(env_vars)
ewarn = RuntimeWarning if expected else None
with pytest.warns(ewarn) as warns:
deal.disable()
if expected:
with pytest.warns(RuntimeWarning) as warns:
deal.disable()
assert len(warns) == 1
assert str(warns[0].message) == f'{expected}. Is it intentional?'
else:
assert len(warns) == 0
with warnings.catch_warnings():
warnings.simplefilter('error')
deal.disable()

with pytest.warns(None) as warns:
with warnings.catch_warnings():
warnings.simplefilter('error')
deal.disable(warn=False)
assert len(warns) == 0
Loading