Skip to content

Commit

Permalink
ci: Fix some mypy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ewuerger committed Aug 26, 2024
1 parent 8f9b1e6 commit 270965c
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ repos:
- capellambse==0.5.69
- click
- jinja2
- polarion-rest-api-client==1.1.0
- polarion-rest-api-client==1.1.1
- pydantic
- types-requests
- types-PyYAML
Expand Down
4 changes: 0 additions & 4 deletions capella2polarion/connectors/polarion_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ def __sizeof__(self) -> int:
"""Return the amount of registered Capella UUIDs."""
return len(self._id_mapping)

def __getitem__(self, item: str) -> data_models.CapellaWorkItem:
"""Return the work_item for a given Capella UUID."""
return self._work_items[item]

def __iter__(self) -> cabc.Iterator[str]:
"""Iterate all Capella UUIDs."""
return self._id_mapping.__iter__()
Expand Down
4 changes: 3 additions & 1 deletion capella2polarion/connectors/polarion_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ def compare_and_update_work_item(
new = converter_data.work_item
assert new is not None
uuid = new.uuid_capella
old: data_models.CapellaWorkItem | None = self.polarion_data_repo[uuid]
old: data_models.CapellaWorkItem | None = (
self.polarion_data_repo.get_work_item_by_capella_uuid(uuid)
)
assert old is not None
assert isinstance(old.id, str)

Expand Down
1 change: 1 addition & 0 deletions capella2polarion/converters/converter_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ def _force_link_config(links: t.Any) -> list[LinkConfig]:
def _filter_links(
c_type: str, links: list[LinkConfig], is_global: bool = False
):
c_class: type[common.ModelObject | diagram.Diagram]
if c_type == "diagram":
c_class = diagram.Diagram
else:
Expand Down
19 changes: 10 additions & 9 deletions capella2polarion/converters/document_config.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# Copyright DB InfraGO AG and contributors
# SPDX-License-Identifier: Apache-2.0
"""Module with classes and a loader for document rendering configs."""
import collections.abc as cabc
import logging
import pathlib
import typing as t

import capellambse
import jinja2
import polarion_rest_api_client as polarion_api
import pydantic
import yaml
from polarion_rest_api_client import data_models

from capella2polarion.converters import polarion_html_helper

Expand Down Expand Up @@ -51,7 +52,7 @@ class BaseDocumentRenderingConfig(pydantic.BaseModel):
work_item_layouts: dict[str, WorkItemLayout] = pydantic.Field(
default_factory=dict
)
instances: list[DocumentRenderingInstance]
instances: cabc.Sequence[DocumentRenderingInstance]


class FullAuthorityDocumentRenderingConfig(BaseDocumentRenderingConfig):
Expand All @@ -64,7 +65,7 @@ class MixedAuthorityDocumentRenderingConfig(BaseDocumentRenderingConfig):
"""Mixed authority document with multiple auto generated sections."""

sections: dict[str, str]
instances: list[SectionBasedDocumentRenderingInstance]
instances: cabc.Sequence[SectionBasedDocumentRenderingInstance]


class DocumentConfigs(pydantic.BaseModel):
Expand Down Expand Up @@ -101,28 +102,28 @@ def read_config_file(

def generate_work_item_layouts(
configs: dict[str, WorkItemLayout]
) -> list[polarion_api.RenderingLayout]:
) -> list[data_models.RenderingLayout]:
"""Create polarion_api.RenderingLayouts for a given configuration."""
results = []
for _type, conf in configs.items():
if conf.show_title and conf.show_description:
layouter = polarion_api.data_models.Layouter.SECTION
layouter = data_models.Layouter.SECTION
elif conf.show_description:
layouter = polarion_api.data_models.Layouter.PARAGRAPH
layouter = data_models.Layouter.PARAGRAPH
else:
if not conf.show_title:
logger.warning(
"Either the title or the description must be shown."
"For that reason, the title will be shown for %s.",
_type,
)
layouter = polarion_api.data_models.Layouter.TITLE
layouter = data_models.Layouter.TITLE
results.append(
polarion_api.RenderingLayout(
data_models.RenderingLayout(
type=_type,
layouter=layouter,
label=polarion_html_helper.camel_case_to_words(_type),
properties=polarion_api.data_models.RenderingProperties(
properties=data_models.RenderingProperties(
fields_at_start=conf.fields_at_start,
fields_at_end=conf.fields_at_end,
fields_at_end_as_table=conf.show_fields_as_table,
Expand Down
1 change: 1 addition & 0 deletions capella2polarion/converters/element_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ def __insert_diagram(
),
None,
):
assert attachment.file_name is not None
return polarion_html_helper.generate_image_html(
diagram.name,
attachment.file_name,
Expand Down
2 changes: 1 addition & 1 deletion capella2polarion/converters/link_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

TYPE_RESOLVERS = {"Part": lambda obj: obj.type.uuid}
_Serializer: t.TypeAlias = cabc.Callable[
[common.GenericElement, str, str, dict[str, t.Any]],
[diag.Diagram | common.GenericElement, str, str, dict[str, t.Any]],
list[polarion_api.WorkItemLink],
]

Expand Down
18 changes: 13 additions & 5 deletions tests/test_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,11 @@ def test_update_links(base_object: BaseObjectContainer):
link = polarion_api.WorkItemLink(
"Obj-1", "Obj-2", "attribute", True, "project_id"
)
work_item = base_object.pw.polarion_data_repo["uuid1"]
work_item = (
base_object.pw.polarion_data_repo.get_work_item_by_capella_uuid(
"uuid1"
)
)
work_item.linked_work_items = [link]
base_object.pw.polarion_data_repo.update_work_items(
[
Expand Down Expand Up @@ -993,11 +997,15 @@ def test_update_links(base_object: BaseObjectContainer):
base_object.pw.polarion_data_repo
)

work_item_1 = data_models.CapellaWorkItem(
**base_object.pw.polarion_data_repo["uuid1"].to_dict()
work_item_1 = (
base_object.pw.polarion_data_repo.get_work_item_by_capella_uuid(
"uuid1"
)
)
work_item_2 = data_models.CapellaWorkItem(
**base_object.pw.polarion_data_repo["uuid2"].to_dict()
work_item_2 = (
base_object.pw.polarion_data_repo.get_work_item_by_capella_uuid(
"uuid2"
)
)
work_item_1.linked_work_items_truncated = True
work_item_2.linked_work_items_truncated = True
Expand Down

0 comments on commit 270965c

Please sign in to comment.