Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move ramstk_hazards to subpackage #992

Merged
merged 3 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/ramstk/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from .commondb.condition.record import RAMSTKConditionRecord # isort:skip
from .commondb.failure_mode.record import RAMSTKFailureModeRecord # isort:skip
from .commondb.group.record import RAMSTKGroupRecord # isort:skip
from .commondb.hazards.record import RAMSTKHazardsRecord # isort:skip
from .commondb.site_info.record import RAMSTKSiteInfoRecord # isort:skip
from .commondb.subcategory.record import RAMSTKSubCategoryRecord # isort:skip
from .commondb.category.table import RAMSTKCategoryTable # isort:skip
Expand All @@ -30,6 +31,7 @@
from .commondb.database import RAMSTKCommonDB
from .commondb.failure_mode.table import RAMSTKFailureModeTable
from .commondb.group.table import RAMSTKGroupTable
from .commondb.hazards.table import RAMSTKHazardsTable
from .commondb.site_info.table import RAMSTKSiteInfoTable
from .commondb.subcategory.table import RAMSTKSubCategoryTable
from .programdb.action.record import RAMSTKActionRecord
Expand Down
1 change: 0 additions & 1 deletion src/ramstk/models/commondb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"""The RAMSTK common database models package."""

# RAMSTK Local Imports
from .ramstkhazards import RAMSTKHazards
from .ramstkloadhistory import RAMSTKLoadHistory
from .ramstkmanufacturer import RAMSTKManufacturer
from .ramstkmeasurement import RAMSTKMeasurement
Expand Down
4 changes: 2 additions & 2 deletions src/ramstk/models/commondb/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
RAMSTKCategoryRecord,
RAMSTKFailureModeRecord,
RAMSTKGroupRecord,
RAMSTKHazardsRecord,
RAMSTKSiteInfoRecord,
RAMSTKSubCategoryRecord,
)
from ramstk.models.commondb import (
RAMSTKRPN,
RAMSTKHazards,
RAMSTKLoadHistory,
RAMSTKManufacturer,
RAMSTKMeasurement,
Expand Down Expand Up @@ -465,7 +465,7 @@ def _do_load_hazards(
:return: user_configuration
:rtype: RAMSTKUserConfiguration
"""
for _record in self.common_dao.session.query(RAMSTKHazards).all():
for _record in self.common_dao.session.query(RAMSTKHazardsRecord).all():
_attributes = _record.get_attributes()
user_configuration.RAMSTK_HAZARDS[_record.hazard_id] = (
_attributes["hazard_category"],
Expand Down
2 changes: 1 addition & 1 deletion src/ramstk/models/commondb/database.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ from ramstk.db import do_create_program_db as do_create_program_db
from ramstk.models import RAMSTKCategoryRecord as RAMSTKCategoryRecord
from ramstk.models import RAMSTKFailureModeRecord as RAMSTKFailureModeRecord
from ramstk.models import RAMSTKGroupRecord as RAMSTKGroupRecord
from ramstk.models import RAMSTKHazardsRecord as RAMSTKHazardsRecord
from ramstk.models import RAMSTKSiteInfoRecord as RAMSTKSiteInfoRecord
from ramstk.models import RAMSTKSubCategoryRecord as RAMSTKSubCategoryRecord
from ramstk.models.commondb import RAMSTKRPN as RAMSTKRPN
from ramstk.models.commondb import RAMSTKHazards as RAMSTKHazards
from ramstk.models.commondb import RAMSTKLoadHistory as RAMSTKLoadHistory
from ramstk.models.commondb import RAMSTKManufacturer as RAMSTKManufacturer
from ramstk.models.commondb import RAMSTKMeasurement as RAMSTKMeasurement
Expand Down
8 changes: 8 additions & 0 deletions src/ramstk/models/commondb/hazards/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# pylint: disable=unused-import
# -*- coding: utf-8 -*-
#
# ramstk.models.commondb.hazards.__init__.py is part of The RAMSTK Project
#
# All rights reserved.
# Copyright since 2007 Doyle "weibullguy" Rowland doyle.rowland <AT> reliaqual <DOT> com
"""The RAMSTK Hazards model package."""
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
#
# ramstk.models.commondb.RAMSTKHazards.py is part of The RAMSTK Project
# ramstk.models.commondb.hazards.record.py is part of The RAMSTK Project
#
# All rights reserved.
# Copyright 2007 - 2017 Doyle Rowland doyle.rowland <AT> reliaqual <DOT> com
# Copyright since 2007 Doyle "weibullguy" Rowland doyle.rowland <AT> reliaqual <DOT> com
"""RAMSTKHazard Table Module."""

# Third Party Imports
Expand All @@ -14,7 +14,7 @@
from ramstk.models import RAMSTKBaseRecord


class RAMSTKHazards(RAMSTK_BASE, RAMSTKBaseRecord):
class RAMSTKHazardsRecord(RAMSTK_BASE, RAMSTKBaseRecord):
"""Class to represent ramstk_hazard in the RAMSTK Common database."""

__defaults__ = {
Expand Down Expand Up @@ -44,10 +44,8 @@ def get_attributes(self):
:return: {hazard_id, category, subcategory} pairs
:rtype: tuple
"""
_attributes = {
return {
"hazard_id": self.hazard_id,
"hazard_category": self.hazard_category,
"hazard_subcategory": self.hazard_subcategory,
}

return _attributes
57 changes: 57 additions & 0 deletions src/ramstk/models/commondb/hazards/table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
#
# ramstk.models.commondb.hazards.table.py is part of The RAMSTK Project
#
# All rights reserved.
# Copyright since 2007 Doyle "weibullguy" Rowland doyle.rowland <AT> reliaqual <DOT> com
"""Hazards Table Model."""

# Standard Library Imports
from typing import Type

# RAMSTK Package Imports
from ramstk.models import RAMSTKBaseTable, RAMSTKHazardsRecord


class RAMSTKHazardsTable(RAMSTKBaseTable):
"""Contain the attributes and methods of the Option data manager."""

# Define private dict class attributes.

# Define private list class attributes.

# Define private scalar class attributes.
_db_id_colname = "fld_hazard_id"
_db_tablename = "ramstk_hazards"
_deprecated = False
_select_msg = "request_get_hazards"
_tag = "hazards"

# 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."""
RAMSTKBaseTable.__init__(self, **kwargs)

# Initialize private dictionary attributes.

# Initialize private list attributes.
self._lst_id_columns = [
"hazard_id",
]

# Initialize private scalar attributes.
self._record: Type[RAMSTKHazardsRecord] = RAMSTKHazardsRecord

# Initialize public dictionary attributes.

# Initialize public list attributes.

# Initialize public scalar attributes.
self.pkey = "hazard_id"

# Subscribe to PyPubSub messages.
2 changes: 1 addition & 1 deletion src/ramstk/models/programdb/action/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# pylint: disable=unused-import
# -*- coding: utf-8 -*-
#
# ramstk.models.action.__init__.py is part of The RAMSTK Project
# ramstk.models.programdb.action.__init__.py is part of The RAMSTK Project
#
# All rights reserved.
# Copyright since 2007 Doyle "weibullguy" Rowland doyle.rowland <AT> reliaqual <DOT> com
Expand Down
44 changes: 44 additions & 0 deletions tests/models/commondb/hazards/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Standard Library Imports
from datetime import date, timedelta

# Third Party Imports
import pytest
from mocks import MockDAO

# RAMSTK Package Imports
from ramstk.models import RAMSTKHazardsRecord


@pytest.fixture
def mock_common_dao(monkeypatch):
_hazards_1 = RAMSTKHazardsRecord()
_hazards_1.hazard_id = 1
_hazards_1.hazard_category = "Common Causes"
_hazards_1.hazard_subcategory = "Fire"

DAO = MockDAO()
DAO.table = [
_hazards_1,
]

yield DAO


@pytest.fixture(scope="function")
def test_attributes():
yield {
"hazard_id": 1,
"hazard_category": "Common Causes",
"hazard_subcategory": "Fire",
}


@pytest.fixture(scope="function")
def test_recordmodel(mock_common_dao):
"""Get a record model instance for each test function."""
dut = mock_common_dao.do_select_all(RAMSTKHazardsRecord, _all=False)

yield dut

# Delete the device under test.
del dut
Loading