Skip to content

Commit

Permalink
test: Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ewuerger committed Jan 6, 2025
1 parent 71af412 commit 18bedf1
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-test-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Install test dependencies
run: python -m pip install '.[test]'
- name: Run unit tests
run: python -m pytest --cov-report=term --cov=capella2polarion --rootdir=.
run: python -m pytest --cov-report=term --cov=capella2polarion --rootdir=. -vv

build:
name: Build wheel
Expand Down
2 changes: 1 addition & 1 deletion capella2polarion/converters/converter_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _force_config(
reverse_field=link.get("reverse_field", f"{lf}_reverse"),
)
else:
logger.error(
logger.error( # type: ignore[unreachable]
"Link not configured correctly: %r",
link,
)
Expand Down
10 changes: 8 additions & 2 deletions capella2polarion/data_model/work_item_attachments.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright DB InfraGO AG and contributors
# SPDX-License-Identifier: Apache-2.0
"""Module providing the CapellaWorkItemAttachment classes."""

from __future__ import annotations

import base64
Expand Down Expand Up @@ -116,9 +117,14 @@ def content_checksum(self) -> str:
try:
elk_input = self.diagram.elk_input_data(self.render_params)
if isinstance(elk_input, tuple):
input_str = ";".join(eit.json() for eit in elk_input)
input_str = ";".join(
eit.model_dump_json(exclude_defaults=True)
for eit in elk_input
)
else:
input_str = elk_input.json()
input_str = elk_input.model_dump_json(
exclude_defaults=True
)
self._checksum = hashlib.sha256(
input_str.encode("utf-8")
).hexdigest()
Expand Down
5 changes: 5 additions & 0 deletions tests/data/model_elements/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
links: # Specify workitem links
- parent
- description_reference
serializer:
add_attributes:
- capella_attr: layer
polarion_id: layer
enum_id: layer
Class:
serializer:
add_tree_diagram:
Expand Down
35 changes: 23 additions & 12 deletions tests/test_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
"</li></ul></ul>"
)
}
DIAGRAM_CONFIG = converter_config.CapellaTypeConfig("diagram", "diagram")
DIAGRAM_CONFIG = converter_config.CapellaTypeConfig("diagram", {"diagram": {}})


class GroupedLinksBaseObject(t.TypedDict):
Expand Down Expand Up @@ -345,7 +345,7 @@ def test_create_work_items_with_special_polarion_type(
uuid: data_session.ConverterData(
"oa",
converter_config.CapellaTypeConfig(
_type[0].lower() + _type[1:]
_type[0].lower() + _type[1:], {}
),
model.by_uuid(uuid),
)
Expand Down Expand Up @@ -1369,6 +1369,7 @@ def test_grouped_links_attributes_with_includes(
ex = model.by_uuid(TEST_SYS_FNC_EX)
fnc_config = converter_config.CapellaTypeConfig(
"systemFunction",
{},
links=[
converter_config.LinkConfig(
capella_attr="inputs.exchanges",
Expand All @@ -1381,6 +1382,7 @@ def test_grouped_links_attributes_with_includes(
)
ex_config = converter_config.CapellaTypeConfig(
"systemFunctionalExchange",
{},
links=[
converter_config.LinkConfig(
capella_attr="exchange_items",
Expand All @@ -1390,7 +1392,7 @@ def test_grouped_links_attributes_with_includes(
)
],
)
ex_item_config = converter_config.CapellaTypeConfig("exchangeItem")
ex_item_config = converter_config.CapellaTypeConfig("exchangeItem", {})
base_object.mc.converter_session = {
TEST_SYS_FNC: data_session.ConverterData(
"sa", fnc_config, fnc, None
Expand Down Expand Up @@ -1578,9 +1580,7 @@ def test_grouped_linked_work_items_order_consistency(
base_object.pw.polarion_params.project_id,
base_object.c2pcli.capella_model,
)
config = converter_config.CapellaTypeConfig(
"fakeModelObject",
)
config = converter_config.CapellaTypeConfig("fakeModelObject", {})
work_item = data_model.CapellaWorkItem("id", title="Dummy")
converter_data = data_session.ConverterData(
"test", config, FakeModelObject(""), work_item
Expand Down Expand Up @@ -1863,12 +1863,19 @@ def test_generic_work_item(
def test_add_attributes(self, model: capellambse.MelodyModel):
converters = {
"add_attributes": [
{
"capella_attr": "layer",
"polarion_id": "layer",
"enum_id": "layer",
},
{"capella_attr": "nature", "polarion_id": "nature"},
{"capella_attr": "kind", "polarion_id": "kind"},
]
}
type_config = converter_config.CapellaTypeConfig(
"PhysicalComponent", converters, []
"PhysicalComponent",
converter_config.CapellaTypeConfig._force_dict(converters),
[],
)
serializer = element_converter.CapellaWorkItemSerializer(
model,
Expand All @@ -1886,13 +1893,14 @@ def test_add_attributes(self, model: capellambse.MelodyModel):
work_item = serializer.serialize(TEST_PHYS_COMP)

assert work_item is not None
assert work_item.nature == {"type": "string", "value": "UNSET"}
assert work_item.kind == {"type": "string", "value": "UNSET"}
assert work_item.layer == {"type": "enum:layer", "value": "pa"}
assert work_item.nature == "UNSET"
assert work_item.kind == "UNSET"

@staticmethod
def test_add_context_diagram(model: capellambse.MelodyModel):
type_config = converter_config.CapellaTypeConfig(
"test", "add_context_diagram", []
"test", {"add_context_diagram": {}}, []
)
serializer = element_converter.CapellaWorkItemSerializer(
model,
Expand Down Expand Up @@ -1951,6 +1959,9 @@ def test_add_context_diagram_with_params(
type_config = converter_config.CapellaTypeConfig(
"systemFunction", config, []
)
type_config.converters = (
converter_config.CapellaTypeConfig._force_dict(config)
)
expected_filter = getattr(filters, context_diagram_filter)
monkeypatch.setattr(
element_converter.CapellaWorkItemSerializer,
Expand Down Expand Up @@ -2034,7 +2045,7 @@ def test_multiple_serializers(model: capellambse.MelodyModel, prefix: str):
cap = model.by_uuid(TEST_OCAP_UUID)
type_config = converter_config.CapellaTypeConfig(
f"{prefix}_test" if prefix else "test",
["include_pre_and_post_condition", "add_context_diagram"],
{"include_pre_and_post_condition": {}, "add_context_diagram": {}},
[],
)
serializer = element_converter.CapellaWorkItemSerializer(
Expand Down Expand Up @@ -2233,7 +2244,7 @@ def test_read_config_links(caplog: pytest.LogCaptureFixture):
@staticmethod
def test_add_context_diagram_with_caption(model: capellambse.MelodyModel):
type_config = converter_config.CapellaTypeConfig(
"test", "add_context_diagram", []
"test", {"add_context_diagram": {}}, []
)
serializer = element_converter.CapellaWorkItemSerializer(
model,
Expand Down
Loading

0 comments on commit 18bedf1

Please sign in to comment.