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

pyecore / pyecore / 748

pending completion
748

cron

travis-ci-com

aranega
Merge branch 'release/0.13.0'

157 of 157 new or added lines in 9 files covered. (100.0%)

2780 of 2877 relevant lines covered (96.63%)

7.73 hits per line

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

90.16
/pyecore/ordered_set_patch.py
1
import ordered_set
8✔
2
from typing import Iterable
8✔
3

4

5
SLICE_ALL = ordered_set.SLICE_ALL
8✔
6

7

8
# monkey patching the OrderedSet implementation
9
def insert(self, index, key):
8✔
10
    """Adds an element at a dedicated position in an OrderedSet.
11

12
    This implementation is meant for the OrderedSet from the ordered_set
13
    package only.
14
    """
15
    if key in self.map:
8✔
16
        return
8✔
17
    # compute the right index
18
    size = len(self.items)
8✔
19
    if index < 0:
8✔
20
        index = size + index if size + index > 0 else 0
8✔
21
    else:
22
        index = index if index < size else size
8✔
23
    # insert the value
24
    self.items.insert(index, key)
8✔
25
    for k, v in self.map.items():
8✔
26
        if v >= index:
8✔
27
            self.map[k] = v + 1
8✔
28
    self.map[key] = index
8✔
29

30

31
def pop(self, index=-1):
8✔
32
    """Removes an element at the tail of the OrderedSet or at a dedicated
33
    position.
34

35
    This implementation is meant for the OrderedSet from the ordered_set
36
    package only.
37
    """
38
    if not self.items:
8✔
39
        raise KeyError('Set is empty')
8✔
40

41
    elem = self.items[index]
8✔
42
    del self.items[index]
8✔
43
    del self.map[elem]
8✔
44
    if elem != -1:
8✔
45
        for k, v in self.map.items():
8✔
46
            if v >= index and v > 0:
8✔
47
                self.map[k] = v - 1
8✔
48
    return elem
8✔
49

50

51
def __setitem__(self, index, item):
8✔
52
    if isinstance(index, slice):
8✔
53
        raise KeyError('Item assignation using slices is not yet supported '
8✔
54
                       f'for {self.__class__.__name__}')
55
    if index < 0:
8✔
56
        index = len(self.items) + index
8✔
57
        if index < 0:
8✔
58
            raise IndexError('assignement index out of range')
8✔
59
    self.pop(index)
8✔
60
    self.insert(index, item)
8✔
61

62

63
def __getitem__(self, index):
8✔
64
    if isinstance(index, slice) and index == SLICE_ALL:
8✔
65
        return self.copy()
8✔
66
    elif isinstance(index, Iterable):
8✔
67
        return self.subcopy(self.items[i] for i in index)
8✔
68
    elif isinstance(index, slice) or hasattr(index, "__index__"):
8✔
69
        result = self.items[index]
8✔
70
        if isinstance(result, list):
8✔
71
            return self.subcopy(result)
8✔
72
        else:
73
            return result
8✔
74
    else:
75
        raise TypeError("Don't know how to index an OrderedSet by %r" % index)
8✔
76

77

78
def __delitem__(self, index):
8✔
79
    if isinstance(index, slice) and index == SLICE_ALL:
×
80
        self.clear()
×
81
        return
×
82
    elif isinstance(index, slice):
×
83
        raise KeyError('Item deletion using slices is not yet supported '
×
84
                       f'for {self.__class__.__name__}')
85
    self.pop(index)
×
86

87

88
def subcopy(self, subitems):
8✔
89
    """
90
    This method is here mainly for overriding
91
    """
92
    return self.__class__(subitems)
8✔
93

94

95
ordered_set.OrderedSet.insert = insert
8✔
96
ordered_set.OrderedSet.pop = pop
8✔
97
ordered_set.OrderedSet.__setitem__ = __setitem__
8✔
98
ordered_set.OrderedSet.__getitem__ = __getitem__
8✔
99
ordered_set.OrderedSet.__delitem__ = __delitem__
8✔
100
ordered_set.OrderedSet.subcopy = subcopy
8✔
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