def test_getattr_attribute():
    class Foo:
        a = None

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

    p = Publisher(Foo(3))
    p.inherit_type(Foo)

    dut = p.a
    m = mock.Mock()
    dut.subscribe(Sink(m))

    m.assert_called_once_with(3)
    assert dut.get() == 3
    m.reset_mock()

    p.notify(Foo(4))

    assert dut.get() == 4

    m.assert_called_once_with(4)

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

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

    dut = p.lower().split(' ')
    m = mock.Mock()
    dut.subscribe(Sink(m))
    m.assert_called_once_with([''])
    m.reset_mock()

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

    dut = op.Len(('abc' + p + 'ghi').upper())
    m = mock.Mock()
    dut.subscribe(Sink(m))
    m.assert_called_once_with(6)
    m.reset_mock()

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

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

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

    dut1.subscribe(Sink(mock1))
    dut2.subscribe(Sink(mock2))
    dut3.subscribe(Sink(mock3))

    assert dut1.get() == []
    assert dut2.get() == ['']
    assert dut3.get() == ['']

    mock1.assert_called_once_with([])
    mock2.assert_called_once_with([''])
    mock3.assert_called_once_with([''])

    mock1.reset_mock()
    mock2.reset_mock()
    mock3.reset_mock()

    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', ''])