Esempio n. 1
0
def test_component_detaches_from_child_after_child_is_remove():
    component = Component(view=Mock(), presenter=Mock())

    mock_cfactory = MockComponentFactory()
    new_child = component.new_component(mock_cfactory)
    component.remove_component(new_child)

    assert new_child.on_destroyed.num_connections == 0
Esempio n. 2
0
def test_component_remove_component():
    component = Component(view=Mock(), presenter=Mock())

    mock_cfactory = MockComponentFactory()
    mock_child = tcast(Mock, component.new_component(mock_cfactory))

    component.remove_component(mock_child)

    mock_child.destroy.assert_called_once_with()

    # Should raise an error if we try to remove again.
    with pytest.raises(ValueError):
        component.remove_component(mock_child)
Esempio n. 3
0
def test_component_removes_child_if_child_is_destroyed():
    component = Component(view=Mock(), presenter=Mock())

    mock_cfactory = MockComponentFactory()
    new_child = tcast(MockComponent, component.new_component(mock_cfactory))

    new_child.sim_destroy()

    # Should raise an error since child should have been automatically removed after it is destroyed.
    with pytest.raises(ValueError):
        component.remove_component(new_child)

    # Child should not be destroyed again by previous call to `component.remove_component()`
    new_child.destroy.assert_not_called()