Skip to content

Commit

Permalink
refactor: add standard exception handling to Options data manager (#431)
Browse files Browse the repository at this point in the history
  • Loading branch information
weibullguy authored Jan 12, 2021
1 parent c645ebf commit 254d4b2
Show file tree
Hide file tree
Showing 106 changed files with 423 additions and 151 deletions.
103 changes: 84 additions & 19 deletions src/ramstk/controllers/options/datamanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
"""Options Package Data Model."""

# Standard Library Imports
from typing import Any, Dict
import inspect
from typing import Any, Dict, List

# Third Party Imports
from pubsub import pub

# RAMSTK Package Imports
from ramstk.controllers import RAMSTKDataManager
from ramstk.exceptions import DataAccessError
from ramstk.models.commondb import RAMSTKSiteInfo
from ramstk.models.programdb import RAMSTKProgramInfo

Expand All @@ -25,20 +27,34 @@ class DataManager(RAMSTKDataManager):
data from the Site and Program databases.
"""

# Define private dict class attributes.

# Define private list class attributes.

# Define private scalar class attributes.
_tag = 'options'
_root = 0

# Define public dict class attributes.

# Define public list class attributes.

# Define public scalar class attributes.

def __init__(self, **kwargs) -> None:
"""Initialize a Options data manager instance."""
RAMSTKDataManager.__init__(self, **kwargs)

# Initialize private dictionary attributes.
self._pkey = {'siteinfo': ['site_id'], 'programinfo': ['revision_id']}
self._pkey: Dict[str, List[str]] = {
'siteinfo': ['site_id'],
'programinfo': ['revision_id']
}

# Initialize private list attributes.

# Initialize private scalar attributes.
self._parent_id = 0
self._parent_id: int = 0

# Initialize public dictionary attributes.

Expand Down Expand Up @@ -97,7 +113,10 @@ def do_select_all(self, attributes: Dict[str, Any]) -> None:
parent=self._root,
data={'programinfo': _option})

pub.sendMessage('succeed_retrieve_options', tree=self.tree)
pub.sendMessage(
'succeed_retrieve_options',
tree=self.tree,
)

def do_update(self, node_id: str) -> None:
"""Update the record associated with node ID in RAMSTK databases.
Expand All @@ -106,18 +125,64 @@ def do_update(self, node_id: str) -> None:
:return: None
:rtype: None
"""
if node_id == 'siteinfo':
# noinspection PyUnresolvedReferences
self.common_dao.session.add(
self.tree.get_node(node_id).data[node_id])
self.dao.do_update()
pub.sendMessage('succeed_update_options', node_id=node_id)
elif node_id == 'programinfo':
# noinspection PyUnresolvedReferences
self.dao.session.add(self.tree.get_node(node_id).data[node_id])
self.dao.do_update()
pub.sendMessage('succeed_update_options', node_id=node_id)
else:
pub.sendMessage('fail_update_options',
error_message=('Error saving {0:s} Options to the '
'database.').format(node_id))
try:
if node_id == 'siteinfo':
# noinspection PyUnresolvedReferences
self.common_dao.session.add(
self.tree.get_node(node_id).data[node_id])
self.common_dao.do_update()
pub.sendMessage(
'succeed_update_options',
node_id=node_id,
)
elif node_id == 'programinfo':
# noinspection PyUnresolvedReferences
self.dao.session.add(self.tree.get_node(node_id).data[node_id])
self.dao.do_update()
pub.sendMessage(
'succeed_update_options',
node_id=node_id,
)
else:
_method_name: str = inspect.currentframe( # type: ignore
).f_code.co_name
_error_msg = ('{1}: Attempted to save non-existent Option '
'type {0}.').format(str(node_id), _method_name)
pub.sendMessage(
'do_log_debug',
logger_name='DEBUG',
message=_error_msg,
)
pub.sendMessage(
'fail_update_options',
error_message=_error_msg,
)
except KeyError:
_method_name: str = inspect.currentframe( # type: ignore
).f_code.co_name
_error_msg = ('{1}: No data package found for Option {0}.').format(
str(node_id), _method_name)
pub.sendMessage(
'do_log_debug',
logger_name='DEBUG',
message=_error_msg,
)
pub.sendMessage(
'fail_update_options',
error_message=_error_msg,
)
except (TypeError, DataAccessError):
_method_name: str = inspect.currentframe( # type: ignore
).f_code.co_name
_error_msg = ('{1}: The value for one or more attributes for '
'Options {0} was the wrong type.').format(
str(node_id), _method_name)
pub.sendMessage(
'do_log_debug',
logger_name='DEBUG',
message=_error_msg,
)
pub.sendMessage(
'fail_update_options',
error_message=_error_msg,
)
1 change: 1 addition & 0 deletions src/ramstk/controllers/options/datamanager.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ from typing import Any, Dict

# RAMSTK Package Imports
from ramstk.controllers import RAMSTKDataManager as RAMSTKDataManager
from ramstk.exceptions import DataAccessError as DataAccessError
from ramstk.models.commondb import RAMSTKSiteInfo as RAMSTKSiteInfo
from ramstk.models.programdb import RAMSTKProgramInfo as RAMSTKProgramInfo

Expand Down
3 changes: 2 additions & 1 deletion tests/analyses/milhdbk217f/models/test_capacitor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=invalid-name, protected-access
# pylint: skip-file
# type: ignore
# -*- coding: utf-8 -*-
#
# tests.analyses.milhdbk217f.models.test_capacitor.py is part of The
Expand Down
3 changes: 2 additions & 1 deletion tests/analyses/milhdbk217f/models/test_connection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=invalid-name, protected-access
# pylint: skip-file
# type: ignore
# -*- coding: utf-8 -*-
#
# tests.analyses.milhdbk217f.models.test_connection.py is part of The
Expand Down
3 changes: 2 additions & 1 deletion tests/analyses/milhdbk217f/models/test_crystal.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=invalid-name, protected-access
# pylint: skip-file
# type: ignore
# -*- coding: utf-8 -*-
#
# tests.analyses.milhdbk217f.models.test_crystal.py is part of The RAMSTK
Expand Down
3 changes: 2 additions & 1 deletion tests/analyses/milhdbk217f/models/test_filter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=invalid-name, protected-access
# pylint: skip-file
# type: ignore
# -*- coding: utf-8 -*-
#
# tests.analyses.milhdbk217f.models.test_filter.py is part of The RAMSTK
Expand Down
3 changes: 2 additions & 1 deletion tests/analyses/milhdbk217f/models/test_fuse.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=invalid-name, protected-access
# pylint: skip-file
# type: ignore
# -*- coding: utf-8 -*-
#
# tests.analyses.milhdbk217f.models.test_fuse.py is part of The RAMSTK
Expand Down
3 changes: 2 additions & 1 deletion tests/analyses/milhdbk217f/models/test_inductor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=invalid-name, protected-access
# pylint: skip-file
# type: ignore
# -*- coding: utf-8 -*-
#
# tests.analyses.milhdbk217f.models.test_inductor.py is part of The
Expand Down
3 changes: 2 additions & 1 deletion tests/analyses/milhdbk217f/models/test_integrated_circuit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=invalid-name, protected-access
# pylint: skip-file
# type: ignore
# -*- coding: utf-8 -*-
#
# tests.analyses.milhdbk217f.models.test_integrated_circuit.py is part of
Expand Down
3 changes: 2 additions & 1 deletion tests/analyses/milhdbk217f/models/test_lamp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=invalid-name, protected-access
# pylint: skip-file
# type: ignore
# -*- coding: utf-8 -*-
#
# tests.analyses.milhdbk217f.models.test_lamp.py is part of The RAMSTK
Expand Down
3 changes: 2 additions & 1 deletion tests/analyses/milhdbk217f/models/test_meter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=invalid-name, protected-access
# pylint: skip-file
# type: ignore
# -*- coding: utf-8 -*-
#
# tests.analyses.milhdbk217f.models.test_meter.py is part of The RAMSTK
Expand Down
3 changes: 2 additions & 1 deletion tests/analyses/milhdbk217f/models/test_relay.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=invalid-name, protected-access
# pylint: skip-file
# type: ignore
# -*- coding: utf-8 -*-
#
# tests.analyses.milhdbk217f.models.test_relay.py is part of The RAMSTK
Expand Down
3 changes: 2 additions & 1 deletion tests/analyses/milhdbk217f/models/test_resistor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=invalid-name, protected-access
# pylint: skip-file
# type: ignore
# -*- coding: utf-8 -*-
#
# tests.analyses.milhdbk271f.models.test_resistor.py is part of The
Expand Down
3 changes: 2 additions & 1 deletion tests/analyses/milhdbk217f/models/test_semiconductor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=invalid-name, protected-access
# pylint: skip-file
# type: ignore
# -*- coding: utf-8 -*-
#
# tests.analyses.milhdbk217f.models.test_semiconductor.py is part of The
Expand Down
3 changes: 2 additions & 1 deletion tests/analyses/milhdbk217f/models/test_switch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=invalid-name, protected-access
# pylint: skip-file
# type: ignore
# -*- coding: utf-8 -*-
#
# tests.analyses.milhdbk217f.models.test_switch.py is part of The RAMSTK
Expand Down
3 changes: 2 additions & 1 deletion tests/analyses/milhdbk217f/test_milhdbk217f.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=invalid-name, protected-access
# pylint: skip-file
# type: ignore
# -*- coding: utf-8 -*-
#
# tests.analyses.milhdbk217f.test_milhdbk217f.py is part of The RAMSTK Project
Expand Down
3 changes: 2 additions & 1 deletion tests/analyses/statistics/test_bounds.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=protected-access, no-self-use, missing-docstring
# pylint: skip-file
# type: ignore
# -*- coding: utf-8 -*-
#
# tests.analyses.statistics.test_bounds.py is part of The RAMSTK Project
Expand Down
3 changes: 2 additions & 1 deletion tests/analyses/test_allocation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=invalid-name, protected-access
# pylint: skip-file
# type: ignore
# -*- coding: utf-8 -*-
#
# tests.analyses.test_allocation.py is part of The RAMSTK Project
Expand Down
3 changes: 2 additions & 1 deletion tests/analyses/test_criticality.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=invalid-name, protected-access
# pylint: skip-file
# type: ignore
# -*- coding: utf-8 -*-
#
# tests.analyses.test_criticality.py is part of The RAMSTK Project
Expand Down
3 changes: 2 additions & 1 deletion tests/analyses/test_derating.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=invalid-name, protected-access
# pylint: skip-file
# type: ignore
# -*- coding: utf-8 -*-
#
# tests.analyses.test_derating.py is part of The RAMSTK Project
Expand Down
3 changes: 2 additions & 1 deletion tests/analyses/test_dormancy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=invalid-name, protected-access
# pylint: skip-file
# type: ignore
# -*- coding: utf-8 -*-
#
# tests.analyses.test_dormancy.py is part of The RAMSTK Project
Expand Down
3 changes: 2 additions & 1 deletion tests/analyses/test_fha.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=invalid-name, protected-access
# pylint: skip-file
# type: ignore
# -*- coding: utf-8 -*-
#
# tests.analyses.test_fha.py is part of The RAMSTK Project
Expand Down
3 changes: 2 additions & 1 deletion tests/analyses/test_improvementfactor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=invalid-name, protected-access
# pylint: skip-file
# type: ignore
# -*- coding: utf-8 -*-
#
# tests.analyses.test_improvementfactor.py is part of The RAMSTK Project
Expand Down
3 changes: 2 additions & 1 deletion tests/analyses/test_similaritem.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=invalid-name, protected-access
# pylint: skip-file
# type: ignore
# -*- coding: utf-8 -*-
#
# tests.analyses.test_similaritem.py is part of The RAMSTK Project
Expand Down
3 changes: 2 additions & 1 deletion tests/analyses/test_stress.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=invalid-name, protected-access
# pylint: skip-file
# type: ignore
# -*- coding: utf-8 -*-
#
# tests.analyses.test_stress.py is part of The RAMSTK Project
Expand Down
3 changes: 2 additions & 1 deletion tests/controllers/test_allocations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=protected-access, no-self-use, missing-docstring, invalid-name
# pylint: skip-file
# type: ignore
# -*- coding: utf-8 -*-
#
# tests.controllers.test_allocations.py is part of The RAMSTK
Expand Down
3 changes: 2 additions & 1 deletion tests/controllers/test_failure_definition.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=protected-access, no-self-use, missing-docstring
# pylint: skip-file
# type: ignore
# -*- coding: utf-8 -*-
#
# tests.controllers.test_revision.py is part of The RAMSTK Project
Expand Down
2 changes: 1 addition & 1 deletion tests/controllers/test_function.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# pylint: skip-file
# type: ignore
# pylint: disable=protected-access, no-self-use, missing-docstring
# -*- coding: utf-8 -*-
#
# tests.controllers.test_function.py is part of The RAMSTK Project
Expand Down
3 changes: 2 additions & 1 deletion tests/controllers/test_hardware.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=protected-access, no-self-use, missing-docstring, invalid-name
# pylint: skip-file
# type: ignore
# -*- coding: utf-8 -*-
#
# tests.controllers.hardware.test_hardware.py is part of The RAMSTK
Expand Down
3 changes: 2 additions & 1 deletion tests/controllers/test_hazards.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=protected-access, no-self-use, missing-docstring
# pylint: skip-file
# type: ignore
# -*- coding: utf-8 -*-
#
# tests.controllers.test_function.py is part of The RAMSTK Project
Expand Down
Loading

0 comments on commit 254d4b2

Please sign in to comment.