Exemplo n.º 1
0
 def test_ordering(self):
     s = mappings.OrderedFrozenSet('set')
     assert 'set' == ''.join(s)
     assert 'tes' == ''.join(reversed(s))
     s = mappings.OrderedFrozenSet('setordered')
     assert 'setord' == ''.join(s)
     assert 'drotes' == ''.join(reversed(s))
Exemplo n.º 2
0
 def test_immmutability(self):
     s = mappings.OrderedFrozenSet(range(9))
     assert len(s) == 9
     with pytest.raises(AttributeError):
         s.add(9)
     with pytest.raises(AttributeError):
         s.discard(0)
     with pytest.raises(AttributeError):
         s.update(range(5))
Exemplo n.º 3
0
    def test_magic_methods(self):
        s = mappings.OrderedFrozenSet(range(9))
        for x in range(9):
            assert x in s
        assert len(s) == 9

        # test indexing support
        for i in range(9):
            assert s[i] == i
        with pytest.raises(IndexError, match='index out of range'):
            s[9]

        assert s == set(range(9))
        assert str(s) == str(set(range(9)))
        assert repr(s) == str(s)
        assert hash(s)
Exemplo n.º 4
0
 def test_symmetric_difference(self):
     s = mappings.OrderedFrozenSet(range(9))
     new = s.symmetric_difference({0, 9})
     assert new == mappings.OrderedFrozenSet(range(1, 10))
     assert new == s ^ {0, 9}
     assert isinstance(new, mappings.OrderedFrozenSet)
Exemplo n.º 5
0
 def test_difference(self):
     s = mappings.OrderedFrozenSet(range(9))
     new = s.difference({8})
     assert new == mappings.OrderedFrozenSet(range(8))
     assert new == s - {8}
     assert isinstance(new, mappings.OrderedFrozenSet)
Exemplo n.º 6
0
 def test_union(self):
     s = mappings.OrderedFrozenSet(range(9))
     new = s.union({9})
     assert new == mappings.OrderedFrozenSet(range(10))
     assert new == s | {9}
     assert isinstance(new, mappings.OrderedFrozenSet)
Exemplo n.º 7
0
 def test_intersection(self):
     s = mappings.OrderedFrozenSet(range(9))
     new = s.intersection({1, 9})
     assert new == mappings.OrderedFrozenSet({1})
     assert new == s & {1, 9}
     assert isinstance(new, mappings.OrderedFrozenSet)