diff --git a/gramps/gen/utils/test/callback_test.py b/gramps/gen/utils/test/callback_test.py index 1684c4a1e..a26d9b055 100644 --- a/gramps/gen/utils/test/callback_test.py +++ b/gramps/gen/utils/test/callback_test.py @@ -18,7 +18,6 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -# gen/utils/test/callback_test.py # $Id$ import unittest @@ -50,8 +49,8 @@ class TestCallback(unittest.TestCase): t.emit('test-signal',(1,)) - assert len(rl) == 1, "No signal emitted" - assert rl[0] == 1, "Wrong argument recieved" + self.assertEqual(len(rl), 1, "No signal emitted") + self.assertEqual(rl[0], 1, "Wrong argument recieved") def test_exception_catch(self): @@ -89,8 +88,8 @@ class TestCallback(unittest.TestCase): t.emit('test-signal',(1,)) log = _log - assert len(rl) == 1, "No signal emitted" - assert rl[0] == 1, "Wrong argument recieved" + self.assertEqual(len(rl), 1, "No signal emitted") + self.assertEqual(rl[0], 1, "Wrong argument recieved") def test_disconnect(self): @@ -109,15 +108,15 @@ class TestCallback(unittest.TestCase): t.emit('test-signal',(1,)) - assert len(rl) == 1, "No signal emitted" - assert rl[0] == 1, "Wrong argument recieved" + self.assertEqual(len(rl), 1, "No signal emitted") + self.assertEqual(rl[0], 1, "Wrong argument recieved") t.disconnect(key) t.emit('test-signal',(1,)) - assert len(rl) == 1, "Callback not disconnected" - assert rl[0] == 1, "Callback not disconnected" + self.assertEqual(len(rl), 1, "Callback not disconnected") + self.assertEqual(rl[0], 1, "Callback not disconnected") def test_noargs(self): @@ -136,8 +135,8 @@ class TestCallback(unittest.TestCase): t.emit('test-noargs') - assert len(rl) == 1, "No signal emitted" - assert rl[0] == 1, "Wrong argument recieved" + self.assertEqual(len(rl), 1, "No signal emitted") + self.assertEqual(rl[0], 1, "Wrong argument recieved") def test_no_callback(self): @@ -170,14 +169,14 @@ class TestCallback(unittest.TestCase): t.connect('test-signal',fn) t.emit('test-signal',(1,)) - assert len(rl) == 1, "No signal emitted" - assert rl[0] == 1, "Wrong argument recieved" + self.assertEqual(len(rl), 1, "No signal emitted") + self.assertEqual(rl[0], 1, "Wrong argument recieved") t.connect('test-sub-signal',fn) t.emit('test-sub-signal',(1,)) - assert len(rl) == 2, "No subclass signal emitted" - assert rl[1] == 1, "Wrong argument recieved in subclass" + self.assertEqual(len(rl), 2, "No subclass signal emitted") + self.assertEqual(rl[1], 1, "Wrong argument recieved in subclass") def test_signal_block(self): @@ -195,24 +194,24 @@ class TestCallback(unittest.TestCase): t.connect('test-signal',fn) t.emit('test-signal',(1,)) - assert len(rl) == 1, "No signal emitted" - assert rl[0] == 1, "Wrong argument recieved" + self.assertEqual(len(rl), 1, "No signal emitted") + self.assertEqual(rl[0], 1, "Wrong argument recieved") Callback.disable_all_signals() t.emit('test-signal',(1,)) - assert len(rl) == 1, "Signal emitted while class blocked" + self.assertEqual(len(rl), 1, "Signal emitted while class blocked") Callback.enable_all_signals() t.emit('test-signal',(1,)) - assert len(rl) == 2, "Signals not class unblocked" + self.assertEqual(len(rl), 2, "Signals not class unblocked") t.disable_signals() t.emit('test-signal',(1,)) - assert len(rl) == 2, "Signal emitted while instance blocked" + self.assertEqual(len(rl), 2, "Signal emitted while instance blocked") t.enable_signals() t.emit('test-signal',(1,)) - assert len(rl) == 3, "Signals not instance unblocked" + self.assertEqual(len(rl), 3, "Signals not instance unblocked") def test_type_checking(self): @@ -233,26 +232,26 @@ class TestCallback(unittest.TestCase): t = TestSignals() t.connect('test-int',fn), t.emit('test-int',(1,)) - assert isinstance(rl[0], int), "not int" + self.assertIsInstance(rl[0], int, "not int") t.connect('test-list',fn), t.emit('test-list',([1,2],)) - assert isinstance(rl[1], list), "not list" + self.assertIsInstance(rl[1], list, "not list") t.connect('test-object',fn), t.emit('test-object',(t,)) - assert isinstance(rl[2], object), "not object" + self.assertIsInstance(rl[2], object, "not object") t.connect('test-float',fn), t.emit('test-float',(2.3,)) - assert isinstance(rl[3], float), "not float" + self.assertIsInstance(rl[3], float, "not float") t.connect('test-dict',fn), t.emit('test-dict',({1:2},)) - assert isinstance(rl[4], dict), "not dict" + self.assertIsInstance(rl[4], dict, "not dict") rl = [] def fn2(i,s,l, o,f,r=rl): rl.append(i) t.connect('test-lots',fn2), t.emit('test-lots',(1,'a',[1,2],t,1.2)) - assert isinstance(rl[0], int), "not lots" + self.assertIsInstance(rl[0], int, "not lots") # This should fail because the type of arg1 is wrong res=[] @@ -260,7 +259,7 @@ class TestCallback(unittest.TestCase): res.append(s) t._warn = fn3 t.connect('test-lots',fn2), t.emit('test-lots',('a','a',[1,2],t,1.2)) - assert res[0][0:6] == "Signal", "Type error not detected" + self.assertEqual(res[0][0:6], "Signal", "Type error not detected") def test_recursion_block(self): @@ -284,9 +283,9 @@ class TestCallback(unittest.TestCase): try: t.emit('test-recursion',(t,)) except RuntimeError: - assert False, "signal recursion not blocked1." + self.fail("signal recursion not blocked1.") - assert res[0][0:6] == "Signal", "signal recursion not blocked" + self.assertEqual(res[0][0:6], "Signal", "signal recursion not blocked") def test_multisignal_recursion_block(self): @@ -319,9 +318,10 @@ class TestCallback(unittest.TestCase): try: t.emit('test-top',(t,)) except RuntimeError: - assert False, "multisignal recursion not blocked1." + self.fail("multisignal recursion not blocked1.") - assert res[0][0:6] == "Signal", "multisignal recursion not blocked" + self.assertEqual(res[0][0:6], "Signal", + "multisignal recursion not blocked") if __name__ == "__main__": unittest.main()