def test_getattr_attribute():
    p = StatefulPublisher()

    class Foo:
        a = None

        def __init__(self, a=5):
            self.a = a

    p.inherit_type(Foo)

    dut = p.a
    m = mock.Mock()
    dut | op.Sink(m)

    with pytest.raises(ValueError):
        dut.get()

    m.assert_not_called()

    p.notify(Foo(3))

    assert dut.get() == 3

    m.assert_called_once_with(3)

    with pytest.raises(ValueError):
        dut.emit_op(0, who=Publisher())

    with pytest.raises(AttributeError):
        dut.assnign(5)
def test_inherit_getattr():
    p = StatefulPublisher()
    p.inherit_type(str)

    dut = p.lower().split(' ')
    m = mock.Mock()
    dut | op.Sink(m)

    p.notify('This is a TEST')
    m.assert_called_once_with(['this', 'is', 'a', 'test'])
def test_inherit_with_operators():
    p = StatefulPublisher()
    p.inherit_type(str)

    dut = op.Len(('abc' + p + 'ghi').upper())
    m = mock.Mock()
    dut | op.Sink(m)

    p.notify('def')
    m.assert_called_once_with(9)
def test_getattr_method():
    p = StatefulPublisher()
    p.inherit_type(str)

    dut1 = p.split()
    dut2 = p.split(',')
    dut3 = p.split(sep='!')

    mock1 = mock.Mock()
    mock2 = mock.Mock()
    mock3 = mock.Mock()

    dut1 | op.Sink(mock1)
    dut2 | op.Sink(mock2)
    dut3 | op.Sink(mock3)

    with pytest.raises(ValueError):
        dut1.get()

    with pytest.raises(ValueError):
        dut2.get()

    with pytest.raises(ValueError):
        dut3.get()

    mock1.assert_not_called()
    mock2.assert_not_called()
    mock3.assert_not_called()

    p.notify('This is just a test, honestly!')

    assert dut1.get() == ['This', 'is', 'just', 'a', 'test,', 'honestly!']
    assert dut2.get() == ['This is just a test', ' honestly!']
    assert dut3.get() == ['This is just a test, honestly', '']

    mock1.assert_called_once_with(
        ['This', 'is', 'just', 'a', 'test,', 'honestly!'])
    mock2.assert_called_once_with(['This is just a test', ' honestly!'])
    mock3.assert_called_once_with(['This is just a test, honestly', ''])