diff options
author | Vincent Vinet <vince.vinet@gmail.com> | 2009-12-04 05:06:49 (GMT) |
---|---|---|
committer | Vincent Vinet <vince.vinet@gmail.com> | 2009-12-06 20:32:16 (GMT) |
commit | fb422aef7ee6832c85c8fa8a703e491838e74d62 (patch) | |
tree | 871950b00610cb90f212cc78a5bca0fa1825aef9 /tests/probetests.py | |
parent | 96e5675b0003d57cb87eb44f470aa2d309d8329b (diff) |
Add Event Sources:
- Add source property in Action and EventFilter
- Change TPropContainer contructor to accept keyword arguments and set
properties that were given
- Change every single TPropContainer subclass constructor to accept
kwargs and pass them on to super init
- Add a "null" option for TStringProperty
Use Event Sources:
- Make the probe require a source property to install or subscribe
- Have ProbeProxy install and subscribe return a prefixed address
- Make update, uninstall and unsubsribe extract the prefix from the
address
- Have the TutorialRunner set a source on actions/events before
installing/subscribing instead of setting current activity on
ProbeManager
Test Event Sources:
- Change the tests according to the new constructors and behaviors
Diffstat (limited to 'tests/probetests.py')
-rw-r--r-- | tests/probetests.py | 129 |
1 files changed, 89 insertions, 40 deletions
diff --git a/tests/probetests.py b/tests/probetests.py index 357d223..f073135 100644 --- a/tests/probetests.py +++ b/tests/probetests.py @@ -71,7 +71,6 @@ class MockActivity(object): def get_id(self): return "unique_id_1" - class MockProbeProxy(object): _MockProxyCache = {} @@ -191,6 +190,8 @@ class ProbeTest(unittest.TestCase): self.activity.get_id(), service_proxy=MockServiceProxy()) #Override the eventOccured on the Probe... + # Stores events in a global "event box" + #WARNING: Depends on the implementation of TProbe!! self.old_eO = self.probe.eventOccured def newEo(event): global event_box @@ -343,51 +344,78 @@ class ProbeManagerTest(unittest.TestCase): assert len(self.probeManager.get_registered_probes_list("act1")) == 0 assert self.probeManager.get_registered_probes_list("act1") == [] - def test_actions(self): + def test_action_uninstall(self): self.probeManager.register_probe("act1", "unique_id_1") self.probeManager.register_probe("act2", "unique_id_2") act1 = self.probeManager.get_registered_probes_list("act1")[0][1] act2 = self.probeManager.get_registered_probes_list("act2")[0][1] - ad1 = MockAddon() - ad1_address = "Address1" - def callback(value): - pass - def error_cb(): - pass - #ErrorCase: install, update, uninstall without currentActivity - #Action functions should do a warning if there is no activity - self.assertRaises(RuntimeWarning, self.probeManager.install, ad1_address, ad1, callback) - self.assertRaises(RuntimeWarning, self.probeManager.update, ad1_address, ad1) - self.assertRaises(RuntimeWarning, self.probeManager.uninstall, ad1_address) - assert act1.MockAction is None, "Action should not be installed on inactive proxy" - assert act2.MockAction is None, "Action should not be installed on inactive proxy" - - self.probeManager.currentActivity = "act1" - self.probeManager.install(ad1, callback, error_cb) - assert act1.MockAction == ad1, "Action should have been installed" - assert act2.MockAction is None, "Action should not be installed on inactive proxy" + ad1 = MockAddon(source="act1") - self.probeManager.update(ad1_address, ad1) - assert act1.MockActionUpdate == ad1, "Action should have been updated" - assert act2.MockActionUpdate is None, "Should not update on inactive" + #ErrorCase: update should fail without a source + self.assertRaises(RuntimeWarning, self.probeManager.update, "SomeAddress", ad1) + #ErrorCase: update should fail if the source does not exist + self.assertRaises(RuntimeWarning, self.probeManager.update, "unique:SomeAddress", ad1) - self.probeManager.currentActivity = "act2" - self.probeManager.uninstall(ad1_address) - assert act1.MockActionAddress == ad1_address, "Action should still be installed" + self.probeManager.install(ad1, None, None) + + assert act1.MockAction == ad1, "Action should have been installed" + + self.probeManager.uninstall("unique_id_2:SomeAddress") + assert act1.MockAction == ad1, "Action should still be installed" - self.probeManager.currentActivity = "act1" - self.probeManager.uninstall(ad1_address) + self.probeManager.uninstall("unique_id_1:SomeAddress") assert act1.MockAction is None, "Action should be uninstalled" - def test_events(self): + def test_action_install(self): self.probeManager.register_probe("act1", "unique_id_1") self.probeManager.register_probe("act2", "unique_id_2") act1 = self.probeManager.get_registered_probes_list("act1")[0][1] act2 = self.probeManager.get_registered_probes_list("act2")[0][1] + ad1 = MockAddon(source="act1") + ad2 = MockAddon(source="act2") + ad3 = MockAddon(source="act3") + ad4 = MockAddon() + + #ErrorCase: install should fail without a source + self.assertRaises(RuntimeWarning, self.probeManager.install, ad4, None, None) + #ErrorCase: install should fail if the source does not exist + self.assertRaises(RuntimeWarning, self.probeManager.install, ad3, None, None) + + #install should put the action in the right probes + self.probeManager.install(ad1, None, None) + assert act1.MockAction is ad1, "Action should be on act1" + assert act2.MockAction is not ad1, "Action should not be on act2" + + self.probeManager.install(ad2, None, None) + assert act1.MockAction is not ad2, "Action should not be on act1" + assert act2.MockAction is ad2, "Action should be on act2" + + def test_action_update(self): + self.probeManager.register_probe("act1", "unique_id_1") + self.probeManager.register_probe("act2", "unique_id_2") + act1 = self.probeManager.get_registered_probes_list("act1")[0][1] + act2 = self.probeManager.get_registered_probes_list("act2")[0][1] ad1 = MockAddon() - ad2 = MockAddon() + + #ErrorCase: update should fail without a source + self.assertRaises(RuntimeWarning, self.probeManager.update, "SomeAddress", ad1) + #ErrorCase: update should fail if the source does not exist + self.assertRaises(RuntimeWarning, self.probeManager.update, "unique:SomeAddress", ad1) + + #update should update the right probe + self.probeManager.update("unique_id_1:Address", ad1) + assert act1.MockActionUpdate is ad1, "Action should be on act1" + assert act2.MockActionUpdate is not ad1, "Action should not be on act1" + + def test_event_unsubscribe(self): + self.probeManager.register_probe("act1", "unique_id_1") + self.probeManager.register_probe("act2", "unique_id_2") + act1 = self.probeManager.get_registered_probes_list("act1")[0][1] + + ad1 = MockAddon(source="act1") + ad2 = MockAddon(source="act2") ad2.i, ad2.s = (2, "test2") cb1 = lambda *args: None @@ -395,22 +423,43 @@ class ProbeManagerTest(unittest.TestCase): error_cb1 = lambda *args:None cb2 = lambda *args: None - #ErrorCase: unsubscribe and subscribe without current activity - #Event functions should do a warning if there is no activity - 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" + #ErrorCase: unsubscribe should fail without a source + self.assertRaises(RuntimeWarning, self.probeManager.unsubscribe, "SomeAddress") + #ErrorCase: unsubscribe should fail silently if the source does not exist + self.probeManager.unsubscribe("unique:SomeAddress") + assert act1.MockEventAddr is None, "No unsubcribe should have been called" - self.probeManager.currentActivity = "act1" 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" - self.probeManager.unsubscribe("SomeAddress") + self.probeManager.unsubscribe("unique_id_1:SomeAddress") assert act1.MockEventAddr == "SomeAddress", "Unsubscribe should have been called" - assert act2.MockEventAddr is None, "Unsubscribe should not have been called" + + def test_event_subscribe(self): + self.probeManager.register_probe("act1", "unique_id_1") + self.probeManager.register_probe("act2", "unique_id_2") + act1 = self.probeManager.get_registered_probes_list("act1")[0][1] + act2 = self.probeManager.get_registered_probes_list("act2")[0][1] + + ad1 = MockAddon(source="act1") + ad2 = MockAddon(source="act2") + ad3 = MockAddon(source="act3") + ad4 = MockAddon() + + #ErrorCase: subscribe should fail without a source + self.assertRaises(RuntimeWarning, self.probeManager.subscribe, ad4, None, None, None) + #ErrorCase: subscribe should fail if the source does not exist + self.assertRaises(RuntimeWarning, self.probeManager.subscribe, ad3, None, None, None) + #subscribe should put the action in the right probes + self.probeManager.subscribe(ad1, None, None, None) + assert act1.MockEvent is ad1, "Action should be on act1" + assert act2.MockEvent is not ad1, "Action should not be on act2" + + self.probeManager.subscribe(ad2, None, None, None) + assert act1.MockEvent is not ad2, "Action should not be on act1" + assert act2.MockEvent is ad2, "Action should be on act2" + class ProbeProxyTest(unittest.TestCase): def setUp(self): |