• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ni / nixnet-python / #631999863

08 Apr 2025 07:22AM UTC coverage: 67.546% (-0.005%) from 67.551%
#631999863

Pull #302

travis-ci

Pull Request #302: Fix `tox -e mypy` errors with `mypy 1.14.1`

22 of 66 new or added lines in 15 files covered. (33.33%)

10 existing lines in 1 file now uncovered.

4712 of 6976 relevant lines covered (67.55%)

0.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.24
/nixnet/_utils.py
1
from collections.abc import Iterable
1✔
2
import typing  # NOQA: F401
1✔
3

1✔
4
import six
5

1✔
6
from nixnet import _cconsts
7
from nixnet import _errors
1✔
8
from nixnet import constants
×
9
from nixnet import types
NEW
10

×
11

1✔
12
def flatten_items(list):
13
    # type: (typing.Union[typing.Text, typing.List[typing.Text], None]) -> typing.Text
1✔
14
    """Flatten an item list to a string
15

1✔
16
    >>> str(flatten_items('Item'))
1✔
17
    'Item'
1✔
18
    >>> str(flatten_items(['A', 'B']))
1✔
19
    'A,B'
20
    >>> str(flatten_items(None))
21
    ''
1✔
22
    """
23
    if isinstance(list, six.string_types):
24
        # For FRAME_IN_QUEUED / FRAME_OUT_QUEUED
25
        # Convenience for everything else
26
        if ',' in list:
27
            _errors.raise_xnet_error(_cconsts.NX_ERR_INVALID_PROPERTY_VALUE)
28
        flattened = list
29
    elif isinstance(list, Iterable):
30
        flattened = ",".join(list)
31
    elif list is None:
32
        # For FRAME_IN_STREAM / FRAME_OUT_STREAM
1✔
33
        flattened = ''
34
    else:
35
        _errors.raise_xnet_error(_cconsts.NX_ERR_INVALID_PROPERTY_VALUE)
1✔
36

1✔
37
    return flattened
1✔
38

1✔
39

1✔
40
def parse_can_comm_bitfield(bitfield):
1✔
41
    # type:  (int) -> types.CanComm
42
    """Parse a CAN Comm bitfield."""
1✔
43
    state = constants.CanCommState(bitfield & 0x0F)
44
    tcvr_err = ((bitfield >> 4) & 0x01) != 0
1✔
45
    sleep = ((bitfield >> 5) & 0x01) != 0
46
    last_err = constants.CanLastErr((bitfield >> 8) & 0x0F)
1✔
47
    tx_err_count = ((bitfield >> 16) & 0x0FF)
48
    rx_err_count = ((bitfield >> 24) & 0x0FF)
49
    return types.CanComm(state, tcvr_err, sleep, last_err, tx_err_count, rx_err_count)
1✔
50

51

52
def parse_lin_comm_bitfield(first, second):
1✔
53
    # type: (int, int) -> types.LinComm
1✔
54
    """Parse a LIN Comm first."""
1✔
55
    sleep = ((first >> 1) & 0x01) != 0
1✔
56
    state = constants.LinCommState((first >> 2) & 0x03)
1✔
57
    last_err = constants.LinLastErr((first >> 4) & 0x0F)
1✔
58
    last_err_received = (first >> 8) & 0x0FF
1✔
59
    last_err_expected = (first >> 16) & 0x0FF
60
    last_err_id = (first >> 24) & 0x03F
61
    tcvr_rdy = ((first >> 32) & 0x01) != 0
1✔
62

63
    sched_index = second & 0x0FF
64

1✔
65
    return types.LinComm(
1✔
66
        sleep,
1✔
67
        state,
1✔
68
        last_err,
1✔
69
        last_err_received,
1✔
70
        last_err_expected,
1✔
71
        last_err_id,
72
        tcvr_rdy,
1✔
73
        sched_index)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc