def run_job_and_check_output(self, expected_output, sort=False, literal_eval=False):
    'Helper function to run job and compare output.'
    job_id = self.job_class.create_new()
    self.assertEqual(self.count_jobs_in_taskqueue(taskqueue_services.QUEUE_NAME_ONE_OFF_JOBS), 0)
    self.job_class.enqueue(job_id)
    self.assertEqual(self.count_jobs_in_taskqueue(taskqueue_services.QUEUE_NAME_ONE_OFF_JOBS), 1)
    self.process_and_flush_pending_tasks()
    actual_output = self.job_class.get_output(job_id)
    if literal_eval:
        actual_output_dict = {}
        expected_output_dict = {}
        for item in [ast.literal_eval(value) for value in actual_output]:
            value = item[1]
            if isinstance(value, list):
                value = sorted(value)
            actual_output_dict[item[0]] = value
        for item in [ast.literal_eval(value) for value in expected_output]:
            value = item[1]
            if isinstance(value, list):
                value = sorted(value)
            expected_output_dict[item[0]] = value
        self.assertEqual(sorted(actual_output_dict.keys()), sorted(expected_output_dict.keys()))
        for key in actual_output_dict:
            self.assertEqual(actual_output_dict[key], expected_output_dict[key])
    elif sort:
        self.assertEqual(sorted(actual_output), sorted(expected_output))
    else:
        self.assertEqual(actual_output, expected_output)
Helper function to run job and compare output.
def run_job_and_check_output(self, expected_output, sort=False, literal_eval=False):
    
    job_id = self.job_class.create_new()
    self.assertEqual(self.count_jobs_in_taskqueue(taskqueue_services.QUEUE_NAME_ONE_OFF_JOBS), 0)
    self.job_class.enqueue(job_id)
    self.assertEqual(self.count_jobs_in_taskqueue(taskqueue_services.QUEUE_NAME_ONE_OFF_JOBS), 1)
    self.process_and_flush_pending_tasks()
    actual_output = self.job_class.get_output(job_id)
    if literal_eval:
        actual_output_dict = {}
        expected_output_dict = {}
        for item in [ast.literal_eval(value) for value in actual_output]:
            value = item[1]
            if isinstance(value, list):
                value = sorted(value)
            actual_output_dict[item[0]] = value
        for item in [ast.literal_eval(value) for value in expected_output]:
            value = item[1]
            if isinstance(value, list):
                value = sorted(value)
            expected_output_dict[item[0]] = value
        self.assertEqual(sorted(actual_output_dict.keys()), sorted(expected_output_dict.keys()))
        for key in actual_output_dict:
            self.assertEqual(actual_output_dict[key], expected_output_dict[key])
    elif sort:
        self.assertEqual(sorted(actual_output), sorted(expected_output))
    else:
        self.assertEqual(actual_output, expected_output)