def test_index(range_creator):
    build_range = range_creator.create(range(10))
    # no build_info fetched yet, so ValueError is raised
    with pytest.raises(ValueError):
        build_range.index(5)

    mid = build_range.mid_point()
    assert mid == 5
    assert mid == build_range.index(5)
示例#2
0
def test_index(range_creator):
    build_range = range_creator.create(range(10))
    # no build_info fetched yet, so ValueError is raised
    with pytest.raises(ValueError):
        build_range.index(5)

    mid = build_range.mid_point()
    assert mid == 5
    assert mid == build_range.index(5)
示例#3
0
def test_mid_point(range_creator):
    build_range = range_creator.create(range(10))
    fetch_unless(build_range, lambda i: i == 9)

    assert build_range.mid_point() == 4
    assert len(build_range) == 9
    assert [build_range[i] for i in range(9)] == range(9)

    # with a range len < 3, mid is 0.
    assert build_range[:2].mid_point() == 0
示例#4
0
def test_mid_point(range_creator):
    build_range = range_creator.create(range(10))
    fetch_unless(build_range, lambda i: i == 9)

    assert build_range.mid_point() == 4
    assert len(build_range) == 9
    assert [build_range[i] for i in range(9)] == range(9)

    # with a range len < 3, mid is 0.
    assert build_range[:2].mid_point() == 0
def test_mid_point(range_creator):
    build_range = range_creator.create(range(10))

    def fetch(index):
        # last build info can't be fetched
        if index == 9:
            raise BuildInfoNotFound("")
        return index

    build_range.build_info_fetcher.find_build_info.side_effect = fetch

    assert build_range.mid_point() == 4
    assert len(build_range) == 9
    assert [build_range[i] for i in range(9)] == range(9)

    # with a range len < 3, mid is 0.
    assert build_range[:2].mid_point() == 0
示例#6
0
def test_mid_point(range_creator):
    build_range = range_creator.create(range(10))

    def fetch(index):
        # last build info can't be fetched
        if index == 9:
            raise BuildInfoNotFound("")
        return index

    build_range.build_info_fetcher.find_build_info.side_effect = fetch

    assert build_range.mid_point() == 4
    assert len(build_range) == 9
    assert [build_range[i] for i in range(9)] == range(9)

    # with a range len < 3, mid is 0.
    assert build_range[:2].mid_point() == 0
def test_mid_point_interrupt(range_creator):
    build_range = range_creator.create(range(10))
    assert build_range.mid_point(interrupt=lambda: False) == 5
    with pytest.raises(StopIteration):
        build_range.mid_point(interrupt=lambda: True)
示例#8
0
def test_mid_point_interrupt(range_creator):
    build_range = range_creator.create(range(10))
    assert build_range.mid_point(interrupt=lambda: False) == 5
    with pytest.raises(StopIteration):
        build_range.mid_point(interrupt=lambda: True)