Skip to content

Commit

Permalink
apply ruff and mypy on test_aoe
Browse files Browse the repository at this point in the history
  • Loading branch information
Conengmo committed Mar 17, 2024
1 parent d7ef828 commit e8934f1
Showing 1 changed file with 46 additions and 5 deletions.
51 changes: 46 additions & 5 deletions tests/test_aoe.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,87 @@
def mock_scene():
return Mock()


@pytest.fixture
def aoe_manager(mock_scene):
return AreaOfEffectManager(mock_scene)


def test_area_of_effect_manager_wait_for(aoe_manager):
callback = Mock()
aoe_manager.wait_for("circle", "red", callback)
assert aoe_manager.waiting_for.func == Circle
assert aoe_manager.waiting_for.keywords == {"color": "red"}
assert aoe_manager.callback == callback


def test_area_of_effect_manager_cancel(aoe_manager):
aoe_manager.wait_for("circle", "red", Mock())
aoe_manager.cancel()
assert aoe_manager.waiting_for is None
assert aoe_manager.callback is None


def test_area_of_effect_manager_clear_all(aoe_manager):
aoe_manager._store = [Mock(), Mock()]
aoe_manager.clear_all()
assert aoe_manager._store == []


def test_area_of_effect_manager_mouse_press_event(aoe_manager):
aoe_manager.wait_for("circle", "red", Mock())
event = QMouseEvent(QMouseEvent.Type.MouseButtonPress, QPointF(10, 20), Qt.LeftButton, Qt.NoButton, Qt.NoModifier)
event = QMouseEvent(
QMouseEvent.Type.MouseButtonPress,
QPointF(10, 20),
Qt.LeftButton, # type: ignore[attr-defined]
Qt.NoButton, # type: ignore[attr-defined]
Qt.NoModifier, # type: ignore[attr-defined]
)
assert aoe_manager.mouse_press_event(event) is True
assert aoe_manager.waiting_for.keywords == {"color": "red", "x1": 10, "y1": 20}


def test_area_of_effect_manager_mouse_move_event(aoe_manager, mock_scene):
aoe_manager.wait_for("circle", "red", Mock())
aoe_manager.mouse_press_event(QMouseEvent(QMouseEvent.Type.MouseButtonPress, QPointF(10, 20), Qt.LeftButton, Qt.NoButton, Qt.NoModifier))
event = QMouseEvent(QMouseEvent.Type.MouseMove, QPointF(30, 40), Qt.NoButton, Qt.NoButton, Qt.NoModifier)
aoe_manager.mouse_press_event(
QMouseEvent(
QMouseEvent.Type.MouseButtonPress,
QPointF(10, 20),
Qt.LeftButton, # type: ignore[attr-defined]
Qt.NoButton, # type: ignore[attr-defined]
Qt.NoModifier, # type: ignore[attr-defined]
)
)
event = QMouseEvent(
QMouseEvent.Type.MouseMove,
QPointF(30, 40),
Qt.NoButton, # type: ignore[attr-defined]
Qt.NoButton, # type: ignore[attr-defined]
Qt.NoModifier, # type: ignore[attr-defined]
)
aoe_manager.mouse_move_event(event)
assert mock_scene.addItem.call_count == 1


def test_area_of_effect_manager_mouse_release_event(aoe_manager, mock_scene):
callback = Mock()
aoe_manager.wait_for("circle", "red", callback)
aoe_manager.mouse_press_event(QMouseEvent(QMouseEvent.Type.MouseButtonPress, QPointF(10, 20), Qt.LeftButton, Qt.NoButton, Qt.NoModifier))
event = QMouseEvent(QMouseEvent.Type.MouseButtonRelease, QPointF(30, 40), Qt.LeftButton, Qt.NoButton, Qt.NoModifier)
aoe_manager.mouse_press_event(
QMouseEvent(
QMouseEvent.Type.MouseButtonPress,
QPointF(10, 20),
Qt.LeftButton, # type: ignore[attr-defined]
Qt.NoButton, # type: ignore[attr-defined]
Qt.NoModifier, # type: ignore[attr-defined]
)
)
event = QMouseEvent(
QMouseEvent.Type.MouseButtonRelease,
QPointF(30, 40),
Qt.LeftButton, # type: ignore[attr-defined]
Qt.NoButton, # type: ignore[attr-defined]
Qt.NoModifier, # type: ignore[attr-defined]
)
assert aoe_manager.mouse_release_event(event) is True
assert callback.call_count == 1
assert mock_scene.addItem.call_count == 1
Expand Down

0 comments on commit e8934f1

Please # to comment.