Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormike <michael.jmontcalm@gmail.com>2009-11-26 23:03:38 (GMT)
committer mike <michael.jmontcalm@gmail.com>2009-11-26 23:03:38 (GMT)
commitb290d0384ea13319026ddcaeca5d567a2556f0e3 (patch)
tree5ad586b7000d023c8ac0d37f72bb392a6449da2e
parenta6bdbdecfbe53924dc8e38768aed1d8037be6143 (diff)
LP 448319 : Code review changes 2
-rw-r--r--tests/enginetests.py57
-rw-r--r--tests/probetests.py14
-rw-r--r--tutorius/TProbe.py12
-rw-r--r--tutorius/engine.py2
-rw-r--r--tutorius/translator.py31
5 files changed, 20 insertions, 96 deletions
diff --git a/tests/enginetests.py b/tests/enginetests.py
index 2d1e723..f24aedb 100644
--- a/tests/enginetests.py
+++ b/tests/enginetests.py
@@ -49,60 +49,6 @@ class MockProbeMgrMultiAddons(object):
currentActivity = property(fget=lambda s:s, fset=lambda s, v: v)
def run_install_cb(self, action_number, action):
- self._action_installed_cb_list[action_number](action, str(uuid1()))
-
- def run_install_error_cb(self, action_number):
- self._install_error_cb_list[action_number](Exception("Could not install action..."))
-
- def run_subscribe_cb(self, event_number):
- self._event_subscribed_cb_list[event_number](str(uuid1()))
-
- def run_subscribe_error(self, event_number):
- self._subscribe_error_cb_list[event_number](str(uuid1()))
-
- def install(self, action, action_installed_cb, error_cb):
- action_address = str(uuid1())
- self.action_dict[action_address] = action
- self._action_installed_cb_list.append(action_installed_cb)
- self._install_error_cb_list.append(error_cb)
-
- def update(self, action_address, new_action):
- self.action_dict[action_address] = new_action
-
- def uninstall(self, action_address):
- del self.action_dict[action_address]
-
- def subscribe(self, event_name, event, notif_cb, subscribe_cb, error_cb):
- event_address = str(uuid1())
- self.event_dict[event_name] = event_address
- self.event_cb_dict[event_name] = notif_cb
- self._event_subscribed_cb_list.append(subscribe_cb)
- self._subscribe_error_cb_list.append(error_cb)
-
- def unsubscribe(self, address):
- for (event_name, other_event) in self.event_dict.values():
- if event == othet_event:
- del self.event_dict[event_name]
- break
-
-class MockProbeMgrMultiAddons(object):
- """
- Mock probe manager that supports installing more than one action
- at the time.
- """
- def __init__(self):
- self.action_dict = {}
- self.event_dict = {}
- self.event_cb_dict = {}
-
- self._action_installed_cb_list = []
- self._install_error_cb_list = []
- self._event_subscribed_cb_list = []
- self._subscribe_error_cb_list = []
-
- currentActivity = property(fget=lambda s:s, fset=lambda s, v: v)
-
- def run_install_cb(self, action_number, action):
self._action_installed_cb_list[action_number](str(uuid1()))
def run_install_error_cb(self, action_number):
@@ -112,7 +58,7 @@ class MockProbeMgrMultiAddons(object):
self._event_subscribed_cb_list[event_number](str(uuid1()))
def run_subscribe_error(self, event_number):
- self._subscribe_error_cb_list[event_number](str(uuid1()))
+ self._subscribe_error_cb_list[event_number](Exception("Could not subscribe to event"))
def install(self, action, action_installed_cb, error_cb):
action_address = str(uuid1())
@@ -248,7 +194,6 @@ class TestInstallationStates(unittest.TestCase):
self.state_name = self.tutorial.add_state()
self.tutorial.update_transition(Tutorial.INITIAL_TRANSITION_NAME,
None, self.state_name)
- #import rpdb2; rpdb2.start_embedded_debugger('pass')
self.action1 = CountAction()
self.tutorial.add_action(self.state_name, self.action1)
self.action2 = CountAction()
diff --git a/tests/probetests.py b/tests/probetests.py
index d43da8e..8dbac29 100644
--- a/tests/probetests.py
+++ b/tests/probetests.py
@@ -113,9 +113,8 @@ class MockProbeProxy(object):
self.MockActionUpdate = None
return None
- def subscribe(self, event_name, event, notif_cb, subscribe_cb, error_cb):
+ def subscribe(self, event, notif_cb, subscribe_cb, error_cb):
#Do like the current Probe
- self.MockEventName = event_name
self.MockEvent = event
self.MockCB = notif_cb
self.MockSubscribeCB = subscribe_cb
@@ -383,8 +382,6 @@ class ProbeManagerTest(unittest.TestCase):
act1 = self.probeManager.get_registered_probes_list("act1")[0][1]
act2 = self.probeManager.get_registered_probes_list("act2")[0][1]
- event_name1 = 'State0/event0'
- event_name2 = 'State0/event1'
ad1 = MockAddon()
ad2 = MockAddon()
ad2.i, ad2.s = (2, "test2")
@@ -396,13 +393,13 @@ class ProbeManagerTest(unittest.TestCase):
#ErrorCase: unsubscribe and subscribe without current activity
#Event functions should do a warning if there is no activity
- self.assertRaises(RuntimeWarning, self.probeManager.subscribe, event_name1, ad1, cb1, install_cb1, error_cb1)
+ self.assertRaises(RuntimeWarning, self.probeManager.subscribe, ad1, cb1, install_cb1, error_cb1)
self.assertRaises(RuntimeWarning, self.probeManager.unsubscribe, None)
assert act1.MockEvent is None, "No event should be on act1"
assert act2.MockEvent is None, "No event should be on act2"
self.probeManager.currentActivity = "act1"
- self.probeManager.subscribe(event_name1, ad1, cb1, install_cb1, error_cb1)
+ self.probeManager.subscribe(ad1, cb1, install_cb1, error_cb1)
assert act1.MockEvent == ad1, "Event should have been installed"
assert act1.MockCB == cb1, "Callback should have been set"
assert act2.MockEvent is None, "No event should be on act2"
@@ -484,13 +481,12 @@ class ProbeProxyTest(unittest.TestCase):
address = "Addr1"
#Set the return value of probe subscribe
self.mockObj.MockRet["subscribe"] = address
- self.probeProxy.subscribe('State0/event0', event, callback, subs_cb, error_cb)
- self.probeProxy._ProbeProxy__update_event('State0/event0', event, callback, subs_cb, event_address)
+ self.probeProxy.subscribe(event, callback, subs_cb, error_cb)
+ self.probeProxy._ProbeProxy__update_event(event, callback, subs_cb, event_address)
assert pickle.loads(self.mockObj.MockCall["subscribe"]["args"][0]) == event, "1 argument, the event"
#Call the callback with the event
global message_box
- #import rpdb2; rpdb2.start_embedded_debugger('pass')
self.mockObj.MockCB["eventOccured"]["handler_function"](pickle.dumps(event))
assert message_box == event, "callback should have been called with event"
message_box = None
diff --git a/tutorius/TProbe.py b/tutorius/TProbe.py
index e408fe9..dd27762 100644
--- a/tutorius/TProbe.py
+++ b/tutorius/TProbe.py
@@ -29,7 +29,7 @@ from . import addon
from .services import ObjectStore
from .properties import TPropContainer
-from .dbustools import remote_call, save_args, ignore, logError
+from .dbustools import remote_call, save_args
import copy
"""
@@ -359,7 +359,7 @@ class ProbeProxy:
del self._actions[this_action]
break
- def __update_event(self, event_name, event, callback, event_subscribed_cb, address):
+ def __update_event(self, event, callback, event_subscribed_cb, address):
LOGGER.debug("ProbeProxy :: Registered event %s with address %s", str(hash(event)), str(address))
# Since multiple callbacks could be associated to the same
# event signature, we will store multiple callbacks
@@ -408,7 +408,7 @@ class ProbeProxy:
else:
LOGGER.debug("ProbeProxy :: unsubsribe address %s inconsistency : not registered", address)
- def subscribe(self, event_name, event, notification_cb, event_subscribed_cb, error_cb):
+ def subscribe(self, event, notification_cb, event_subscribed_cb, error_cb):
"""
Register an event listener
@param event Event to listen for
@@ -425,7 +425,7 @@ class ProbeProxy:
# for event types and sources, we will need to revise the lookup
# mecanism for which callback function to call
self._probe.subscribe(pickle.dumps(event),
- reply_handler=save_args(self.__update_event, event_name, event, notification_cb, event_subscribed_cb),
+ reply_handler=save_args(self.__update_event, event, notification_cb, event_subscribed_cb),
error_handler=save_args(error_cb, event))
def unsubscribe(self, address, block=True):
@@ -526,7 +526,7 @@ class ProbeManager(object):
else:
raise RuntimeWarning("No activity attached")
- def subscribe(self, event_name, event, notification_cb, event_subscribed_cb, error_cb):
+ def subscribe(self, event, notification_cb, event_subscribed_cb, error_cb):
"""
Register an event listener
@param event Event to listen for
@@ -538,7 +538,7 @@ class ProbeManager(object):
@return address identifier used for unsubscribing
"""
if self.currentActivity:
- return self._first_proxy(self.currentActivity).subscribe(event_name, event, notification_cb,\
+ return self._first_proxy(self.currentActivity).subscribe(event, notification_cb,\
event_subscribed_cb, error_cb)
else:
raise RuntimeWarning("No activity attached")
diff --git a/tutorius/engine.py b/tutorius/engine.py
index 46e1152..c882d91 100644
--- a/tutorius/engine.py
+++ b/tutorius/engine.py
@@ -91,7 +91,7 @@ class TutorialRunner(object):
if self._runner_state == RUNNER_STATE_SETUP_ACTIONS or \
self._runner_state == RUNNER_STATE_SETUP_EVENTS:
heappush(self._message_queue, (STOP_MSG_PRIORITY, None))
- else:
+ elif self._runner_state != RUNNER_STATE_IDLE:
self._execute_stop()
def action_installed(self, action_name, address):
diff --git a/tutorius/translator.py b/tutorius/translator.py
index 13b3c61..4f29078 100644
--- a/tutorius/translator.py
+++ b/tutorius/translator.py
@@ -53,10 +53,6 @@ class ResourceTranslator(object):
self._probe_manager = probe_manager
self._tutorial_id = tutorial_id
- self._translation_mapping = {}
- self._action_installed_cbs = {}
- self._install_error_cbs = {}
-
def translate_resource(self, res_value):
"""
Replace the TResourceProperty in the container by their
@@ -154,8 +150,8 @@ class ResourceTranslator(object):
def detach(self, activity_id):
self._probe_manager.detach(activity_id)
- def subscribe(self, event_name, event, notification_cb, event_subscribed_cb, error_cb):
- return self._probe_manager.subscribe(event_name, event, notification_cb, event_subscribed_cb, error_cb)
+ def subscribe(self, event, notification_cb, event_subscribed_cb, error_cb):
+ return self._probe_manager.subscribe(event, notification_cb, event_subscribed_cb, error_cb)
def unsubscribe(self, address):
return self._probe_manager.unsubscribe(address)
@@ -171,19 +167,14 @@ class ResourceTranslator(object):
###########################################################################
- def action_installed(self, new_action, address):
- # Update the internal mapping
- self._translation_mapping[address] = new_action
-
+ def action_installed(self, action_installed_cb, address):
# Callback to the upper layers to inform them that the action
# was installed
- action_installed_cb = self._action_installed_cbs[new_action]
action_installed_cb(address)
- def action_install_error(self, new_action, exception):
+ def action_install_error(self, install_error_cb, old_action, exception):
# Warn the upper layer that the installation failed
- error_cb = self._install_error_cbs[new_action]
- error_cb(old_action, exception)
+ install_error_cb(old_action, exception)
# Decorated functions
def install(self, action, action_installed_cb, error_cb):
@@ -194,24 +185,16 @@ class ResourceTranslator(object):
# Execute the replacement
self.translate(new_action)
- self._action_installed_cbs[new_action] = action_installed_cb
- self._install_error_cbs[new_action] = error_cb
-
# Send the new action to the probe manager
- self._probe_manager.install(new_action, save_args(self.action_installed, new_action),
- save_args(self.action_install_error, new_action))
+ self._probe_manager.install(new_action, save_args(self.action_installed, action_installed_cb),
+ save_args(self.action_install_error, error_cb, new_action))
def update(self, action_address, newaction):
translated_new_action = copy_module.deepcopy(newaction)
self.translate(translated_new_action)
- self._translation_mapping[action_address] = translated_new_action
-
self._probe_manager.update(action_address, translated_new_action, block)
def uninstall(self, action_address):
- if self._translation_mapping.has_key(action_address):
- del self._translation_mapping[action_address]
-
self._probe_manager.uninstall(action_address)