Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests/coretests.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/coretests.py')
-rw-r--r--tests/coretests.py85
1 files changed, 28 insertions, 57 deletions
diff --git a/tests/coretests.py b/tests/coretests.py
index 10cc716..4f564c8 100644
--- a/tests/coretests.py
+++ b/tests/coretests.py
@@ -182,14 +182,11 @@ class StateTest(unittest.TestCase):
assert state.add_action(act2), "Could not add the second action"
assert state.add_action(act3), "Could not add the third action"
- # Try to add a second time an action that was already inserted
- assert state.add_action(act1) == False, "Not supposed to insert an action twice"
-
# Fetch the associated actions
actions = state.get_action_list()
# Make sure all the actions are present in the state
- assert act1 in actions and act2 in actions and act3 in actions,\
+ assert act1 in actions and act2 in actions and act3 in actions, \
"The actions were not properly inserted in the state"
# Clear the list
@@ -225,16 +222,16 @@ class StateTest(unittest.TestCase):
assert len(state.get_event_filter_list()) == 0, \
"Could not clear the event filter list properly"
- def test_is_identical_simple(self):
+ def test_eq_simple(self):
"""
Two empty states with the same name must be identical
"""
st1 = State("Identical")
st2 = State("Identical")
- assert st1.is_identical(st2), "Empty states with the same name should be identical"
+ assert st1 == st2, "Empty states with the same name should be identical"
- def test_is_identical(self):
+ def test_eq(self):
"""
Test whether two states share the same set of actions and event filters.
"""
@@ -261,33 +258,33 @@ class StateTest(unittest.TestCase):
st2.add_event_filter(event1)
# Make sure that they are identical for now
- assert st1.is_identical(st2), "States should be considered as identical"
- assert st2.is_identical(st1), "States should be considered as identical"
+ assert st1 == st2, "States should be considered as identical"
+ assert st2 == st1, "States should be considered as identical"
# Modify the second bubble message action
act2.message = "New message"
# Since one action changed in the second state, this should indicate that the states
# are not identical anymore
- assert st1.is_identical(st2) == False, "Action was changed and states should be different"
- assert st2.is_identical(st1) == False, "Action was changed and states should be different"
+ assert not (st1 == st2), "Action was changed and states should be different"
+ assert not (st2 == st1), "Action was changed and states should be different"
# Make sure that trying to find identity with something else than a State object fails properly
- assert st1.is_identical(non_state) == False, "Passing a non-State object should fail for identity"
+ assert not (st1 == non_state), "Passing a non-State object should fail for identity"
st2.name = "Not identical anymore"
- assert st1.is_identical(st2) == False, "Different state names should give different states"
+ assert not(st1 == st2), "Different state names should give different states"
st2.name = "Identical"
st3 = copy.deepcopy(st1)
st3.add_action(addon.create("BubbleMessage", "Hi!", [128,264]))
- assert st1.is_identical(st3) == False, "States having a different number of actions should be different"
+ assert not (st1 == st3), "States having a different number of actions should be different"
st4 = copy.deepcopy(st1)
st4.add_event_filter(addon.create("GtkWidgetEventFilter", "next_state", "0.0.1.1.2.2.3", "clicked"))
- assert st1.is_identical(st4) == False, "States having a different number of events should be different"
+ assert not (st1 == st4), "States having a different number of events should be different"
st5 = copy.deepcopy(st1)
st5._event_filters = []
@@ -295,7 +292,8 @@ class StateTest(unittest.TestCase):
st5.add_event_filter(addon.create("GtkWidgetEventFilter", "other_state", "0.1.2.3.4.1.2", "pressed"))
#import rpdb2; rpdb2.start_embedded_debugger('pass')
- assert st1.is_identical(st5) == False, "States having the same number of event filters but those being different should be different"
+ assert not (st1 == st5), "States having the same number of event filters" \
+ + " but those being different should be different"
class FSMTest(unittest.TestCase):
"""
@@ -433,10 +431,10 @@ class FSMTest(unittest.TestCase):
# Make sure that there is no link to the removed state in the rest
# of the FSM
- assert "second" not in fsm.get_following_states("INIT"),\
+ assert "second" not in fsm.get_following_states("INIT"), \
"The link to second from INIT still exists after removal"
- assert "second" not in fsm.get_following_states("third"),\
+ assert "second" not in fsm.get_following_states("third"), \
"The link to second from third still exists after removal"
def test_set_same_state(self):
@@ -463,7 +461,7 @@ class FSMTest(unittest.TestCase):
"The action was triggered a second time, do_count = %d"%do_count
undo_count = fsm.get_state_by_name("INIT").get_action_list()[0].undo_count
- assert fsm.get_state_by_name("INIT").get_action_list()[0].undo_count == 0,\
+ assert fsm.get_state_by_name("INIT").get_action_list()[0].undo_count == 0, \
"The action has been undone unappropriately, undo_count = %d"%undo_count
def test_setup(self):
@@ -514,12 +512,12 @@ class FSMTest(unittest.TestCase):
assert str(fsm) == "INIT, Final State, Other State, "
- def test_is_identical(self):
+ def test_eq_(self):
fsm = FiniteStateMachine("Identity test")
non_fsm_object = object()
- assert fsm.is_identical(non_fsm_object) == False, "Testing with non FSM object should not give identity"
+ assert not (fsm == non_fsm_object), "Testing with non FSM object should not give identity"
# Compare FSMs
act1 = CountAction()
@@ -528,19 +526,21 @@ class FSMTest(unittest.TestCase):
fsm2 = copy.deepcopy(fsm)
- assert fsm.is_identical(fsm2)
+ assert fsm == fsm2
act2 = CountAction()
fsm2.add_action(act2)
- assert fsm.is_identical(fsm2) == False, "FSMs having a different number of actions should be different"
+ assert not(fsm == fsm2), \
+ "FSMs having a different number of actions should be different"
fsm3 = FiniteStateMachine("Identity test")
act3 = addon.create("BubbleMessage", "Hi!", [123,312])
fsm3.add_action(act3)
- assert fsm3.is_identical(fsm) == False, "Actions having the same number of actions but different ones should be different"
+ assert not(fsm3 == fsm), \
+ "Actions having the same number of actions but different ones should be different"
st1 = State("INIT")
@@ -551,17 +551,17 @@ class FSMTest(unittest.TestCase):
fsm4 = copy.deepcopy(fsm)
- assert fsm.is_identical(fsm4)
+ assert fsm == fsm4
st3 = State("Last State")
fsm4.add_state(st3)
- assert fsm.is_identical(fsm4) == False, "FSMs having a different number of states should not be identical"
+ assert not (fsm == fsm4), "FSMs having a different number of states should not be identical"
fsm4.remove_state("OtherState")
- assert fsm.is_identical(fsm4) == False, "FSMs having different states should be different"
+ assert not (fsm == fsm4), "FSMs having different states should be different"
fsm4.remove_state("Last State")
@@ -570,7 +570,7 @@ class FSMTest(unittest.TestCase):
fsm4.add_state(st5)
- assert fsm.is_identical(fsm4) == False, "FSMs having states with same name but different content should be different"
+ assert not(fsm == fsm4), "FSMs having states with same name but different content should be different"
class FSMExplorationTests(unittest.TestCase):
def setUp(self):
@@ -627,34 +627,5 @@ class FSMExplorationTests(unittest.TestCase):
self.validate_previous_states("Fourth", ("Second"))
- def test_is_identical(self):
- otherFSM = copy.deepcopy(self.fsm)
-
- assert self.fsm.is_identical(otherFSM), "Copied FSM was different"
-
- # Change the name of the second FSM
- otherFSM.name = "OtherName"
-
- assert self.fsm.is_identical(otherFSM) == False, "Name change should make the FSMs different"
-
- otherFSM.name = self.fsm.name
-
- # Add an extra state to the second FSM
- new_state = State("New State!")
-
- act1 = addon.create("BubbleMessage", message="This will make the second FSM different", position=[100, 0])
- new_state.add_action(act1)
-
- otherFSM.add_state(new_state)
-
- assert self.fsm.is_identical(otherFSM) == False, "The second FSM has an extra state and should not be identical"
-
- otherFSM.remove_state("New State!")
-
- # Test difference with one FSM having an FSM-level action
- otherFSM.add_action(act1)
-
- assert self.fsm.is_identical(otherFSM) == False, "The second FSM has an FSM-level action and should be different"
-
if __name__ == "__main__":
unittest.main()