Passed
Pull Request — main (#169)
by
unknown
01:30
created

tests.core.test_heartbeat.TestHeartbeat.test_get()   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nop 0
1
# Copyright Pincer 2021-Present
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
# Full MIT License can be found in `LICENSE` at the project root.
3
4
from unittest.mock import AsyncMock, Mock, patch
0 ignored issues
show
Bug introduced by
The name AsyncMock does not seem to exist in module unittest.mock.
Loading history...
5
6
import pytest
0 ignored issues
show
introduced by
Unable to import 'pytest'
Loading history...
7
8
from pincer.core.heartbeat import Heartbeat
9
from tests.utils.utils import assert_not_raises
10
11
12
@pytest.fixture
13
def web_socket_client_protocol():
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
14
    return AsyncMock()
15
16
17
class TestHeartbeat:
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
18
    @staticmethod
19
    def test_get():
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
20
        assert Heartbeat.get() == 0
21
22
    @pytest.mark.asyncio
23
    async def test_handle_hello(self, web_socket_client_protocol):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
Comprehensibility Bug introduced by
web_socket_client_protocol is re-defining a name which is already available in the outer-scope (previously defined on line 13).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
24
        payload = Mock()
25
        payload.data.get.return_value = 1
26
        with patch("pincer.core.heartbeat.Heartbeat"):
27
            await Heartbeat.handle_hello(web_socket_client_protocol, payload)
28
        web_socket_client_protocol.send.assert_awaited_once()
29
30
    @pytest.mark.asyncio
31
    async def test_handle_heartbeat(self, web_socket_client_protocol):
0 ignored issues
show
Comprehensibility Bug introduced by
web_socket_client_protocol is re-defining a name which is already available in the outer-scope (previously defined on line 13).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
introduced by
Missing function or method docstring
Loading history...
32
        await Heartbeat.handle_heartbeat(web_socket_client_protocol, "GARBAGE")
33
        web_socket_client_protocol.send.assert_awaited_once()
34
35
    @staticmethod
36
    def test_update_sequence():
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
37
        with assert_not_raises():
38
            Heartbeat.update_sequence(42)
39