|
16 | 16 |
|
17 | 17 | import pytest |
18 | 18 |
|
19 | | -from structurizr.model import Component, Container, Model, SoftwareSystem |
| 19 | +from structurizr.model import Component, Container, Model |
20 | 20 |
|
21 | 21 |
|
22 | 22 | _model = Model() |
@@ -44,47 +44,44 @@ def test_container_init(attributes): |
44 | 44 |
|
45 | 45 |
|
46 | 46 | def test_container_add_component_adds_to_component_list(empty_container: Container): |
47 | | - """Ensure that add_component() adds the new component to Container.components and sets up other properties.""" |
| 47 | + """Verify add_component() adds the new component to Container.components.""" |
48 | 48 | component = empty_container.add_component(name="Component") |
49 | 49 | assert component in empty_container.components |
50 | 50 | assert component.id != "" |
51 | 51 | assert component.model is _model |
52 | 52 | assert component.parent is empty_container |
53 | 53 |
|
54 | 54 |
|
55 | | -@pytest.mark.xfail(strict=True) |
56 | 55 | def test_container_add_constructed_component(empty_container: Container): |
57 | | - """Verify behaviour when adding a newly constructed Container rather than calling add_container().""" |
| 56 | + """Verify behaviour when adding a newly constructed Container.""" |
58 | 57 | component = Component(name="Component") |
59 | | - empty_container.add(component) |
| 58 | + empty_container += component |
60 | 59 | assert component in empty_container.components |
61 | | - assert component.id != "" # Currently failing |
62 | | - assert component.model is _model # Currently failing |
63 | | - assert component.parent is empty_container # Currently failing |
| 60 | + assert component.id != "" |
| 61 | + assert component.model is _model |
| 62 | + assert component.parent is empty_container |
64 | 63 |
|
65 | 64 |
|
66 | 65 | def test_container_adding_component_twice_is_ok(empty_container: Container): |
67 | 66 | """Defensive check that adding the same component twice is OK.""" |
68 | 67 | component = Component(name="Component") |
69 | | - empty_container.add(component) |
70 | | - empty_container.add(component) |
| 68 | + empty_container += component |
| 69 | + empty_container += component |
71 | 70 | assert len(empty_container.components) == 1 |
72 | 71 |
|
73 | 72 |
|
74 | | -@pytest.mark.xfail(strict=True) |
75 | 73 | def test_container_adding_component_with_same_name_fails(empty_container: Container): |
76 | | - """Defensive check that adding a component with the same name as an existing one fails.""" |
| 74 | + """Check that adding a component with the same name as an existing one fails.""" |
77 | 75 | empty_container.add_component(name="Component") |
78 | 76 | with pytest.raises(ValueError, match="Component with name .* already exists"): |
79 | 77 | empty_container.add_component(name="Component") |
80 | 78 | with pytest.raises(ValueError, match="Component with name .* already exists"): |
81 | | - empty_container.add(Component(name="Component")) # Doesn't currently raise |
| 79 | + empty_container += Component(name="Component") |
82 | 80 |
|
83 | 81 |
|
84 | | -@pytest.mark.xfail(strict=True) |
85 | 82 | def test_adding_component_with_existing_parent_fails(empty_container: Container): |
86 | | - """Defensive check that if a component already has a (different) parent then it can't be added.""" |
| 83 | + """Check that adding a component with a different parent fails.""" |
87 | 84 | container2 = _system.add_container(name="Container 2", description="Description") |
88 | 85 | component = empty_container.add_component(name="Component") |
89 | | - with pytest.raises(ValueError): |
90 | | - container2.add(component) # Doesn't currently raise |
| 86 | + with pytest.raises(ValueError, match="Component with name .* already has parent"): |
| 87 | + container2 += component |
0 commit comments