def get_ranges(self, asset: AssetReference) -> RangeSet: """Get the set of code points covered by the given asset.""" cmap = self.get_best_cmap(asset) range_set = RangeSet() for k, _ in cmap.items(): range_set.append(k) return range_set
def test_pop(): c = RangeSet((1, 2, 5, 6, 7)) assert c.pop() == 7 assert c.pop() == 6 assert c.pop() == 5 assert c.pop() == 2 assert c.pop() == 1 with pytest.raises(KeyError): assert c.pop()
def test_remove(): for i, r, o in _test_remove: c = RangeSet(i) try: if isinstance(r, tuple): c.remove(*r) else: c.remove(r) except KeyError: assert list(i) == o assert list(c) == o, (i, r, o)
def test_disjoint(): for i, j, o in _test_disjoint: i = RangeSet(i) j = RangeSet(j) assert o == i.isdisjoint(j) assert o == j.isdisjoint(i)
def test_create(): for i, o in _test_create: for ii in permutations(i): c = RangeSet(ii) assert list(c) == o, (ii, o)
def test_symmetric_difference(): c = RangeSet((1, 3, 4, 5, 7, 8)) d = RangeSet((3, 4, 7, 8)) e = RangeSet((3, 4, 7, 8, 9)) f = RangeSet((1, 3, 4, 5, 7, 8, 9)) g = RangeSet((5, )) h = RangeSet((1, )) assert c.symmetric_difference(f) == RangeSet((9, )) assert f.symmetric_difference(c) == RangeSet((9, )) assert c.symmetric_difference(d, h) == g assert e.symmetric_difference(f) == g | h assert e.symmetric_difference(f, g) == h assert e.symmetric_difference(f, h) == g assert e.symmetric_difference(g, h) == f assert f.symmetric_difference(g, h) == e assert d.symmetric_difference(d) == RangeSet() assert c ^ d ^ h == g assert e ^ f == g | h assert c == RangeSet((1, 3, 4, 5, 7, 8)) assert f == RangeSet((1, 3, 4, 5, 7, 8, 9)) assert g == RangeSet((5, )) gx = g.copy() gg = g g ^= c ^ h assert gg is g assert g is not d assert g == d ff = f.copy() f.symmetric_difference_update(e) assert f == gx | h ff.symmetric_difference_update(gx, h) assert ff == e assert d == RangeSet((3, 4, 7, 8)) assert e == RangeSet((3, 4, 7, 8, 9)) assert gx == RangeSet((5, )) assert h == RangeSet((1, ))
def test_difference(): c = RangeSet((1, 3, 4, 5, 7, 8)) d = RangeSet((3, 4, 7, 8)) e = RangeSet((3, 4, 7, 8, 9)) f = RangeSet((1, 3, 4, 5, 7, 8, 9)) g = RangeSet((5, )) h = RangeSet((1, )) assert c.difference(d, h) == g assert d.difference(c) == RangeSet() assert f.difference(f) == RangeSet() assert d.difference(f) == RangeSet() assert c.difference(d, g) == h assert c - d - h == g assert d - c == RangeSet() assert f - f == RangeSet() assert g - h == g assert h - g == h assert c == RangeSet((1, 3, 4, 5, 7, 8)) assert f == RangeSet((1, 3, 4, 5, 7, 8, 9)) assert g == RangeSet((5, )) assert h == RangeSet((1, )) cc = c c -= g | h assert cc is c assert c is not d assert c == d ff = f.copy() f.difference_update(e) assert f == g | h ff.difference_update(g, h) assert ff == e assert d == RangeSet((3, 4, 7, 8)) assert e == RangeSet((3, 4, 7, 8, 9))
def test_intersection(): c = RangeSet((1, 3, 4, 5, 7, 8)) d = RangeSet((3, 4, 7, 8)) e = RangeSet((3, 4, 7, 8, 9)) f = RangeSet((1, 3, 4, 5, 7, 8, 9)) g = RangeSet((5, 7)) h = RangeSet((1, )) assert c.intersection(d) == d assert d.intersection(c) == d assert c.intersection(e) == d assert e.intersection(c) == d assert f.intersection(e, g) == RangeSet((7, )) assert c & d == d assert d & c == d assert c & e == d assert c == RangeSet((1, 3, 4, 5, 7, 8)) assert f == RangeSet((1, 3, 4, 5, 7, 8, 9)) assert g == RangeSet((5, 7)) assert h == RangeSet((1, )) cx = c.copy() cc = c c &= d assert cc is c assert c is not d assert c == d cx.intersection_update(e, g) assert cx == RangeSet((7, )) f.intersection_update(e) assert f == e assert d == RangeSet((3, 4, 7, 8)) assert e == RangeSet((3, 4, 7, 8, 9)) assert e == RangeSet((3, 4, 7, 8, 9))
def test_union(): c = RangeSet((1, 3, 4, 5, 7, 8)) d = RangeSet((3, 4, 7, 8)) e = RangeSet((3, 4, 7, 8, 9)) f = RangeSet((1, 3, 4, 5, 7, 8, 9)) g = RangeSet((5, 7)) h = RangeSet((1, )) assert c.union(d) == c assert d.union(c) == c assert c.union(e) == f assert e.union(c) == f assert d.union(h, g) == c assert d.union(g, h) == c assert g.union(h, d) == c assert g.union(d, h) == c assert h.union(g, d) == c assert h.union(d, g) == c assert c | d == c assert d | c == c assert c | e == f assert d == RangeSet((3, 4, 7, 8)) assert e == RangeSet((3, 4, 7, 8, 9)) dd = d d |= c assert dd is d assert d is not c assert d == c e.union_update(g, h) assert e == f assert c == RangeSet((1, 3, 4, 5, 7, 8)) assert g == RangeSet((5, 7)) assert h == RangeSet((1, )) assert f == RangeSet((1, 3, 4, 5, 7, 8, 9))
def test_cmp_etc(): b = RangeSet((1, 3)) c = RangeSet((1, 3, 4, 5, 7, 8)) d = RangeSet((3, 4, 7, 8)) e = RangeSet((3, 4, 7, 8, 9)) f = RangeSet((3, 4, 7, 8, 10)) g = RangeSet((4, 7, 8, 10)) assert b.span() == RangeSet(((1, 4), )) assert c.span() == RangeSet(((1, 9), )) assert g.span() == RangeSet(((4, 11), )) assert c & g == RangeSet((4, 7, 8)) assert c | g == RangeSet((1, 3, 4, 5, 7, 8, 10)) assert b.isdisjoint(g) assert not b.isdisjoint(e) assert d < c assert d <= c assert not d > c assert not d >= c assert c <= c assert c > d assert c >= d assert not c < d assert not c <= d assert c != d assert d != c assert c != f assert f != c assert not (c > f) assert not (c >= f) assert not (c < f) assert not (c <= f) assert not (f > c) assert not (f >= c) assert not (f < c) assert not (f <= c) assert c.issubset(c) assert not c.issubset(c, proper=True) assert not c.issubset(f, proper=False) assert not c.issubset(f, proper=True) assert not f.issubset(c, proper=False) assert not f.issubset(c, proper=True) assert not c.issubset(d, proper=False) assert not c.issubset(d, proper=True) assert d.issubset(c, proper=False) assert d.issubset(c, proper=True) assert c.issuperset(c) assert not c.issuperset(c, proper=True) assert not c.issuperset(f, proper=False) assert not c.issuperset(f, proper=True) assert not f.issuperset(c, proper=False) assert not f.issuperset(c, proper=True) assert c.issuperset(d, proper=False) assert c.issuperset(d, proper=True) assert not d.issuperset(c, proper=False) assert not d.issuperset(c, proper=True) assert c == RangeSet((1, 3, 4, 5, 7, 8)) assert d == RangeSet((3, 4, 7, 8)) assert e == RangeSet((3, 4, 7, 8, 9)) assert f == RangeSet((3, 4, 7, 8, 10))
def test_len(): c = RangeSet() assert len(c) == 0 assert len(cs) == 3 assert cs.count() == 6
else: c.remove(r) except KeyError: assert list(i) == o assert list(c) == o, (i, r, o) def test_disjoint(): for i, j, o in _test_disjoint: i = RangeSet(i) j = RangeSet(j) assert o == i.isdisjoint(j) assert o == j.isdisjoint(i) cs = RangeSet((2, 5, 6, 7, 9, 10)) def test_inside(): assert 0 not in cs assert 1 not in cs assert 2 in cs assert 3 not in cs assert 4 not in cs assert 5 in cs assert 6 in cs assert 7 in cs assert 8 not in cs assert 9 in cs assert 10 in cs assert 11 not in cs
def test_from_offset_string(self): self.assertEqual( RangeSet(ranges=[range( 0, 5), range(9, 10), range(20, 29)]), RangeSet.from_offset_string('0+4,5,11+8'))
def test_to_offset_string_skip_zero(self): r = RangeSet(ranges=[range(3, 5), range(9, 10), range(20, 29)]) self.assertEqual('3+1,5,11+8', r.to_offset_string())
def test_to_offset_string(self): r = RangeSet(ranges=[range(0, 5), range(9, 10), range(20, 29)]) self.assertEqual('0+4,5,11+8', r.to_offset_string())