• 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

83.02
/nixnet/database/_dbc_signal_value_table.py
1
from collections.abc import Mapping
1✔
2
import six
1✔
3
import typing  # NOQA: F401
1✔
4

5
from nixnet import _funcs
1✔
6
from nixnet import constants
7

1✔
8

×
9
class DbcSignalValueTable(Mapping):
NEW
10
    """Collection for accessing a DBC signal value table."""
×
11

1✔
12
    def __init__(self, handle):
1✔
13
        # type: (int) -> None
14
        self._handle = handle
1✔
15

1✔
16
    def __repr__(self):
17
        return '{}(handle={})'.format(type(self).__name__, self._handle)
18

1✔
19
    def __eq__(self, other):
20
        if isinstance(other, self.__class__):
21
            return self._handle == typing.cast(DbcSignalValueTable, other)._handle
1✔
22
        else:
23
            return NotImplemented
1✔
24

25
    def __ne__(self, other):
1✔
26
        result = self.__eq__(other)
1✔
27
        if result is NotImplemented:
28
            return result
1✔
29
        else:
1✔
30
            return not result
1✔
31

32
    def __hash__(self):
×
33
        return hash(self._handle)
34

1✔
35
    def __len__(self):
1✔
36
        return len(self._value_table)
1✔
37

×
38
    def __iter__(self):
39
        return self.keys()
1✔
40

41
    def __getitem__(self, key):
1✔
42
        # type: (typing.Text) -> int
1✔
43
        """Return the value.
44

1✔
45
            Args:
1✔
46
                Value description.
47
            Returns:
1✔
48
                Value
1✔
49
        """
50
        if isinstance(key, six.string_types):
1✔
51
            return self._value_table[key]
52
        else:
53
            raise TypeError(key)
54

55
    def keys(self):
56
        """Return all value descriptions in the collection.
57

58
            Yields:
59
                An iterator to all value descriptions in the collection.
1✔
60
        """
1✔
61
        return iter(self._value_table.keys())
62

1✔
63
    def values(self):
64
        """Return all values in the collection.
1✔
65

66
            Yields:
67
                An iterator to all values in the collection.
68
        """
69
        return iter(self._value_table.values())
70

1✔
71
    def items(self):
72
        """Return all value descriptions and values in the collection.
1✔
73

74
            Yields:
75
                An iterator to tuple pairs of value descriptions and values in the collection.
76
        """
77
        return iter(self._value_table.items())
78

1✔
79
    @property
80
    def _value_table(self):
1✔
81
        # type: () -> typing.Dict[typing.Text, int]
82
        mode = constants.GetDbcAttributeMode.VALUE_TABLE_LIST
83
        attribute_size = _funcs.nxdb_get_dbc_attribute_size(self._handle, mode, '')
84
        attribute_info = _funcs.nxdb_get_dbc_attribute(self._handle, mode, '', attribute_size)
85
        table_string = attribute_info[0]
86
        if not table_string:
1✔
87
            return {}
88

1✔
89
        table_list = table_string.split(',')
90
        if len(table_list) % 2:
91
            raise ValueError('Value tables require an even number of items: %s' % table_list)
1✔
92

1✔
93
        # table_string is of the format 'value1, key1, value2, key2, ...'
1✔
94
        # convert to a dict: { 'key1': int('value1'), 'key2': int('value2'), ... }
1✔
95
        table_dict = dict(
1✔
96
            (key, int(value))
1✔
97
            for value, key in zip(table_list[0::2], table_list[1::2]))
98
        return table_dict
×
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