コード例 #1
0
def test_container_adding_component_twice_is_ok(
        model_with_container: MockModel):
    """Defensive check that adding the same component twice is OK."""
    empty_container = model_with_container.empty_container
    component = Component(name="Component")
    empty_container += component
    empty_container += component
    assert len(empty_container.components) == 1
コード例 #2
0
def test_container_add_constructed_component(model_with_container: MockModel):
    """Verify behaviour when adding a newly constructed Container."""
    empty_container = model_with_container.empty_container
    component = Component(name="Component")
    empty_container += component
    assert component in empty_container.components
    assert component.id != ""
    assert component.model is model_with_container
    assert component.parent is empty_container
コード例 #3
0
def test_container_adding_component_with_same_name_fails(
    model_with_container: MockModel, ):
    """Check that adding a component with the same name as an existing one fails."""
    empty_container = model_with_container.empty_container
    empty_container.add_component(name="Component")
    with pytest.raises(ValueError,
                       match="Component with name .* already exists"):
        empty_container.add_component(name="Component")
    with pytest.raises(ValueError,
                       match="Component with name .* already exists"):
        empty_container += Component(name="Component")
コード例 #4
0
def test_model_add_component_must_have_parent(empty_model: Model):
    """Ensure that Model rejects adding Components that aren't within a Container."""
    component = Component(name="c1")
    with pytest.raises(ValueError, match="Element with name .* has no parent"):
        empty_model += component