Skip to content

Commit b55436d

Browse files
authored
Added Docstrings to Functions (#36)
* Added Docstrings to Functions Signed-off-by: afro-coder <[email protected]> * Added Docstring for functions Deleted new lines after functions Signed-off-by: afro-coder <[email protected]>
1 parent 979fa9a commit b55436d

File tree

9 files changed

+31
-10
lines changed

9 files changed

+31
-10
lines changed

src/Action.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ class Action:
22
"""Define Action Class"""
33

44
def __init__(self, expression: str):
5+
"""Initialize Action"""
56
self.expression = expression
67

78
@staticmethod
89
def to_string():
10+
"""To string"""
911
result_s = ""
1012
return result_s

src/Actions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ class Actions:
22
"""Define and check actions"""
33

44
def __init__(self, actions=None):
5+
"""Initialize Actions class"""
56
if actions is None:
67
actions = []
78
self.actions_list = actions
89

910
@staticmethod
1011
def to_string():
12+
"""To string"""
1113
result_s = ""
1214
return result_s

src/Condition.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ class Condition:
22
"""Define a Condition Class"""
33

44
def __init__(self, expression: str, result: str):
5+
"""Initialize Condition class"""
56
self.expression = expression
67
self.result = result
78

89
@staticmethod
910
def to_string():
11+
"""To string"""
1012
result_s = ""
1113
return result_s

src/Conditions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ class Conditions:
22
"""Define Conditions"""
33

44
def __init__(self, conditions=None):
5+
"""Initialize Conditions"""
56
if conditions is None:
67
conditions = []
78
self.conditions_list = conditions
89

910
@staticmethod
1011
def to_string():
12+
"""To string"""
1113
result_s = ""
1214
return result_s

src/Event.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class Event:
66
"""Construct an Event class"""
77

88
def __init__(self, name: str, to_state: str, pre_conditions: Conditions, post_conditions: Conditions, pre_actions: Actions, post_actions: Actions):
9+
"""Initialize Event Class"""
910
self.name = name
1011
self.to_state = to_state
1112
self.pre_conditions = pre_conditions
@@ -14,6 +15,7 @@ def __init__(self, name: str, to_state: str, pre_conditions: Conditions, post_co
1415
self.post_actions = post_actions
1516

1617
def to_string(self):
18+
"""To string"""
1719
result_s = "Event: \n"
1820
result_s += "\tName: " + self.name + "\n"
1921
result_s += "\tToState: " + self.to_state + "\n"

src/ReadStateMachine.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99

1010
def ReadStateMachineFile(xml_file: str):
11+
"""Read the xml file and parse it"""
1112
states = {}
1213
initial_state = ""
1314
tree = ET.parse(xml_file)

src/State.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ class State:
22
"""Define the state class"""
33

44
def __init__(self, name: str, events=None):
5+
"""Initialize State"""
56
if events is None:
67
events = {}
78
self.name = name
89
self.events = events
910

1011
def to_string(self):
12+
"""To string"""
1113
result_s = "State:\n"
1214
result_s += " Name: " + self.name + "\n"
1315
result_s += " Events: \n"

src/StateMachine.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class StateMachine:
66
"""
77
This is a class defines state machine operations.
8-
8+
99
Attributes:
1010
xml_file (str): The name of the xml that defines the state machine.
1111
states (list): list of possible states of the machine.
@@ -16,7 +16,7 @@ class StateMachine:
1616
def __init__(self, xml_file: str):
1717
"""
1818
The constructor for StateMachine class.
19-
19+
2020
Parameters:
2121
xml_file (str): The name of the xml that defines the state machine.
2222
"""
@@ -31,7 +31,7 @@ def __init__(self, xml_file: str):
3131
def __CheckConditions(self, conditions):
3232
"""
3333
This Function checks the conditions passed as argument
34-
34+
3535
Parameters:
3636
conditions (list): List of condition to check.
3737
Returns:
@@ -69,7 +69,7 @@ def __CheckConditions(self, conditions):
6969
def __ExecActions(self, actions):
7070
"""
7171
This Function executes the actions passed as argument
72-
72+
7373
Parameters:
7474
actions (list): List of actions to execute.
7575
Returns:
@@ -115,7 +115,7 @@ def __RestoreState(self):
115115
def __PrepareExpression(expression):
116116
"""
117117
This Function split expression in module and expression
118-
118+
119119
Parameters:
120120
expression (str): complete expression.
121121
Returns:
@@ -148,7 +148,7 @@ def LoadStateMachine(self):
148148
def addModuleToContext(self, module: str):
149149
"""
150150
This Function adds a module to the context of state machine
151-
151+
152152
Parameters:
153153
module (str): The module to add.
154154
"""
@@ -158,7 +158,7 @@ def addModuleToContext(self, module: str):
158158
def InjectEvent(self, event: str):
159159
"""
160160
This Function execute the event injected
161-
161+
162162
Parameters:
163163
event (str): Event injected
164164
"""

tests/testBaseStateMachine.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,39 @@
77

88

99
def everFalse():
10+
"""Return false"""
1011
return False
1112

1213

1314
def everTrue():
15+
"""Return false"""
1416
return True
1517

1618

1719
def testPrint():
20+
"""Return Test"""
1821
print("Test")
1922

2023

2124
def setTestTo3():
25+
"""Sets Test to 3"""
2226
global test # Needed to modify global copy of globvar
2327
print(test)
2428
test = 3
2529
print(test)
2630

2731

2832
def printTest():
33+
"""Print Test"""
2934
print("Test: ", test)
3035

3136

3237
class TestBaseStateMachine(unittest.TestCase):
3338
"""Test state machine using various samples"""
3439

3540
def test1(self):
36-
41+
"""Test Statemachine"""
3742
sm = StateMachine("../sample/sample1.xml")
38-
3943
sm.LoadStateMachine()
4044
self.assertEqual(sm.get_current_state(), "Enter", "Should be Enter")
4145
# OK Event
@@ -55,7 +59,7 @@ def test1(self):
5559
self.assertEqual(sm.get_current_state(), "Null", "Should be Null")
5660

5761
def test2(self):
58-
62+
"""Second Test for Statemachine"""
5963
sm = StateMachine("../sample/sample2.xml")
6064

6165
sm.LoadStateMachine()
@@ -81,6 +85,7 @@ def test2(self):
8185
self.assertEqual(sm.get_current_state(), "Exit", "Should be Exit")
8286

8387
def test3(self):
88+
"""Test 3 for State Machine"""
8489
sm = StateMachine("../sample/sample3.xml")
8590

8691
sm.LoadStateMachine()
@@ -106,6 +111,7 @@ def test3(self):
106111
self.assertEqual(sm.get_current_state(), "Exit", "Should be Exit")
107112

108113
def test4(self):
114+
"""Test 4 for state machine"""
109115
sm = StateMachine("../sample/sample4.xml")
110116

111117
sm.LoadStateMachine()
@@ -131,6 +137,7 @@ def test4(self):
131137
self.assertEqual(sm.get_current_state(), "Null", "Should be Null")
132138

133139
def test5(self):
140+
"""Test 5 for state machine"""
134141
sm = StateMachine("../sample/sample5.xml")
135142

136143
sm.LoadStateMachine()
@@ -156,6 +163,7 @@ def test5(self):
156163
self.assertEqual(sm.get_current_state(), "Null", "Should be Null")
157164

158165
def test6(self):
166+
"""Test 6 for state machine"""
159167
global test
160168
test = 2
161169
sm = StateMachine("../sample/sample6.xml")

0 commit comments

Comments
 (0)