Skip to content
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/Action.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/Actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/Condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/Conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/Event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/ReadStateMachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@


def ReadStateMachineFile(xml_file: str):
"""Read the xml file and parse it"""
states = {}
initial_state = ""
tree = ET.parse(xml_file)
Expand Down
2 changes: 2 additions & 0 deletions src/State.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 7 additions & 7 deletions src/StateMachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
"""
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -115,7 +115,7 @@ def __RestoreState(self):
def __PrepareExpression(expression):
"""
This Function split expression in module and expression

Parameters:
expression (str): complete expression.
Returns:
Expand Down Expand Up @@ -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.
"""
Expand All @@ -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
"""
Expand Down
14 changes: 11 additions & 3 deletions tests/testBaseStateMachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,39 @@


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
print(test)


def printTest():
"""Print Test"""
print("Test: ", test)


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
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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")
Expand Down