forked from Pincer-org/Pincer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve test coverage for core/Heartbeat.py (Pincer-org#121)
- Loading branch information
1 parent
c79b305
commit c1753c6
Showing
5 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Copyright Pincer 2021-Present | ||
# Full MIT License can be found in `LICENSE` at the project root. | ||
|
||
from unittest.mock import AsyncMock, Mock, patch, PropertyMock | ||
|
||
import pytest | ||
|
||
from pincer.core.heartbeat import Heartbeat | ||
from tests.utils.utils import assert_not_raises | ||
|
||
|
||
@pytest.fixture | ||
def web_socket_client_protocol(): | ||
return AsyncMock() | ||
|
||
|
||
class TestHeartbeat: | ||
def test_get(self): | ||
assert Heartbeat.get() == 0 | ||
|
||
@pytest.mark.asyncio | ||
async def test_handle_hello(self, web_socket_client_protocol): | ||
payload = Mock() | ||
payload.data.get.return_value = 1 | ||
with patch("pincer.core.heartbeat.Heartbeat"): | ||
await Heartbeat.handle_hello(web_socket_client_protocol, payload) | ||
web_socket_client_protocol.send.assert_awaited_once() | ||
|
||
@pytest.mark.asyncio | ||
async def test_handle_heartbeat(self, web_socket_client_protocol): | ||
await Heartbeat.handle_heartbeat(web_socket_client_protocol, "GARBAGE") | ||
web_socket_client_protocol.send.assert_awaited_once() | ||
|
||
def test_update_sequence(self): | ||
with assert_not_raises(): | ||
Heartbeat.update_sequence(42) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pytest==6.2.5 | ||
pytest-asyncio==0.16.0 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from contextlib import contextmanager | ||
|
||
|
||
@contextmanager | ||
def assert_not_raises(): | ||
"""Dummy context manager to highlight a row of a test | ||
that should not raises any exception""" | ||
yield |