From f1f606e1c5b559aa264518a89595afd787f12e8a Mon Sep 17 00:00:00 2001 From: Yuheng Long Date: Tue, 6 Aug 2013 14:47:12 -0700 Subject: Encapsulate a couple inner fields in a unittest. BUG=None TEST=unit testings for the pipeline stage, pipeline workers, generation, steering, task, flag and hill climbing. Change-Id: I5d86c107cb7a0693c97a0cb404c2a89a172ce835 Reviewed-on: https://gerrit-int.chromium.org/42418 Reviewed-by: Simon Que Tested-by: Yuheng Long Commit-Queue: Yuheng Long --- bestflags/pipeline_worker_test.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'bestflags/pipeline_worker_test.py') diff --git a/bestflags/pipeline_worker_test.py b/bestflags/pipeline_worker_test.py index 4ed6e350..8c8f315c 100644 --- a/bestflags/pipeline_worker_test.py +++ b/bestflags/pipeline_worker_test.py @@ -22,7 +22,7 @@ import pipeline_worker # Pick an integer at random. -TESTSTAGE = -3 +TEST_STAGE = -3 def MockTaskCostGenerator(): @@ -52,7 +52,7 @@ class PipelineWorkerTest(unittest.TestCase): # Set up the helper process that holds the helper method. helper_process = multiprocessing.Process(target=pipeline_worker.Helper, - args=(TESTSTAGE, {}, helper_queue, + args=(TEST_STAGE, {}, helper_queue, completed_queue, result_queue)) helper_process.start() @@ -72,7 +72,7 @@ class PipelineWorkerTest(unittest.TestCase): # Testing the correctness of having tasks having the same identifier, here # 1. for result in results: - helper_queue.put(MockTask(TESTSTAGE, result, MockTaskCostGenerator())) + helper_queue.put(MockTask(TEST_STAGE, result, MockTaskCostGenerator())) completed_queue.put((2, mock_result[2])) completed_queue.put((1, mock_result[1])) @@ -83,12 +83,11 @@ class PipelineWorkerTest(unittest.TestCase): while results: task = result_queue.get() - identifier = task._identifier - cost = task._cost + identifier = task.GetIdentifier(TEST_STAGE) self.assertTrue(identifier in results) if identifier in mock_result: - self.assertTrue(cost, mock_result[identifier]) - results.remove(task._identifier) + self.assertTrue(task.GetResult(TEST_STAGE), mock_result[identifier]) + results.remove(identifier) def testWorker(self): """"Test the worker method. @@ -107,11 +106,11 @@ class PipelineWorkerTest(unittest.TestCase): mock_tasks = [] for flag, cost in mock_work_tasks.iteritems(): - mock_tasks.append(MockTask(TESTSTAGE, flag, cost)) + mock_tasks.append(MockTask(TEST_STAGE, flag, cost)) # Submit the mock tasks to the worker. for mock_task in mock_tasks: - pipeline_worker.Worker(TESTSTAGE, mock_task, completed_queue, + pipeline_worker.Worker(TEST_STAGE, mock_task, completed_queue, result_queue) # The tasks, from the output queue, should be the same as the input and @@ -119,7 +118,7 @@ class PipelineWorkerTest(unittest.TestCase): for task in mock_tasks: output = result_queue.get() self.assertEqual(output, task) - self.assertTrue(output.Done(TESTSTAGE)) + self.assertTrue(output.Done(TEST_STAGE)) # The tasks, from the completed_queue, should be defined in the # mock_work_tasks dictionary. -- cgit v1.2.3