Core Models#
Data models for requirements items, test links, coverage, and the traceability graph.
Item#
- class jamb.core.models.Item[source]#
Represents a requirements item (requirement, info, heading, etc.).
- active#
Whether the item is active. Inactive items are ignored during validation and coverage checks.
- Type:
- type#
Item type.
- Type:
Literal[“requirement”, “info”, “heading”]
- level#
Heading depth for
type="heading"items. Controls the rendered heading level:<h1>–<h6>in HTML, heading level in DOCX, and#depth in markdown. Has no effect onrequirementorinfoitems (a validation warning is issued if set on those).Noneuses the default depth (equivalent to level 2).- Type:
int | None
- reviewed#
Content hash recorded when the item was last reviewed, or
Noneif never reviewed.- Type:
str | None
- testable#
Whether the item can be verified by testing. If False, the item shows “N/A” instead of “NOT COVERED” in the matrix.
- Type:
Construct an item and access its display text:: >>> item = Item( ... uid="SRS001", ... text="The system shall log in users.", ... document_prefix="SRS", ... ) >>> item.uid 'SRS001' >>> item.display_text 'The system shall log in users.' An item with a header uses the header as display text:: >>> item = Item( ... uid="SRS002", ... text="Details...", ... document_prefix="SRS", ... header="Login", ... ) >>> item.display_text 'Login'- property display_text: str#
Return header if present, otherwise truncated text.
Truncation is safe for multi-byte UTF-8 characters since Python strings are Unicode codepoint sequences, not byte sequences.
- property full_display_text: str#
Return ‘header - text’ if header present, otherwise just text.
Used for full chain matrices where both header and text are desired.
- __init__(uid, text, document_prefix, active=True, type='requirement', header=None, level=None, links=<factory>, reviewed=None, derived=False, testable=True, custom_attributes=<factory>)#
LinkedTest#
- class jamb.core.models.LinkedTest[source]#
Represents a link from a pytest test to a requirements item.
- test_outcome#
Result of the test —
"passed","failed","skipped", or"error".Nonebefore execution.- Type:
str | None
- __init__(test_nodeid, item_uid, test_outcome=None, notes=<factory>, test_actions=<factory>, expected_results=<factory>, actual_results=<factory>, execution_timestamp=None)#
ItemCoverage#
- class jamb.core.models.ItemCoverage[source]#
Coverage status for a single requirements item.
- linked_tests#
Tests linked to this item via requirement markers.
- Type:
- property all_tests_passed: bool#
Return True if all linked tests passed.
Returns False if there are no linked tests, since an item with no tests cannot be considered to have “all tests passing”. This is intentional - use
is_coveredto check if tests exist.
- __init__(item, linked_tests=<factory>)#
- Parameters:
item (Item)
linked_tests (list[LinkedTest])
- Return type:
None
TraceabilityGraph#
- class jamb.core.models.TraceabilityGraph[source]#
Graph representing the full traceability hierarchy.
Stores items by UID and tracks parent-child relationships based on document hierarchy and item links.
- item_parents#
Mapping of item UID to list of parent item UIDs (derived from each item’s
linksfield).
- item_children#
Reverse index mapping item UID to list of child item UIDs that link to it.
- document_parents#
Mapping of document prefix to list of parent document prefixes (the document-level DAG).
Build a graph and add linked items:: >>> graph = TraceabilityGraph() >>> graph.set_document_parents("SRS", ["SYS"]) >>> graph.set_document_parents("SYS", []) >>> sys_item = Item(uid="SYS001", text="System req", document_prefix="SYS") >>> srs_item = Item( ... uid="SRS001", ... text="Software req", ... document_prefix="SRS", ... links=["SYS001"], ... ) >>> graph.add_item(sys_item) >>> graph.add_item(srs_item) >>> graph.item_children["SYS001"] ['SRS001']- add_item(item)[source]#
Add an item to the graph.
- Parameters:
item (
Item) – The Item to add. Its links are used to populate the parent and child reverse-index maps.- Raises:
ValueError – If the item links to itself (self-loop).
- Return type:
- set_document_parent(prefix, parent_prefix)[source]#
Set a single parent document, replacing any existing parents.
Backward-compatible wrapper for single-parent hierarchies. For DAG support with multiple parents, use set_document_parents().
- set_document_parents(prefix, parents)[source]#
Replace all parent documents with the given list.
Use this when you need to set the complete list of parents at once. Existing parents are replaced, not merged.
- add_document_parent(prefix, parent)[source]#
Add a parent document without removing existing parents.
Use this when building the graph incrementally. No-op if the parent already exists for this prefix.
- get_ancestors(uid)[source]#
Get all ancestor items by following links upward.
Returns items in order from immediate parent to root.
- get_descendants(uid)[source]#
Get all descendant items by following children downward.
Returns items in BFS order from immediate children to leaves.
- get_neighbors(uid)[source]#
Get all neighbor items: ancestors + descendants + self.
Returns the item itself plus all items connected to it through the traceability hierarchy.
- get_children_from_document(uid, prefix)[source]#
Get children of uid that belong to the given document.
- get_parents_from_document(uid, prefix)[source]#
Get parents of uid that belong to the given document.