示例#1
0
def test_sink_partial(operator_cls):
    cb = mock.Mock()

    s = Value()
    sink_instance = s.subscribe(operator_cls(cb, 1, 2, 3, a=1))
    assert isinstance(sink_instance, Disposable)

    assert not cb.called
    assert len(s.subscriptions) == 1

    # test various emits on source
    s.emit(None)
    cb.assert_called_with(1, 2, 3, None, a=1)

    s.emit(1)
    cb.assert_called_with(1, 2, 3, 1, a=1)

    s.emit((1, 2))
    cb.assert_called_with(1, 2, 3, (1, 2), a=1)

    # testing dispose()
    cb.reset_mock()

    sink_instance.dispose()
    assert len(s.subscriptions) == 0

    s.emit(1)
    assert not cb.called
示例#2
0
def test_sink(operator_cls):
    cb = mock.Mock()

    s = Value()
    sink_instance = s.subscribe(operator_cls(cb))
    assert isinstance(sink_instance, Disposable)

    assert not cb.called
    assert len(s.subscriptions) == 1

    # test various emits on source
    with pytest.raises(TypeError):
        s.emit()

    s.emit(None)
    cb.assert_called_with(None)

    s.emit(1)
    cb.assert_called_with(1)

    s.emit((1, 2))
    cb.assert_called_with((1, 2))

    # testing dispose()s
    cb.reset_mock()

    sink_instance.dispose()
    assert len(s.subscriptions) == 0

    s.emit(1)
    assert not cb.called
示例#3
0
def test_sink_without_function(operator_cls):
    s = Value()
    sink_instance = s.subscribe(operator_cls())
    assert isinstance(sink_instance, Disposable)
    assert len(s.subscriptions) == 1

    s.emit(1)
示例#4
0
def test_sink2(operator_cls):
    cb = mock.Mock()

    s = Value()
    sink_instance = s.subscribe(operator_cls(cb, unpack=True))
    assert isinstance(sink_instance, Disposable)

    # test various emits on source
    with pytest.raises(TypeError):
        s.emit()

    with pytest.raises(TypeError):
        s.emit(1)

    cb.assert_not_called()

    s.emit((1, 2))
    cb.assert_called_with(1, 2)
示例#5
0
def test_sink_on_subscription(operator):
    cb = mock.Mock()

    s = Value(0)
    sink_instance = s.subscribe(operator(cb))
    assert isinstance(sink_instance, Disposable)

    cb.assert_called_with(0)
    assert len(s.subscriptions) == 1

    s.emit(1)
    cb.assert_called_with(1)

    # testing dispose()
    cb.reset_mock()

    sink_instance.dispose()
    assert len(s.subscriptions) == 0

    s.emit(1)
    assert not cb.called