Пример #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))