Beispiel #1
0
 def inplace_update(self):
     old = s = OrderedSet()
     with Assert.raises(TypeError):
         s |= 'abc'
     s |= OrderedSet('abc')
     Assert(s) == OrderedSet('abc')
     Assert(s).is_(old)
Beispiel #2
0
 def symmetric_difference_update(self):
     old = s = OrderedSet('abc')
     s ^= OrderedSet('def')
     Assert(s) == OrderedSet('abcdef')
     Assert(s).is_(old)
     with Assert.raises(TypeError):
         s ^= 'ghi'
Beispiel #3
0
 def intersection_update(self):
     old = s = OrderedSet('abc')
     with Assert.raises(TypeError):
         s &= 'ab'
     s &= OrderedSet('ab')
     Assert(s) == OrderedSet('ab')
     Assert(s).is_(old)
Beispiel #4
0
 def equality(self):
     a = OrderedSet([1, 2, 3])
     b = OrderedSet([3, 2, 1])
     Assert(a) == a
     Assert(a) == set(b)
     Assert(b) == b
     Assert(b) == set(a)
     Assert(a) != b
Beispiel #5
0
    def difference_update(self):
        s = OrderedSet('abcd')
        s -= s
        Assert(s) == OrderedSet()

        old = s = OrderedSet('abcd')
        s -= OrderedSet('abc')
        with Assert.raises(TypeError):
            s -= 'abc'
        Assert(s) == OrderedSet('d')
        Assert(s).is_(old)
Beispiel #6
0
 def pop(self):
     s = OrderedSet()
     with Assert.raises(KeyError):
         s.pop()
     s = OrderedSet([1, 2, 3])
     Assert(s.pop()) == 3
     Assert(s.pop(last=False)) == 1
Beispiel #7
0
 def difference(self):
     a = OrderedSet('abc')
     Assert(a.difference('abc')) == OrderedSet()
     Assert(a.difference('a', 'b', 'c')) == OrderedSet()
     Assert(a - OrderedSet('ab')) == OrderedSet('c')
     with Assert.raises(TypeError):
         a - 'abc'
Beispiel #8
0
def normalize_words(ws):
    return list(
        OrderedSet(
            map(
                normalize_word,
                filter(lambda s: re.match('\w', s, flags=re.UNICODE),
                       re.split('\W', ws, flags=re.UNICODE)))))
Beispiel #9
0
 def union(self):
     a = OrderedSet('abc')
     b = OrderedSet('def')
     Assert(a.union('def', 'ghi')) == OrderedSet('abcdefghi')
     Assert(a | b) == OrderedSet('abcdef')
     with Assert.raises(TypeError):
         a | 'abc'
Beispiel #10
0
 def repr(self):
     Assert(repr(OrderedSet())) == 'OrderedSet()'
     s = OrderedSet([1, 2, 3])
     Assert(repr(s)) == 'OrderedSet([1, 2, 3])'
Beispiel #11
0
    def symmetric_difference(self):
        for a, b in [('abc', 'def'), ('def', 'abc')]:
            OrderedSet(a).symmetric_difference(b) == OrderedSet(a + b)
            OrderedSet(a) ^ OrderedSet(b) == OrderedSet(a + b)

            OrderedSet(a).symmetric_difference(a + b) == OrderedSet(b)
            OrderedSet(a) ^ OrderedSet(a + b) == OrderedSet(b)

        with Assert.raises(TypeError):
            OrderedSet('abc') ^ 'def'
Beispiel #12
0
    def issub_super_set(self):
        a = OrderedSet('abc')
        b = OrderedSet('abcdef')

        a.issubset(a)
        a.issuperset(a)
        a.issubset(a)
        a.issuperset(a)

        assert a <= a
        assert a >= a

        assert a <= b
        assert b >= a

        assert not (a < a)
        assert not (a > a)

        assert a < b
        assert not (a > b)
Beispiel #13
0
 def update(self):
     s = OrderedSet()
     s.update('abc')
     Assert(s) == OrderedSet('abc')
Beispiel #14
0
 def copy(self):
     s = OrderedSet('abc')
     Assert(s.copy()) == s
     Assert(s.copy()).is_not(s)
Beispiel #15
0
 def iteration(self):
     s = OrderedSet([1, 2, 3])
     Assert(list(s)) == [1, 2, 3]
     Assert(list(reversed(s))) == [3, 2, 1]
Beispiel #16
0
 def clear(self):
     s = OrderedSet([1, 2, 3])
     s.clear()
     assert not s
Beispiel #17
0
 def remove(self):
     s = OrderedSet()
     with Assert.raises(KeyError):
         s.remove(1)
     s.add(1)
     s.remove(1)
Beispiel #18
0
 def discard(self):
     s = OrderedSet()
     s.discard(1)
     s.add(1)
     s.discard(1)
     Assert(1).not_in(s)
Beispiel #19
0
 def add(self):
     s = OrderedSet()
     s.add(1)
     Assert(1).in_(s)
Beispiel #20
0
 def contains(self):
     s = OrderedSet([1, 2, 3])
     for element in s:
         Assert(element).in_(s)
     Assert(4).not_in(s)
Beispiel #21
0
 def intersection(self):
     a = OrderedSet('abc')
     Assert(a.intersection('ab', 'a')) == OrderedSet('a')
     Assert(a & OrderedSet('ab')) == OrderedSet('ab')
     with Assert.raises(TypeError):
         a & 'ab'
Beispiel #22
0
 def hashability(self):
     with Assert.raises(TypeError):
         hash(OrderedSet())
Beispiel #23
0
 def length(self):
     Assert(len(OrderedSet([1, 2, 3]))) == 3