Beispiel #1
0
    def test_ranges_zero_to_end(self):
        labels = [
            Label('a', 0, float('inf')),
            Label('b', 5.1, 8.9)
        ]
        ll = LabelList(labels=labels)

        ranges = ll.ranges()

        r = next(ranges)
        assert 0 == r[0]
        assert 5.1 == r[1]
        assert labels[0] in r[2]

        r = next(ranges)
        assert 5.1 == r[0]
        assert 8.9 == r[1]
        assert labels[0] in r[2]
        assert labels[1] in r[2]

        r = next(ranges)
        assert 8.9 == r[0]
        assert float('inf') == r[1]
        assert labels[0] in r[2]

        with pytest.raises(StopIteration):
            next(ranges)
Beispiel #2
0
    def test_ranges_include_labels(self):
        labels = [Label('a', 3.2, 4.5), Label('b', 5.1, 8.9)]
        ll = LabelList(labels=labels)

        ranges = ll.ranges(include_labels=['a'])

        r = next(ranges)
        assert 3.2 == r[0]
        assert 4.5 == r[1]
        assert labels[0] in r[2]

        with pytest.raises(StopIteration):
            next(ranges)
Beispiel #3
0
    def test_ranges_with_empty(self):
        labels = [
            Label('a', 3.2, 4.5),
            Label('b', 5.1, 8.9),
            Label('c', 7.2, 10.5),
            Label('d', 10.5, 14)
        ]
        ll = LabelList(labels=labels)

        ranges = ll.ranges(yield_ranges_without_labels=True)

        r = next(ranges)
        assert 3.2 == r[0]
        assert 4.5 == r[1]
        assert labels[0] in r[2]

        r = next(ranges)
        assert 4.5 == r[0]
        assert 5.1 == r[1]
        assert 0 == len(r[2])

        r = next(ranges)
        assert 5.1 == r[0]
        assert 7.2 == r[1]
        assert labels[1] in r[2]

        r = next(ranges)
        assert 7.2 == r[0]
        assert 8.9 == r[1]
        assert labels[1] in r[2]
        assert labels[2] in r[2]

        r = next(ranges)
        assert 8.9 == r[0]
        assert 10.5 == r[1]
        assert labels[2] in r[2]

        r = next(ranges)
        assert 10.5 == r[0]
        assert 14 == r[1]
        assert labels[3] in r[2]

        with pytest.raises(StopIteration):
            next(ranges)
Beispiel #4
0
    def test_ranges_with_same_start_times(self):
        labels = [Label('a', 1.2, 1.3), Label('b', 1.2, 5.6)]
        ll = LabelList(labels=labels)

        ranges = ll.ranges()

        r = next(ranges)
        assert r[0] == 1.2
        assert r[1] == 1.3
        assert len(r[2]) == 2
        assert labels[0] in r[2]
        assert labels[1] in r[2]

        r = next(ranges)
        assert r[0] == 1.3
        assert r[1] == 5.6
        assert len(r[2]) == 1
        assert labels[1] in r[2]

        with pytest.raises(StopIteration):
            next(ranges)