summaryrefslogtreecommitdiff
path: root/test/git/async/test_thread.py
blob: ca306cc0dc439e35ce145ccfe29ed4c4b3c21a48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# -*- coding: utf-8 -*-
""" Test thead classes and functions"""
from test.testlib import *
from git.async.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 TestThreads( 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')