Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sils committed May 16, 2015
1 parent e15a93e commit ed42c64
Showing 1 changed file with 14 additions and 39 deletions.
53 changes: 14 additions & 39 deletions coalib/tests/processes/SectionExecutorTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,6 @@ def begin_section(self, name):
self.set_up = True


class RunningProcessSimulatingQueue(queue.Queue):
def __init__(self):
queue.Queue.__init__(self)
self.length = 0

def __len__(self):
return self.length + 1

def put(self, item, block=False, timeout=None):
self.length += 1
queue.Queue.put(self, item, block, timeout)

def get(self, block=False, timeout=None):
retval = queue.Queue.get(self, block, timeout)
self.length -= 1
return retval


class RunningProcessSimulatingSectionExecutor(SectionExecutor):
def __init__(self,
section,
Expand All @@ -67,24 +49,19 @@ def __init__(self,
log_printer)

def process_queues(self,
processes,
control_queue,
local_result_dict,
global_result_dict,
file_dict):

# This test class is only intended to work with the custom
# RunningProcessSimulatingQueue.
assert isinstance(control_queue, RunningProcessSimulatingQueue)
self.ctrlq = control_queue
self._process_queues(processes,
global_result_dict):
# Pass control_queue as processes
self._process_queues(control_queue,
control_queue,
local_result_dict,
global_result_dict,
file_dict)
None)

def _get_running_processes(self, processes):
return len(self.ctrlq)
@staticmethod
def _get_running_processes(processes):
return 0 if processes.empty() else 2


class MessageQueueingInteractor(Interactor):
Expand Down Expand Up @@ -227,7 +204,7 @@ def test_process_queues(self):
self.global_bears["default"],
mock_interactor,
mock_interactor)
ctrlq = RunningProcessSimulatingQueue()
ctrlq = queue.Queue()

# Append custom controlling sequences.
ctrlq.put((CONTROL_ELEMENT.LOCAL, 1))
Expand All @@ -236,16 +213,14 @@ def test_process_queues(self):
ctrlq.put((CONTROL_ELEMENT.LOCAL_FINISHED, None))
ctrlq.put((CONTROL_ELEMENT.GLOBAL_FINISHED, None))

uut.process_queues(None,
ctrlq,
{1: "The first result.", 2: "The second result"},
{1: "The one and only global result"},
None)
uut.process_queues(ctrlq,
{1: "The first result.", 2: "The second result."},
{1: "The one and only global result."})

self.assertEqual(mock_interactor.get(), "The first result.")
self.assertEqual(mock_interactor.get(), "The second result.")
self.assertEqual(mock_interactor.get(), ("The first result.", None))
self.assertEqual(mock_interactor.get(), ("The second result.", None))
self.assertEqual(mock_interactor.get(),
"The one and only global result.")
("The one and only global result.", None))


if __name__ == '__main__':
Expand Down

0 comments on commit ed42c64

Please sign in to comment.