summaryrefslogtreecommitdiff
path: root/tests/ecore/test_04_idler.py
diff options
context:
space:
mode:
authorDave Andreoli <dave@gurumeditation.it>2016-08-14 13:02:19 +0200
committerDave Andreoli <dave@gurumeditation.it>2016-08-14 13:02:19 +0200
commit4bd421562d2c2403ef2000ce3d903b991eae7f6e (patch)
tree53b2c2fef2616b6101149554c4d44f7f21bc6f14 /tests/ecore/test_04_idler.py
parentd6fc38ea59e2c1438fa9bd1a579ba11747e3632d (diff)
Improve the ecore test suite
no more print and lots more asserts
Diffstat (limited to 'tests/ecore/test_04_idler.py')
-rw-r--r--tests/ecore/test_04_idler.py54
1 files changed, 30 insertions, 24 deletions
diff --git a/tests/ecore/test_04_idler.py b/tests/ecore/test_04_idler.py
index dc9b100..7480df7 100644
--- a/tests/ecore/test_04_idler.py
+++ b/tests/ecore/test_04_idler.py
@@ -1,48 +1,54 @@
1#!/usr/bin/env python 1#!/usr/bin/env python
2 2
3from efl import ecore
4import unittest 3import unittest
5import logging 4import logging
6 5
6from efl import ecore
7 7
8def cb_true(n, t, a):
9 print("cb_true: %s %s %s" % (n, t, a))
10 return True
11 8
12def cb_false(n, t, a): 9class TestIdler(unittest.TestCase):
13 print("cb_false: %s %s %s" % (n, t, a))
14 return False
15 10
11 def cb_renew(self, n, t, a):
12 self.assertEqual(n, 123)
13 self.assertEqual(t, "teste")
14 self.assertEqual(a, 456)
15 self.counters[0] += 1
16 return ecore.ECORE_CALLBACK_RENEW
17
18 def cb_cancel(self, n, t, a):
19 self.assertEqual(n, 789)
20 self.assertEqual(t, "bla")
21 self.assertEqual(a, "something in a")
22 self.counters[1] += 1
23 return ecore.ECORE_CALLBACK_CANCEL
16 24
17class TestIdler(unittest.TestCase):
18 def testInit(self): 25 def testInit(self):
19 i1 = ecore.idler_add(cb_true, 123, "teste", a=456) 26 self.counters = [0, 0]
20 i2 = ecore.Idler(cb_false, 789, "bla", a="something in a") 27
28 i1 = ecore.idler_add(self.cb_renew, 123, "teste", a=456)
29 i2 = ecore.Idler(self.cb_cancel, 789, "bla", a="something in a")
21 30
22 self.assertIsInstance(i1, ecore.Idler) 31 self.assertIsInstance(i1, ecore.Idler)
23 self.assertIsInstance(i2, ecore.Idler) 32 self.assertIsInstance(i2, ecore.Idler)
24 33
25 before1 = i1.__repr__()
26 before2 = i2.__repr__()
27
28 t = ecore.timer_add(1, ecore.main_loop_quit) 34 t = ecore.timer_add(1, ecore.main_loop_quit)
29 ecore.main_loop_begin() 35 ecore.main_loop_begin()
30 36
31 after1 = i1.__repr__() 37 # all the callback has been called?
32 after2 = i2.__repr__() 38 self.assertTrue(self.counters[0] > 1)
39 self.assertTrue(self.counters[1] == 1)
33 40
34 self.assertEqual(before1, after1) 41 # not yet deleted since returned true
35 self.assertNotEqual(before2, after2) # already deleted
36
37 self.assertEqual(t.is_deleted(), True)
38 self.assertEqual(i1.is_deleted(), False) 42 self.assertEqual(i1.is_deleted(), False)
39 self.assertEqual(i2.is_deleted(), True)
40
41
42 i1.delete() 43 i1.delete()
43 del t 44 self.assertEqual(i1.is_deleted(), True)
44 del i1 45 del i1
45 del i2 # already deleted since returned false 46
47 # already deleted since returned false
48 self.assertEqual(i2.is_deleted(), True)
49 self.assertEqual(t.is_deleted(), True)
50 del i2
51 del t
46 52
47 53
48if __name__ == '__main__': 54if __name__ == '__main__':