예제 #1
0
def test_seq_generator():
    nxt = seq(i for i in [sentinel.val1, sentinel.val2, sentinel.val3])
    assert nxt() == sentinel.val1
    assert nxt() == sentinel.val2
    assert nxt() == sentinel.val3
    with pytest.raises(StopIteration):
        nxt()
예제 #2
0
def test_seq_generator():
    nxt = seq(i for i in [sentinel.val1, sentinel.val2, sentinel.val3])
    assert nxt() == sentinel.val1
    assert nxt() == sentinel.val2
    assert nxt() == sentinel.val3
    with pytest.raises(StopIteration):
        nxt()
예제 #3
0
def test_seq_list_iterator():
    nxt = seq(iter(iter([sentinel.val1, sentinel.val2, sentinel.val3])))
    assert nxt() == sentinel.val1
    assert nxt() == sentinel.val2
    assert nxt() == sentinel.val3
    with pytest.raises(StopIteration):
        nxt()
예제 #4
0
def test_seq_list_iterator():
    nxt = seq(iter(iter([sentinel.val1, sentinel.val2, sentinel.val3])))
    assert nxt() == sentinel.val1
    assert nxt() == sentinel.val2
    assert nxt() == sentinel.val3
    with pytest.raises(StopIteration):
        nxt()
예제 #5
0
def test_seq_raises_exceptions():
    nxt = seq([sentinel.val1, RuntimeError, RuntimeError(sentinel.val2), sentinel.val3])
    assert nxt() == sentinel.val1

    with pytest.raises(RuntimeError):
        nxt()

    with pytest.raises(RuntimeError) as err:
        nxt()
    assert str(err.value) == str(sentinel.val2)

    assert nxt() == sentinel.val3

    with pytest.raises(StopIteration):
        nxt()
예제 #6
0
def test_seq_raises_exceptions():
    nxt = seq([sentinel.val1, RuntimeError, RuntimeError(sentinel.val2), sentinel.val3])
    assert nxt() == sentinel.val1

    with pytest.raises(RuntimeError):
        nxt()

    try:
        nxt()
    except RuntimeError as e:
        assert e.message == sentinel.val2
    else:
        assert False

    assert nxt() == sentinel.val3

    with pytest.raises(StopIteration):
        nxt()
예제 #7
0
def test_seq_raises_exceptions():
    nxt = seq([
        sentinel.val1, RuntimeError,
        RuntimeError(sentinel.val2), sentinel.val3
    ])
    assert nxt() == sentinel.val1

    with pytest.raises(RuntimeError):
        nxt()

    with pytest.raises(RuntimeError) as err:
        nxt()
    assert str(err.value) == str(sentinel.val2)

    assert nxt() == sentinel.val3

    with pytest.raises(StopIteration):
        nxt()
예제 #8
0
def test_stub_sequence_of_results_from_iterator():
    mock_fn = Mock()
    results = iter([sentinel.foo, sentinel.bar, RuntimeError, RuntimeError(sentinel.boom), sentinel.all_ok_now])
    mock_fn.side_effect = stub((call(sentinel.argfoo), seq(results)))

    assert mock_fn(sentinel.argfoo) == sentinel.foo

    assert mock_fn(sentinel.argfoo) == sentinel.bar

    with pytest.raises(RuntimeError):
        mock_fn(sentinel.argfoo)
        
    with pytest.raises(RuntimeError) as err:
        mock_fn(sentinel.argfoo)
    assert str(err.value) == str(sentinel.boom)

    assert mock_fn(sentinel.argfoo) == sentinel.all_ok_now

    with pytest.raises(StopIteration):
        mock_fn(sentinel.argfoo)
예제 #9
0
def test_stub_sequence_of_results_from_iterator():
    mock_fn = Mock()
    results = iter([sentinel.foo, sentinel.bar, RuntimeError, RuntimeError(sentinel.boom), sentinel.all_ok_now])
    mock_fn.side_effect = stub((call(sentinel.argfoo), seq(results)))

    assert mock_fn(sentinel.argfoo) == sentinel.foo

    assert mock_fn(sentinel.argfoo) == sentinel.bar

    with pytest.raises(RuntimeError):
        mock_fn(sentinel.argfoo)

    try:
        mock_fn(sentinel.argfoo)
    except RuntimeError as e:
        assert e.message == sentinel.boom
    else:
        assert False

    assert mock_fn(sentinel.argfoo) == sentinel.all_ok_now

    with pytest.raises(StopIteration):
        mock_fn(sentinel.argfoo)
예제 #10
0
def test_stub_sequence_of_results_from_iterator():
    mock_fn = Mock()
    results = iter([
        sentinel.foo, sentinel.bar, RuntimeError,
        RuntimeError(sentinel.boom), sentinel.all_ok_now
    ])
    mock_fn.side_effect = stub((call(sentinel.argfoo), seq(results)))

    assert mock_fn(sentinel.argfoo) == sentinel.foo

    assert mock_fn(sentinel.argfoo) == sentinel.bar

    with pytest.raises(RuntimeError):
        mock_fn(sentinel.argfoo)

    with pytest.raises(RuntimeError) as err:
        mock_fn(sentinel.argfoo)
    assert str(err.value) == str(sentinel.boom)

    assert mock_fn(sentinel.argfoo) == sentinel.all_ok_now

    with pytest.raises(StopIteration):
        mock_fn(sentinel.argfoo)
예제 #11
0
def test_seq_empty_list():
    nxt = seq([])
    with pytest.raises(StopIteration):
        nxt()
예제 #12
0
def test_seq_empty_generator():
    nxt = seq(i for i in [])
    with pytest.raises(StopIteration):
        nxt()
예제 #13
0
def test_seq_empty_list_iterator():
    nxt = seq(iter([]))
    with pytest.raises(StopIteration):
        nxt()
예제 #14
0
def test_seq_empty_generator():
    nxt = seq(i for i in [])
    with pytest.raises(StopIteration):
        nxt()
예제 #15
0
def test_seq_empty_list_iterator():
    nxt = seq(iter([]))
    with pytest.raises(StopIteration):
        nxt()
예제 #16
0
def test_seq_empty_list():
    nxt = seq([])
    with pytest.raises(StopIteration):
        nxt()