File: conftest.py

package info (click to toggle)
pyegps 0.2.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 180 kB
  • sloc: python: 554; makefile: 7; sh: 5
file content (43 lines) | stat: -rw-r--r-- 1,065 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""Fixtures definitions for pyEGPS tests."""
from __future__ import annotations

from array import array
from unittest.mock import MagicMock

import pytest

CTRL_IN = 1 << 7


def get_usb_mock(product_id: int) -> MagicMock:
    """Create a Mock representing a pyusb device."""
    mock = MagicMock()
    mock.idProduct = product_id
    mock.manufacturer = "AllFake"
    mock.product = "Fake-Product"

    def ctrl_transfer(
        bmRequestType,
        bRequest,
        wValue,
        wIndex,
        data_or_wLength,
        USB_CTRL_TRANSFER_TIMEOUT,
    ) -> bytes | int:
        req_in: bool = (bmRequestType & CTRL_IN) == CTRL_IN
        return array("B", []) if req_in else 0

    mock.ctrl_transfer = ctrl_transfer
    return mock


@pytest.fixture
def fakeUsbDevice() -> MagicMock:
    """Return a fake USB device with supported product_id."""
    return get_usb_mock(product_id=0xFD15)


@pytest.fixture
def fakeUnknownUsbDevice() -> MagicMock:
    """Return a fake USB device with unsupported product_id."""
    return get_usb_mock(product_id=0xFD20)