示例#1
0
def test_non_int():
    with pytest.raises(TypeError):
        range2(5.5)
    with pytest.raises(TypeError):
        range2("5")
    with pytest.raises(TypeError):
        range2(5, 6.5)
示例#2
0
def test_zero_step():
    with pytest.raises(ValueError):
        range2(2, 10, 0)
示例#3
0
def test_start_stop_negative_step_invalid():
    # careful -- this one could never terminate if done wrong!
    assert list(range(2, 10, -2)) == list(range2(2, 10, -2))
示例#4
0
def test_restart():
    r2 = range2(10)
    for i in r2:
        if i > 5:
            break
    assert [i for i in r2] == list(range2(10))
示例#5
0
def test_start_stop_negative():
    assert list(range(3, 8)) == list(range2(3, 8))
示例#6
0
def test_start_stop_step():
    assert list(range(2, 10, 2)) == list(range2(2, 10, 2))
示例#7
0
def test_start_negative():
    assert list(range(-3, 4)) == list(range2(-3, 4))
示例#8
0
def test_start_stop_same():
    assert list(range2(3, 3)) == []
示例#9
0
def test_negative_stop():
    assert list(range2(-1)) == []
示例#10
0
def test_just_stop():
    assert list(range(5)) == list(range2(5))
示例#11
0
def test_not_call_iter():
    """
    If you try to call next directly it should raise an error.
    """
    with pytest.raises(TypeError):
        next(range2(3))