How to use the asynctest.mock.sentinel function in asynctest

To help you get started, we’ve selected a few asynctest examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zigpy / bellows / tests / test_ezsp.py View on Github external
def test_connection_lost(ezsp_f):
    ezsp_f.enter_failed_state = mock.MagicMock(spec_set=ezsp_f.enter_failed_state)
    ezsp_f.connection_lost(mock.sentinel.exc)
    assert ezsp_f.enter_failed_state.call_count == 1
github zigpy / zigpy / tests / test_zcl_clusters.py View on Github external
else:
                img.get_image_block.return_value = mock.sentinel.data
            if not correct_version:
                img.version = mock.sentinel.wrong_image_version
        else:
            img = None
        return img

    cluster.endpoint.device.application.ota.get_ota_image.side_effect = get_ota_mock
    return cluster._handle_image_block(
        mock.sentinel.field_ctrl,
        mock.sentinel.manufacturer_id,
        mock.sentinel.image_type,
        mock.sentinel.image_version,
        IMAGE_OFFSET,
        mock.sentinel.max_data_size,
        mock.sentinel.addr,
        mock.sentinel.delay,
        tsn=0x21,
    )
github zigpy / zigpy / tests / test_ota.py View on Github external
import datetime

from asynctest import CoroutineMock, mock
import pytest
import zigpy.application
import zigpy.ota
import zigpy.ota.image
import zigpy.ota.provider

MANUFACTURER_ID = mock.sentinel.manufacturer_id
IMAGE_TYPE = mock.sentinel.image_type


@pytest.fixture
def image_with_version():
    def img(version=100):
        img = zigpy.ota.image.OTAImage()
        img.header.manufacturer_id = MANUFACTURER_ID
        img.header.image_type = IMAGE_TYPE
        img.header.file_version = version
        img.subelements.append(
            zigpy.ota.image.SubElement.deserialize(b"\x00\x00\x04\x00\x00\x00abcdef")[0]
        )
        return img

    return img
github zigpy / zigpy / tests / test_group.py View on Github external
def test_add_group(groups, monkeypatch):
    monkeypatch.setattr(
        zigpy.group,
        "Group",
        mock.MagicMock(spec_set=zigpy.group.Group, return_value=mock.sentinel.group),
    )
    grp_id, grp_name = 0x1234, "Group Name for 0x1234 group."

    assert grp_id not in groups
    ret = groups.add_group(grp_id, grp_name)
    assert groups.listener_event.call_count == 1
    assert ret is mock.sentinel.group

    groups.listener_event.reset_mock()
    ret = groups.add_group(grp_id, grp_name)
    assert groups.listener_event.call_count == 0
    assert ret is mock.sentinel.group
github zigpy / bellows / tests / test_application.py View on Github external
if broadcast_success:
            if not send_timeout:
                app._pending[tsn].result.set_result((0, "sendBroadcast failure"))
            return [0]
        else:
            return [t.EmberStatus.ERR_FATAL]

    app._ezsp.sendBroadcast.side_effect = mock_send
    app.get_sequence = mock.MagicMock(return_value=mock.sentinel.msg_tag)

    res = await app.broadcast(
        profile, cluster, src_ep, dst_ep, grpid, radius, tsn, data
    )
    assert app._ezsp.sendBroadcast.call_count == 1
    assert app._ezsp.sendBroadcast.call_args[0][2] == radius
    assert app._ezsp.sendBroadcast.call_args[0][3] == mock.sentinel.msg_tag
    assert app._ezsp.sendBroadcast.call_args[0][4] == data
    assert len(app._pending) == 0
    return res
github zigpy / zigpy / tests / test_zcl.py View on Github external
def test_handle_cluster_request(cluster):
    hdr = mock.MagicMock(auto_spec=foundation.ZCLHeader)
    hdr.command_id = mock.sentinel.command_id
    hdr.frame_control.is_general = False
    hdr.frame_control.is_cluster = True
    hdr.command_id.is_general = False
    cluster.listener_event = mock.MagicMock()
    cluster._update_attribute = mock.MagicMock()
    cluster.handle_cluster_general_request = mock.MagicMock()
    cluster.handle_cluster_request = mock.MagicMock()
    cluster.handle_message(hdr, mock.sentinel.args)

    assert cluster.listener_event.call_count == 1
    assert cluster.listener_event.call_args[0][0] == "cluster_command"
    assert cluster._update_attribute.call_count == 0
    assert cluster.handle_cluster_general_request.call_count == 0
    assert cluster.handle_cluster_request.call_count == 1
github zigpy / zigpy / tests / test_endpoint.py View on Github external
async def mock_req(*args, **kwargs):
        if success:
            return [ZCLStatus.SUCCESS, mock.sentinel.group_id]
        return [ZCLStatus.DUPLICATE_EXISTS, mock.sentinel.group_id]
github zigpy / zigpy / tests / test_zcl_clusters.py View on Github external
async def get_ota_mock(*args):
        if has_image:
            img = mock.MagicMock()
            img.should_update.return_value = True
            img.key.manufacturer_id = mock.sentinel.manufacturer_id
            img.key.image_type = mock.sentinel.image_type
            img.version = mock.sentinel.image_version
            img.header.image_size = IMAGE_SIZE
            if wrong_offset:
                img.get_image_block.side_effect = ValueError()
            else:
                img.get_image_block.return_value = mock.sentinel.data
            if not correct_version:
                img.version = mock.sentinel.wrong_image_version
        else:
            img = None
        return img
github zigpy / zigpy / tests / test_zcl_clusters.py View on Github external
img.key.image_type = mock.sentinel.image_type
            img.version = mock.sentinel.image_version
            img.header.image_size = mock.sentinel.image_size
        elif has_image:
            img = mock.MagicMock()
            img.should_update.return_value = False
        else:
            img = None
        return img

    cluster.endpoint.device.application.ota.get_ota_image.side_effect = get_ota_mock
    return cluster._handle_query_next_image(
        mock.sentinel.field_ctrl,
        mock.sentinel.manufacturer_id,
        mock.sentinel.image_type,
        mock.sentinel.current_file_version,
        mock.sentinel.hw_version,
        tsn=0x21,
    )
github zigpy / zigpy / tests / test_zcl.py View on Github external
def test_handle_cluster_request(cluster):
    hdr = mock.MagicMock(auto_spec=foundation.ZCLHeader)
    hdr.command_id = mock.sentinel.command_id
    hdr.frame_control.is_general = False
    hdr.frame_control.is_cluster = True
    hdr.command_id.is_general = False
    cluster.listener_event = mock.MagicMock()
    cluster._update_attribute = mock.MagicMock()
    cluster.handle_cluster_general_request = mock.MagicMock()
    cluster.handle_cluster_request = mock.MagicMock()
    cluster.handle_message(hdr, mock.sentinel.args)

    assert cluster.listener_event.call_count == 1
    assert cluster.listener_event.call_args[0][0] == "cluster_command"
    assert cluster._update_attribute.call_count == 0
    assert cluster.handle_cluster_general_request.call_count == 0
    assert cluster.handle_cluster_request.call_count == 1