diff --git a/src/Action.py b/src/Action.py index e571da5..7ae2b7d 100644 --- a/src/Action.py +++ b/src/Action.py @@ -2,9 +2,11 @@ class Action: """Define Action Class""" def __init__(self, expression: str): + """Initialize Action""" self.expression = expression @staticmethod def to_string(): + """To string""" result_s = "" return result_s diff --git a/src/Actions.py b/src/Actions.py index 9664672..0f5e843 100644 --- a/src/Actions.py +++ b/src/Actions.py @@ -2,11 +2,13 @@ class Actions: """Define and check actions""" def __init__(self, actions=None): + """Initialize Actions class""" if actions is None: actions = [] self.actions_list = actions @staticmethod def to_string(): + """To string""" result_s = "" return result_s diff --git a/src/Condition.py b/src/Condition.py index 38283c3..786d19c 100644 --- a/src/Condition.py +++ b/src/Condition.py @@ -2,10 +2,12 @@ class Condition: """Define a Condition Class""" def __init__(self, expression: str, result: str): + """Initialize Condition class""" self.expression = expression self.result = result @staticmethod def to_string(): + """To string""" result_s = "" return result_s diff --git a/src/Conditions.py b/src/Conditions.py index bd7a5df..5aac4ca 100644 --- a/src/Conditions.py +++ b/src/Conditions.py @@ -2,11 +2,13 @@ class Conditions: """Define Conditions""" def __init__(self, conditions=None): + """Initialize Conditions""" if conditions is None: conditions = [] self.conditions_list = conditions @staticmethod def to_string(): + """To string""" result_s = "" return result_s diff --git a/src/Event.py b/src/Event.py index 5e42a50..d68e9b1 100644 --- a/src/Event.py +++ b/src/Event.py @@ -6,6 +6,7 @@ class Event: """Construct an Event class""" def __init__(self, name: str, to_state: str, pre_conditions: Conditions, post_conditions: Conditions, pre_actions: Actions, post_actions: Actions): + """Initialize Event Class""" self.name = name self.to_state = to_state self.pre_conditions = pre_conditions @@ -14,6 +15,7 @@ def __init__(self, name: str, to_state: str, pre_conditions: Conditions, post_co self.post_actions = post_actions def to_string(self): + """To string""" result_s = "Event: \n" result_s += "\tName: " + self.name + "\n" result_s += "\tToState: " + self.to_state + "\n" diff --git a/src/ReadStateMachine.py b/src/ReadStateMachine.py index bb75fba..bf51bf4 100644 --- a/src/ReadStateMachine.py +++ b/src/ReadStateMachine.py @@ -8,6 +8,7 @@ def ReadStateMachineFile(xml_file: str): + """Read the xml file and parse it""" states = {} initial_state = "" tree = ET.parse(xml_file) diff --git a/src/State.py b/src/State.py index e4325c8..92ac03a 100644 --- a/src/State.py +++ b/src/State.py @@ -2,12 +2,14 @@ class State: """Define the state class""" def __init__(self, name: str, events=None): + """Initialize State""" if events is None: events = {} self.name = name self.events = events def to_string(self): + """To string""" result_s = "State:\n" result_s += " Name: " + self.name + "\n" result_s += " Events: \n" diff --git a/src/StateMachine.py b/src/StateMachine.py index dd29742..37ed5a1 100644 --- a/src/StateMachine.py +++ b/src/StateMachine.py @@ -5,7 +5,7 @@ class StateMachine: """ This is a class defines state machine operations. - + Attributes: xml_file (str): The name of the xml that defines the state machine. states (list): list of possible states of the machine. @@ -16,7 +16,7 @@ class StateMachine: def __init__(self, xml_file: str): """ The constructor for StateMachine class. - + Parameters: xml_file (str): The name of the xml that defines the state machine. """ @@ -31,7 +31,7 @@ def __init__(self, xml_file: str): def __CheckConditions(self, conditions): """ This Function checks the conditions passed as argument - + Parameters: conditions (list): List of condition to check. Returns: @@ -69,7 +69,7 @@ def __CheckConditions(self, conditions): def __ExecActions(self, actions): """ This Function executes the actions passed as argument - + Parameters: actions (list): List of actions to execute. Returns: @@ -115,7 +115,7 @@ def __RestoreState(self): def __PrepareExpression(expression): """ This Function split expression in module and expression - + Parameters: expression (str): complete expression. Returns: @@ -148,7 +148,7 @@ def LoadStateMachine(self): def addModuleToContext(self, module: str): """ This Function adds a module to the context of state machine - + Parameters: module (str): The module to add. """ @@ -158,7 +158,7 @@ def addModuleToContext(self, module: str): def InjectEvent(self, event: str): """ This Function execute the event injected - + Parameters: event (str): Event injected """ diff --git a/tests/testBaseStateMachine.py b/tests/testBaseStateMachine.py index f84b4ce..ea67bac 100644 --- a/tests/testBaseStateMachine.py +++ b/tests/testBaseStateMachine.py @@ -7,18 +7,22 @@ def everFalse(): + """Return false""" return False def everTrue(): + """Return false""" return True def testPrint(): + """Return Test""" print("Test") def setTestTo3(): + """Sets Test to 3""" global test # Needed to modify global copy of globvar print(test) test = 3 @@ -26,6 +30,7 @@ def setTestTo3(): def printTest(): + """Print Test""" print("Test: ", test) @@ -33,9 +38,8 @@ class TestBaseStateMachine(unittest.TestCase): """Test state machine using various samples""" def test1(self): - + """Test Statemachine""" sm = StateMachine("../sample/sample1.xml") - sm.LoadStateMachine() self.assertEqual(sm.get_current_state(), "Enter", "Should be Enter") # OK Event @@ -55,7 +59,7 @@ def test1(self): self.assertEqual(sm.get_current_state(), "Null", "Should be Null") def test2(self): - + """Second Test for Statemachine""" sm = StateMachine("../sample/sample2.xml") sm.LoadStateMachine() @@ -81,6 +85,7 @@ def test2(self): self.assertEqual(sm.get_current_state(), "Exit", "Should be Exit") def test3(self): + """Test 3 for State Machine""" sm = StateMachine("../sample/sample3.xml") sm.LoadStateMachine() @@ -106,6 +111,7 @@ def test3(self): self.assertEqual(sm.get_current_state(), "Exit", "Should be Exit") def test4(self): + """Test 4 for state machine""" sm = StateMachine("../sample/sample4.xml") sm.LoadStateMachine() @@ -131,6 +137,7 @@ def test4(self): self.assertEqual(sm.get_current_state(), "Null", "Should be Null") def test5(self): + """Test 5 for state machine""" sm = StateMachine("../sample/sample5.xml") sm.LoadStateMachine() @@ -156,6 +163,7 @@ def test5(self): self.assertEqual(sm.get_current_state(), "Null", "Should be Null") def test6(self): + """Test 6 for state machine""" global test test = 2 sm = StateMachine("../sample/sample6.xml")