From 65c9fe0baa579173afa5a2d463ac198d06ef4993 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 5 Jun 2010 16:07:19 +0200 Subject: A code donation: Donating a worker thread implementation inclduding tests to Git-Python. I have the feeling it can do much good here :) --- test/git/odb/test_thread.py | 47 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 test/git/odb/test_thread.py (limited to 'test/git/odb/test_thread.py') diff --git a/test/git/odb/test_thread.py b/test/git/odb/test_thread.py new file mode 100644 index 00000000..3b7f749b --- /dev/null +++ b/test/git/odb/test_thread.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +""" Test thead classes and functions""" +from test.testlib import * +from git.odb.thread import * +from Queue import Queue + +class TestWorker(WorkerThread): + def __init__(self, *args, **kwargs): + super(TestWorker, self).__init__(*args, **kwargs) + self.reset() + + def fun(self, *args, **kwargs): + self.called = True + self.args = args + self.kwargs = kwargs + return True + + def make_assertion(self): + assert self.called + assert self.args + assert self.kwargs + self.reset() + + def reset(self): + self.called = False + self.args = None + self.kwargs = None + + +class TestCase( TestCase ): + + @terminate_threads + def test_worker_thread(self): + worker = TestWorker() + assert isinstance(worker.start(), WorkerThread) + + # test different method types + standalone_func = lambda *args, **kwargs: worker.fun(*args, **kwargs) + for function in ("fun", TestWorker.fun, worker.fun, standalone_func): + rval = worker.call(function, 1, this='that') + assert isinstance(rval, Queue) + assert rval.get() is True + worker.make_assertion() + # END for each function type + + worker.call('quit') + -- cgit v1.2.1