From d5c9eac8fbf938c1874672b78272ba1bee41e573 Mon Sep 17 00:00:00 2001 From: Vincent Vinet Date: Fri, 30 Oct 2009 13:42:50 +0000 Subject: code review fixes for tests --- (limited to 'tests') diff --git a/tests/probetests.py b/tests/probetests.py index 3690a25..e1a587b 100644 --- a/tests/probetests.py +++ b/tests/probetests.py @@ -227,6 +227,7 @@ class ProbeTest(unittest.TestCase): self.probe.update(address, pickle.dumps(action._props)) assert message_box == (10, "ahhah!"), "message box should have changed(i, s)" + #ErrorCase: Update with bad address #try to update 2, should fail self.assertRaises(KeyError, self.probe.update, address2, pickle.dumps(action._props)) @@ -234,6 +235,7 @@ class ProbeTest(unittest.TestCase): assert message_box is None, "undo should clear the message box" message_box = "Test" + #ErrorCase: Uninstall bad address (currently silent fail) #Uninstall twice should do nothing self.probe.uninstall(address) assert message_box == "Test", "undo should not have happened again" @@ -276,6 +278,7 @@ class ProbeTest(unittest.TestCase): assert message_box is None, "unsubscribe should clear the message_box" event_box = None + #ErrorCase: callback called from unregistered event filter #Do the callback 1 again self.assertRaises(RuntimeWarning, cb1) @@ -285,6 +288,7 @@ class ProbeManagerTest(unittest.TestCase): self.probeManager = ProbeManager(proxy_class=MockProbeProxy) def test_attach(self): + #ErrorCase: Set currentActivity to unattached activity #Attempt to set to a non existing activity try: self.probeManager.currentActivity = "act1" @@ -297,8 +301,8 @@ class ProbeManagerTest(unittest.TestCase): #Should have been created assert "act1" in MockProbeProxy._MockProxyCache.keys(), "Proxy not created" - act1 = MockProbeProxy("act1") + #ErrorCase: Attach multiple times to same activity #Try to attach again self.assertRaises(RuntimeWarning, self.probeManager.attach, "act1") @@ -320,6 +324,7 @@ class ProbeManagerTest(unittest.TestCase): assert self.probeManager.currentActivity is None, "Current activity should be None" #Attempt to detach again, should do nothing + #ErrorCase: detach already detached (currently silent fail) self.probeManager.detach("act1") #Now, attach 2 activities @@ -345,12 +350,13 @@ class ProbeManagerTest(unittest.TestCase): act2 = MockProbeProxy("act2") ad1 = MockAddon() + #ErrorCase: install, update, uninstall without currentActivity #Action functions should do a warning if there is no activity self.assertRaises(RuntimeWarning, self.probeManager.install, ad1) self.assertRaises(RuntimeWarning, self.probeManager.update, ad1, ad1) self.assertRaises(RuntimeWarning, self.probeManager.uninstall, ad1) assert act1.MockAction is None, "Action should not be installed on inactive proxy" - 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) @@ -382,6 +388,7 @@ class ProbeManagerTest(unittest.TestCase): 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) self.assertRaises(RuntimeWarning, self.probeManager.unsubscribe, None) @@ -395,8 +402,8 @@ class ProbeManagerTest(unittest.TestCase): assert act2.MockEvent is None, "No event should be on act2" self.probeManager.unsubscribe("SomeAddress") - assert act1.MockEventAddr == "SomeAddress", "Unsubscrive should have been called" - assert act2.MockEventAddr is None, "Unsubscrive should not have been called" + assert act1.MockEventAddr == "SomeAddress", "Unsubscribe should have been called" + assert act2.MockEventAddr is None, "Unsubscribe should not have been called" class ProbeProxyTest(unittest.TestCase): def setUp(self): @@ -429,7 +436,7 @@ class ProbeProxyTest(unittest.TestCase): self.probeProxy.install(action, block=True) assert pickle.loads(self.mockObj.MockCall["install"]["args"][0]) == action, "1 argument, the action" - #Update should fail on noninstalled actions + #ErrorCase: Update should fail on noninstalled actions self.assertRaises(RuntimeWarning, self.probeProxy.update, action2, action2, block=True) #Test the update @@ -438,6 +445,7 @@ class ProbeProxyTest(unittest.TestCase): assert args[0] == address, "arg 1 should be the action address" assert pickle.loads(args[1]) == action2._props, "arg2 should be the new action properties" + #ErrorCase: Uninstall on not installed action (silent fail) #Test the uninstall self.probeProxy.uninstall(action2, block=True) assert not "uninstall" in self.mockObj.MockCall, "Uninstall should not be called if action is not installed" @@ -468,11 +476,13 @@ class ProbeProxyTest(unittest.TestCase): assert message_box == event, "callback should have been called with event" message_box = None + #ErrorCase: eventOccured triggered by a wrong event #Call with a wrong event self.mockObj.MockCB["eventOccured"]["handler_function"](pickle.dumps(event2)) assert message_box is None, "callback should not have been called" + #ErrorCase: unsubcribe for non subscribed event #Test the unsubscribe self.probeProxy.unsubscribe("otheraddress", block=True) assert not "unsubscribe" in self.mockObj.MockCall, "Unsubscribe should not be called if event is not subscribeed" @@ -480,6 +490,7 @@ class ProbeProxyTest(unittest.TestCase): self.probeProxy.unsubscribe(address, block=True) assert self.mockObj.MockCall["unsubscribe"]["args"][0] == address, "1 argument, the event address" + #ErrorCase: eventOccured triggered by uninstalled event #Test the callback with unregistered event self.mockObj.MockCB["eventOccured"]["handler_function"](pickle.dumps(event)) assert message_box is None, "callback should not have been called" -- cgit v0.9.1