diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/glibext/work.py | 26 | ||||
-rw-r--r-- | tests/glibext/workqueue.py | 49 |
2 files changed, 75 insertions, 0 deletions
diff --git a/tests/glibext/work.py b/tests/glibext/work.py new file mode 100644 index 0000000..808e25e --- /dev/null +++ b/tests/glibext/work.py @@ -0,0 +1,26 @@ + +from chrysacase import ChrysalideTestCase +from pychrysalide.glibext import GenericWork + + +class TestWorks(ChrysalideTestCase): + """TestCase for glibext.GenericWork""" + + def testBasicWorkImplementation(self): + """Implement a basic work.""" + + class BasicWork(GenericWork): + def __init__(self, lst): + super(BasicWork, self).__init__() + self._lst = lst + def _run(self): + self._lst.append('done') + + test = [] + + work = BasicWork(test) + + work.process() + + self.assertEqual(len(test), 1) + self.assertEqual(test[0], 'done') diff --git a/tests/glibext/workqueue.py b/tests/glibext/workqueue.py new file mode 100644 index 0000000..203970b --- /dev/null +++ b/tests/glibext/workqueue.py @@ -0,0 +1,49 @@ + +from chrysacase import ChrysalideTestCase +from pychrysalide.glibext import GenericWork, WorkQueue +from threading import Lock + + +class TestWorks(ChrysalideTestCase): + """TestCase for glibext.*Work*""" + + def testBasicWorkQueueBehaviour(self): + """Check the default basic behaviour of a work queue.""" + + queue = WorkQueue() + + ret = queue.is_empty(123) + self.assertTrue(ret) + + + def testWorkScheduling(self): + """Check scheduled works results.""" + + class SchedulableWork(GenericWork): + def __init__(self, lck, val): + super(SchedulableWork, self).__init__() + self._lck = lck + self._val = val + def _run(self): + self._lck.acquire() + self._val['integer'] += 1 + self._lck.release() + + lock = Lock() + value = { 'integer': 0 } + + queue = WorkQueue() + + gid = queue.define_group(4) + + count = 31 + + for i in range(count): + + work = SchedulableWork(lock, value) + queue.schedule(work, gid) + + while not(queue.wait_for_completion(gid)): + pass + + self.assertEqual(value['integer'], count) |