Skip to content

Commit

Permalink
removed some obsolete code
Browse files Browse the repository at this point in the history
  • Loading branch information
deichmab-draeger committed Nov 21, 2024
1 parent e0cfc41 commit ea66398
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 29 deletions.
8 changes: 4 additions & 4 deletions src/sdc11073/entity_mdib/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def get_xsi_type(element: LxmlElement) -> QName:
_xsi_type = QName(element.tag)
try:
return _static_type_lookup[_xsi_type]
except KeyError as err:
except KeyError as err: # pragma: no cover
raise KeyError(str(_xsi_type)) from err


Expand Down Expand Up @@ -139,7 +139,7 @@ def __init__(self,
self._mdib: EntityConsumerMdib = mdib

cls = mdib.sdc_definitions.data_model.get_descriptor_container_class(source.node_type)
if cls is None:
if cls is None: # pragma: no cover
raise ValueError(f'do not know how to make container from {source.node_type!s}')
handle = source.descriptor.get('Handle')
self.descriptor: AbstractDescriptorContainer = cls(handle, parent_handle=source.parent_handle)
Expand Down Expand Up @@ -242,7 +242,7 @@ def new_state(self, state_handle: str | None = None) -> AbstractMultiStateContai
If this new state is used as a proposed context state in SetContextState operation, this means a new
state shall be created on providers side.
"""
if state_handle in self.states:
if state_handle in self.states: # pragma: no cover
raise ValueError(
f'State handle {state_handle} already exists in {self.__class__.__name__}, handle = {self.handle}')
cls = self._mdib.data_model.get_state_container_class(self.descriptor.STATE_QNAME)
Expand Down Expand Up @@ -409,7 +409,7 @@ def is_multi_state(self) -> bool:
def update(self):
"""Update from internal entity."""
source_entity = self._mdib.internal_entities.get(self.handle)
if source_entity is None:
if source_entity is None: # pragma: no cover
raise ValueError(f'entity {self.handle} no longer exists in mdib')
self.descriptor.update_from_other_container(source_entity.descriptor)
for handle, src_state in source_entity.states.items():
Expand Down
2 changes: 1 addition & 1 deletion src/sdc11073/entity_mdib/entity_consumermdib.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
@dataclass
class _BufferedData:
received_message_data: ReceivedMessage
handler: callable
handler: Callable


multi_state_q_names = (pm_qnames.PatientContextDescriptor,
Expand Down
2 changes: 1 addition & 1 deletion src/sdc11073/entity_mdib/entity_providermdibxtra.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def set_initial_content(self,
descriptor_containers: list[AbstractDescriptorContainer],
state_containers: list[AbstractStateContainer]):
"""Add states."""
if self._mdib.is_initialized:
if self._mdib.is_initialized: # pragma: no cover
raise ApiUsageError('method "set_initial_content" can not be called when mdib is already initialized')
for d in descriptor_containers:
states = [s for s in state_containers if s.DescriptorHandle == d.Handle]
Expand Down
30 changes: 7 additions & 23 deletions src/sdc11073/entity_mdib/entity_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ def _update_multi_states(mdib: EntityProviderMdib, # noqa: C901
old: ProviderMultiStateEntity,
modified_handles: list[str] | None = None,
adjust_state_version: bool = True):
if not (new.is_multi_state and old.is_multi_state):
if not (new.is_multi_state and old.is_multi_state): # pragma: no cover
raise ApiUsageError('_update_multi_states only handles context states!')
if new.handle != old.handle:
if new.handle != old.handle: # pragma: no cover
raise ApiUsageError(f'_update_multi_states found different handles! new={new.handle}, old = {old.handle}')
if not modified_handles:
modified_handles = new.states.keys()
Expand Down Expand Up @@ -148,7 +148,7 @@ def get_state_transaction_item(self, handle: str) -> TransactionItem | None:
:param handle: the Handle of a context state or the DescriptorHandle in all other cases
"""
if not handle:
if not handle: # pragma: no cover
raise ValueError('No handle for state specified')
for lookup in (self.metric_state_updates,
self.alert_state_updates,
Expand Down Expand Up @@ -181,7 +181,7 @@ def transaction__entity(self, descriptor_handle: str) -> ProviderEntity | Provid
The descriptor can already be part of the transaction, and e.g. in pre_commit handlers of role providers
it can be necessary to have access to it.
"""
if not descriptor_handle:
if not descriptor_handle: # pragma: no cover
raise ValueError('No handle for descriptor specified')
tr_container = self.descriptor_updates.get(descriptor_handle)
if tr_container is not None:
Expand All @@ -195,7 +195,7 @@ def write_entity(self, # noqa: PLR0912, C901
adjust_version_counter: bool = True):
"""Insert or update an entity."""
descriptor_handle = entity.descriptor.Handle
if descriptor_handle in self.descriptor_updates:
if descriptor_handle in self.descriptor_updates: # pragma: no cover
raise ValueError(f'Entity {descriptor_handle} already in updated set!')
tmp = copy.copy(entity) # cannot deepcopy entity, that would deepcopy also whole mdib
tmp.descriptor = copy.deepcopy(entity.descriptor) # do not touch original entity of user
Expand Down Expand Up @@ -269,7 +269,7 @@ def write_entities(self,

def remove_entity(self, entity: ProviderEntity | ProviderMultiStateEntity):
"""Remove existing descriptor from mdib."""
if entity.handle in self.descriptor_updates:
if entity.handle in self.descriptor_updates: # pragma: no cover
raise ValueError(f'Descriptor {entity.handle} already in updated set!')

internal_entity = self._mdib.internal_entities.get(entity.handle)
Expand Down Expand Up @@ -313,7 +313,7 @@ def process_transaction(self, set_determination_time: bool) -> TransactionResult
if handle]
if not types:
return proc # nothing changed
if len(types) > 1:
if len(types) > 1: # pragma: no cover
raise ValueError('this transaction can only handle one of insert, update, delete!')

for tr_item in self.descriptor_updates.values():
Expand Down Expand Up @@ -433,22 +433,6 @@ def _increment_parent_descriptor_version(self, proc: TransactionResult,
proc.descr_updated.append(parent_entity.descriptor.mk_copy())
updates_list.append(parent_entity.state.mk_copy())

def _get_states_update(self, container: AbstractStateProtocol | AbstractDescriptorProtocol) -> dict:
if getattr(container, 'is_realtime_sample_array_metric_state', False) \
or getattr(container, 'is_realtime_sample_array_metric_descriptor', False):
return self.rt_sample_state_updates
if getattr(container, 'is_metric_state', False) or getattr(container, 'is_metric_descriptor', False):
return self.metric_state_updates
if getattr(container, 'is_alert_state', False) or getattr(container, 'is_alert_descriptor', False):
return self.alert_state_updates
if getattr(container, 'is_component_state', False) or getattr(container, 'is_component_descriptor', False):
return self.component_state_updates
if getattr(container, 'is_operational_state', False) or getattr(container, 'is_operational_descriptor', False):
return self.operational_state_updates
if getattr(container, 'is_context_state', False) or getattr(container, 'is_context_descriptor', False):
return self.context_state_updates
raise NotImplementedError(f'Unhandled case {container}')


class StateTransactionBase(_TransactionBase):
"""Base Class for all transactions that modify states."""
Expand Down

0 comments on commit ea66398

Please sign in to comment.