Skip to content

Commit

Permalink
tests should assert reason for failure
Browse files Browse the repository at this point in the history
  • Loading branch information
bandophahita committed Feb 8, 2024
1 parent 9e3b236 commit 0abc77e
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions tests/test_actions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

import warnings
from typing import cast
from contextlib import contextmanager
from typing import Generator, cast
from unittest import mock

import pytest
Expand Down Expand Up @@ -64,6 +65,20 @@
TARGET = FakeTarget()


@contextmanager
def not_raises(ExpectedException: type[Exception]) -> Generator:
try:
yield

except ExpectedException as error:
msg = f"Incorrectly Raised {error}"
raise AssertionError(msg) from error

except Exception as error: # noqa: BLE001
msg = f"Unexpected exception {error}"
raise AssertionError(msg) from error


class TestAcceptAlert:
def test_can_be_instantiated(self) -> None:
aa = AcceptAlert()
Expand Down Expand Up @@ -441,11 +456,11 @@ def test_positional_arg_warns(self) -> None:
Enter("", True)

def test_keyword_arg_does_not_warn(self) -> None:
with warnings.catch_warnings():
with not_raises(DeprecationWarning), warnings.catch_warnings():
warnings.simplefilter("error")
Enter.the_secret("")

with warnings.catch_warnings():
with not_raises(DeprecationWarning), warnings.catch_warnings():
warnings.simplefilter("error")
Enter("", mask=True)

Expand Down Expand Up @@ -638,11 +653,11 @@ def test_positional_arg_warns(self) -> None:
HoldDown(None, True)

def test_keyword_arg_does_not_warn(self) -> None:
with warnings.catch_warnings():
with not_raises(DeprecationWarning), warnings.catch_warnings():
warnings.simplefilter("error")
HoldDown.left_mouse_button()

with warnings.catch_warnings():
with not_raises(DeprecationWarning), warnings.catch_warnings():
warnings.simplefilter("error")
HoldDown(lmb=True)

Expand Down Expand Up @@ -916,11 +931,11 @@ def test_positional_arg_warns(self) -> None:
Release(None, True)

def test_keyword_arg_does_not_warn(self) -> None:
with warnings.catch_warnings():
with not_raises(DeprecationWarning), warnings.catch_warnings():
warnings.simplefilter("error")
Release.left_mouse_button()

with warnings.catch_warnings():
with not_raises(DeprecationWarning), warnings.catch_warnings():
warnings.simplefilter("error")
Release(lmb=True)

Expand Down

0 comments on commit 0abc77e

Please sign in to comment.