From ea66398f6da0c811a93a96254766b5073dde190b Mon Sep 17 00:00:00 2001 From: Deichmann Date: Thu, 21 Nov 2024 18:19:15 +0100 Subject: [PATCH] removed some obsolete code --- src/sdc11073/entity_mdib/entities.py | 8 ++--- .../entity_mdib/entity_consumermdib.py | 2 +- .../entity_mdib/entity_providermdibxtra.py | 2 +- .../entity_mdib/entity_transactions.py | 30 +++++-------------- 4 files changed, 13 insertions(+), 29 deletions(-) diff --git a/src/sdc11073/entity_mdib/entities.py b/src/sdc11073/entity_mdib/entities.py index d7ee5cf3..dea3cb87 100644 --- a/src/sdc11073/entity_mdib/entities.py +++ b/src/sdc11073/entity_mdib/entities.py @@ -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 @@ -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) @@ -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) @@ -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(): diff --git a/src/sdc11073/entity_mdib/entity_consumermdib.py b/src/sdc11073/entity_mdib/entity_consumermdib.py index b0f5d3aa..179ee854 100644 --- a/src/sdc11073/entity_mdib/entity_consumermdib.py +++ b/src/sdc11073/entity_mdib/entity_consumermdib.py @@ -38,7 +38,7 @@ @dataclass class _BufferedData: received_message_data: ReceivedMessage - handler: callable + handler: Callable multi_state_q_names = (pm_qnames.PatientContextDescriptor, diff --git a/src/sdc11073/entity_mdib/entity_providermdibxtra.py b/src/sdc11073/entity_mdib/entity_providermdibxtra.py index e7cfc478..9ccccc93 100644 --- a/src/sdc11073/entity_mdib/entity_providermdibxtra.py +++ b/src/sdc11073/entity_mdib/entity_providermdibxtra.py @@ -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] diff --git a/src/sdc11073/entity_mdib/entity_transactions.py b/src/sdc11073/entity_mdib/entity_transactions.py index 4a28c844..bc930ce5 100644 --- a/src/sdc11073/entity_mdib/entity_transactions.py +++ b/src/sdc11073/entity_mdib/entity_transactions.py @@ -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() @@ -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, @@ -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: @@ -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 @@ -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) @@ -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(): @@ -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."""