Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Vinet <vince.vinet@gmail.com>2009-10-23 19:08:32 (GMT)
committer Vincent Vinet <vince.vinet@gmail.com>2009-10-23 19:08:32 (GMT)
commit704e35494433a11ecdcf675fff7cfccaa8bbd2ec (patch)
tree0757d4f3fa7cc0613135897d65e5fa827d4abb41
parentfa1197aad8d56b43bdf57ec3ad3ef9b9216d1376 (diff)
fix some of the tests, fix some bugs
-rw-r--r--tests/coretests.py45
-rw-r--r--tutorius/core.py20
-rw-r--r--tutorius/properties.py2
3 files changed, 28 insertions, 39 deletions
diff --git a/tests/coretests.py b/tests/coretests.py
index 4f564c8..4d5055e 100644
--- a/tests/coretests.py
+++ b/tests/coretests.py
@@ -130,9 +130,9 @@ class StateTest(unittest.TestCase):
Tests the fact that the event filters are correctly installed on setup
and uninstalled on teardown.
"""
- event_filter = addon.create('TriggerEventFilter', "second_state")
+ event_filter = addon.create('TriggerEventFilter')
- state = State("event_test", event_filter_list=[event_filter])
+ state = State("event_test", event_filter_list=[(event_filter, "second_state")])
state.set_tutorial(SimpleTutorial())
assert event_filter.toggle_on_callback == False, "Wrong init of event_filter"
@@ -198,22 +198,21 @@ class StateTest(unittest.TestCase):
def test_add_event_filter(self):
state = State("INIT")
- event1 = addon.create('TriggerEventFilter', "s")
- event2 = addon.create('TriggerEventFilter', "t")
- event3 = addon.create('TriggerEventFilter', "r")
+ event1 = addon.create('TriggerEventFilter')
+ event2 = addon.create('TriggerEventFilter')
# Insert the event filters
- assert state.add_event_filter(event1), "Could not add event filter 1"
- assert state.add_event_filter(event2), "Could not add event filter 2"
- assert state.add_event_filter(event3), "Could not add event filter 3"
+ assert state.add_event_filter(event1, "s"), "Could not add event filter 1"
# Make sure we cannot insert an event twice
- assert state.add_event_filter(event1) == False, "Could add twice the event filter"
+ assert state.add_event_filter(event1, "s") == False, "Could add twice the event filter"
+ assert state.add_event_filter(event2, "t") == False, "Could add event filter 2"
# Get the list of event filters
- event_filters = state.get_event_filter_list()
+ event_filters = map(lambda x: x[0],state.get_event_filter_list())
- assert event1 in event_filters and event2 in event_filters and event3 in event_filters, \
+ #even if we added only the event 1, they are equivalent
+ assert event1 in event_filters and event2 in event_filters, \
"The event filters were not all added inside the state"
# Clear the list
@@ -243,19 +242,19 @@ class StateTest(unittest.TestCase):
act1 = addon.create("BubbleMessage", message="Hi", position=[132,450])
act2 = addon.create("BubbleMessage", message="Hi", position=[132,450])
- event1 = addon.create("GtkWidgetEventFilter", "nextState", "0.0.0.1.1.2.3.1", "clicked")
+ event1 = addon.create("GtkWidgetEventFilter", "0.0.0.1.1.2.3.1", "clicked")
act3 = addon.create("DialogMessage", message="Hello again.", position=[200, 400])
# Build the first state
st1.add_action(act1)
st1.add_action(act3)
- st1.add_event_filter(event1)
+ st1.add_event_filter(event1, "nextState")
# Build the second state
st2.add_action(act2)
st2.add_action(act3)
- st2.add_event_filter(event1)
+ st2.add_event_filter(event1, "nextState")
# Make sure that they are identical for now
assert st1 == st2, "States should be considered as identical"
@@ -305,10 +304,10 @@ class FSMTest(unittest.TestCase):
act_init = TrueWhileActiveAction()
act_second = TrueWhileActiveAction()
- event_init = FakeEventFilter("SECOND")
+ event_init = FakeEventFilter()
content = {
- "INIT": State("INIT", action_list=[act_init],event_filter_list=[event_init]),
+ "INIT": State("INIT", action_list=[act_init],event_filter_list=[(event_init,"SECOND")]),
"SECOND": State("SECOND", action_list=[act_second])
}
@@ -399,9 +398,9 @@ class FSMTest(unittest.TestCase):
This test removes a state from the FSM. It also verifies that the links
from other states going into the removed state are gone.
"""
- st1 = State("INIT", event_filter_list=[addon.create('TriggerEventFilter', "second")])
- st2 = State("second", event_filter_list=[addon.create('TriggerEventFilter', "third")])
- st3 = State("third", event_filter_list=[addon.create('TriggerEventFilter', "second")])
+ st1 = State("INIT", event_filter_list=[(addon.create('TriggerEventFilter'), "second")])
+ st2 = State("second", event_filter_list=[(addon.create('TriggerEventFilter'), "third")])
+ st3 = State("third", event_filter_list=[(addon.create('TriggerEventFilter'), "second")])
fsm = FiniteStateMachine("StateRemovalTest")
@@ -582,13 +581,13 @@ class FSMExplorationTests(unittest.TestCase):
"""
st1 = State("INIT")
st1.add_action(CountAction())
- st1.add_event_filter(addon.create('TriggerEventFilter', "Second"))
- st1.add_event_filter(addon.create('TriggerEventFilter', "Third"))
+ st1.add_event_filter(addon.create('TriggerEventFilter'), "Second")
+ st1.add_event_filter(addon.create('TriggerEventFilter'), "Third")
st2 = State("Second")
st2.add_action(TrueWhileActiveAction())
- st2.add_event_filter(addon.create('TriggerEventFilter', "Third"))
- st2.add_event_filter(addon.create('TriggerEventFilter', "Fourth"))
+ st2.add_event_filter(addon.create('TriggerEventFilter'), "Third")
+ st2.add_event_filter(addon.create('TriggerEventFilter'), "Fourth")
st3 = State("Third")
st3.add_action(CountAction())
diff --git a/tutorius/core.py b/tutorius/core.py
index 15a0c87..b24b80b 100644
--- a/tutorius/core.py
+++ b/tutorius/core.py
@@ -271,7 +271,7 @@ class State(object):
if len(self._actions) != len(otherState._actions):
return False
- if len(self._event_filters) != len(otherState._event_filters):
+ if len(self._transitions) != len(otherState._transitions):
return False
for act in self._actions:
@@ -287,18 +287,8 @@ class State(object):
return False
# Do they have the same event filters?
- for event in self._event_filters:
- found = False
- # For every event filter in the other state, try to match it with
- # the current filter. We just need to find one with the right
- # properties and values.
- for otherEvent in otherState._event_filters:
- if event == otherEvent:
- found = True
- break
- if found == False:
- # We could not find the given event filter in the other state.
- return False
+ if self._transitions != otherState._transitions:
+ return False
# If nothing failed up to now, then every actions and every filters can
# be found in the other state
@@ -536,7 +526,7 @@ class FiniteStateMachine(State):
next_states = set()
- for event, state in state._transitions:
+ for event, state in state._transitions.items():
next_states.add(state)
return tuple(next_states)
@@ -559,7 +549,7 @@ class FiniteStateMachine(State):
states = []
# Walk through the list of states
for st in self._states.itervalues():
- for event, state in st._transitions:
+ for event, state in st._transitions.items():
if state == state_name:
states.append(state)
continue
diff --git a/tutorius/properties.py b/tutorius/properties.py
index 78e3c2b..cbb2ae3 100644
--- a/tutorius/properties.py
+++ b/tutorius/properties.py
@@ -104,7 +104,7 @@ class TPropContainer(object):
return hash(tuple(map(tuple,sorted(self._props.items(), cmp=lambda x, y: cmp(x[0], y[0])))))
def __eq__(self, e2):
- return self._props == e2._props
+ return isinstance(e2, type(self)) and self._props == e2._props
# Adding methods for pickling and unpickling an object with
# properties