• 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

54.24
/nixnet/database/_collection.py
1
from collections.abc import Mapping
1✔
2
import typing  # NOQA: F401
1✔
3

1✔
4
import six
5

1✔
6
from nixnet import _cprops
7
from nixnet import _funcs
1✔
8
from nixnet import constants  # NOQA: F401
×
9

NEW
10
from nixnet.database import _database_object  # NOQA: F401
×
11

1✔
12

13
class DbCollection(Mapping):
1✔
14
    """Collection of database objects."""
15

1✔
16
    def __init__(self, handle, db_type, prop_id, factory):
1✔
17
        # type: (int, constants.ObjectClass, int, typing.Any) -> None
1✔
18
        self._handle = handle
19
        self._type = db_type
1✔
20
        self._prop_id = prop_id
21
        self._factory = factory
22

1✔
23
    def __repr__(self):
24
        return '{}(handle={}, db_type={})'.format(type(self).__name__, self._handle, self._type)
25

1✔
26
    def __eq__(self, other):
27
        if isinstance(other, self.__class__):
1✔
28
            sys_other = typing.cast(DbCollection, other)
1✔
29
            return self._handle == sys_other._handle and self._prop_id == sys_other._prop_id
1✔
30
        else:
1✔
31
            return NotImplemented
32

1✔
33
    def __ne__(self, other):
×
34
        result = self.__eq__(other)
35
        if result is NotImplemented:
1✔
36
            return result
×
37
        else:
×
38
            return not result
×
39

40
    def __hash__(self):
×
41
        return hash(self._handle)
42

1✔
43
    def __len__(self):
×
44
        return _cprops.get_database_ref_array_len(self._handle, self._prop_id)
×
45

×
46
    def __iter__(self):
47
        return self.keys()
×
48

49
    def __getitem__(self, index):
1✔
50
        """Return the database object.
×
51

52
        Args:
1✔
53
            Name of database object
×
54
        Returns:
55
            index(str): Name of database object.
1✔
56
        """
×
57
        if isinstance(index, six.string_types):
58
            ref = _funcs.nxdb_find_object(self._handle, self._type, index)
1✔
59
            return self._factory(_handle=ref)
60
        else:
61
            raise TypeError(index)
62

63
    def __delitem__(self, index):
64
        ref = _funcs.nxdb_find_object(self._handle, self._type, index)
65
        _funcs.nxdb_delete_object(ref)
66

×
67
    def keys(self):
×
68
        """Return database object names in the collection.
×
69

70
        Yields:
×
71
            An iterator to database object names in the collection.
72
        """
1✔
73
        for child in self._get_children():
×
74
            yield child.name
×
75

76
    def values(self):
1✔
77
        """Return database objects in the collection.
78

79
        Yields:
80
            An iterator to database objects in the collection.
81
        """
82
        return self._get_children()
×
83

×
84
    def items(self):
85
        """Return all database object names and objects in the collection.
1✔
86

87
        Yields:
88
            An iterator to tuple pairs of database object names and objects in the collection
89
        """
90
        for child in self._get_children():
91
            yield child.name, child
×
92

93
    def add(self, name):
1✔
94
        # type: (typing.Text) -> _database_object.DatabaseObject
95
        """Add a new database object to the collection.
96

97
        Args:
98
            name(str): Name of the new database object.
99
        Returns:
×
100
            ``DatabaseObject``: An instance of the new database object.
×
101
        """
102
        ref = _funcs.nxdb_create_object(self._handle, self._type, name)
1✔
103
        return self._factory(_handle=ref)
104

105
    def _get_children(self):
106
        for ref in _cprops.get_database_ref_array(self._handle, self._prop_id):
107
            yield self._factory(_handle=ref)
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