Skip to content

Commit

Permalink
add docstring to reqdiagram module
Browse files Browse the repository at this point in the history
  • Loading branch information
ouhammmourachid committed Nov 18, 2023
1 parent cb6d8bd commit 8f9a22d
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
29 changes: 29 additions & 0 deletions mermaid/reqdiagram/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
"""ReqDiagram module.
This module provides the ReqDiagram class for creating and manipulating requirement diagrams.
It also provides utility classes for representing elements, links, and requirements in a requirement diagram.
Classes:
ReqDiagram: Represents a requirement diagram.
Element: Represents an element in a requirement diagram.
Link: Represents a link between elements or requirements in a requirement diagram.
Requirement: Represents a requirement in a requirement diagram.
"""
from mermaid.graph import Graph

from .element import *
Expand All @@ -6,8 +17,26 @@


class RequirementDiagram(Graph):
"""RequirementDiagram class.
This class represents a requirement diagram, which is a type of graph.
It contains elements, requirements, and links between them.
Attributes:
elements (list[Element]): The elements in the diagram.
requirements (list[Requirement]): The requirements in the diagram.
links (list[Link]): The links between elements and requirements in the diagram.
"""
def __init__(self, title: str, elements: list[Element],
requirements: list[Requirement], links: list[Link]) -> None:
"""Initialize a new RequirementDiagram.
Args:
title (str): The title of the diagram.
elements (list[Element]): The elements in the diagram.
requirements (list[Requirement]): The requirements in the diagram.
links (list[Link]): The links between elements and requirements in the diagram.
"""
super().__init__(title, '')
self.elements: list[Element] = elements if elements is not None else []
self.requirements: list[
Expand Down
22 changes: 22 additions & 0 deletions mermaid/reqdiagram/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,37 @@


class Element:
"""UserJourney module.
This module provides the UserJourney class for creating and manipulating user journeys.
It also provides the Section and Task classes for representing sections and tasks in a user journey.
Classes:
UserJourney: Represents a user's journey through a website or application.
Section: Represents a section in a user's journey.
Task: Represents a task in a section of a user's journey.
"""
def __init__(self,
name: str,
type_: str,
docRef: Optional[str] = None) -> None:
"""Initialize a new Element.
Args:
name (str): The name of the element.
type_ (str): The type of the element.
docRef (Optional[str]): The documentation reference for the element.
"""
self.name: str = name
self.type_: str = type_
self.docRef: Optional[str] = docRef

def __str__(self) -> str:
"""Return a string representation of the element.
Returns:
str: A string representation of the element.
"""
string: str = f'element {self.name} {{\n'
string += f'\ttype: "{self.type_}"\n'
string += f'\tdocRef: {self.docRef}\n' if self.docRef else ''
Expand Down
21 changes: 21 additions & 0 deletions mermaid/reqdiagram/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,32 @@


class Link:
"""Link class.
This class represents a link between elements or requirements in a requirement diagram.
Attributes:
source (Union[Element, Requirement]): The source of the link.
destination (Union[Element, Requirement]): The destination of the link.
type_ (str): The type of the link.
"""
def __init__(self, source: Union[Element, Requirement],
destination: Union[Element, Requirement], type_: str) -> None:
"""Initialize a new Link.
Args:
source (Union[Element, Requirement]): The source of the link.
destination (Union[Element, Requirement]): The destination of the link.
type_ (str): The type of the link.
"""
self.source: Union[Element, Requirement] = source
self.destination: Union[Element, Requirement] = destination
self.type_: str = type_

def __str__(self) -> str:
"""Return a string representation of the link.
Returns:
str: A string representation of the link.
"""
return f'{self.source.name} - {self.type_} -> {self.destination.name}'
35 changes: 35 additions & 0 deletions mermaid/reqdiagram/requirement.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,32 @@


class Risk(Enum):
"""Risk Enum.
This enum represents the different levels of risk associated with a requirement in a requirement diagram.
"""
LOW = 'Low'
MEDIUM = 'Medium'
HIGH = 'High'


class VerifyMethod(Enum):
"""VerifyMethod Enum.
This enum represents the different methods of verifying a requirement in a requirement diagram.
"""
ANALYSIS = 'Analysis'
INSPECTION = 'Inspection'
TEST = 'Test'
DEMONSTRATION = 'Demonstration'


class Type(Enum):
"""Return a string representation of the link.
Returns:
str: A string representation of the link.
"""
REQUIREMENT = 'requirement'
FUNCTIONAL = 'functionalRequirement'
INTERFACE = 'interfaceRequirement'
Expand All @@ -25,9 +38,31 @@ class Type(Enum):


class Requirement:
"""Requirement class.
This class represents a requirement in a requirement diagram.
Attributes:
id_ (str): The ID of the requirement.
name (str): The name of the requirement.
text (str): The text of the requirement.
type_ (Union[str, Type]): The type of the requirement.
risk (Union[str, Risk]): The risk of the requirement.
verifymethod (Union[str, VerifyMethod]): The verification method of the requirement.
"""
def __init__(self, id_: str, name: str, text: str, type_: Union[str, Type],
risk: Union[str, Risk],
verifymethod: Union[str, VerifyMethod]) -> None:
"""Initialize a new Requirement.
Args:
id_ (str): The ID of the requirement.
name (str): The name of the requirement.
text (str): The text of the requirement.
type_ (Union[str, Type]): The type of the requirement.
risk (Union[str, Risk]): The risk of the requirement.
verifymethod (Union[str, VerifyMethod]): The verification method of the requirement.
"""
self.id_: str = id_
self.name: str = name
self.text: str = text
Expand Down

0 comments on commit 8f9a22d

Please sign in to comment.