Esempio n. 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()
Esempio n. 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()
Esempio n. 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()
Esempio n. 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()
Esempio n. 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()
Esempio n. 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()
Esempio n. 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()
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 11
0
def test_seq_empty_list():
    nxt = seq([])
    with pytest.raises(StopIteration):
        nxt()
Esempio n. 12
0
def test_seq_empty_generator():
    nxt = seq(i for i in [])
    with pytest.raises(StopIteration):
        nxt()
Esempio n. 13
0
def test_seq_empty_list_iterator():
    nxt = seq(iter([]))
    with pytest.raises(StopIteration):
        nxt()
Esempio n. 14
0
def test_seq_empty_generator():
    nxt = seq(i for i in [])
    with pytest.raises(StopIteration):
        nxt()
Esempio n. 15
0
def test_seq_empty_list_iterator():
    nxt = seq(iter([]))
    with pytest.raises(StopIteration):
        nxt()
Esempio n. 16
0
def test_seq_empty_list():
    nxt = seq([])
    with pytest.raises(StopIteration):
        nxt()