def test_jobs(): print() setup_logging() init_test_jobs() test_jobs = JobDescriptor.get_test_jobs(ontology.DOCUMENT_SUMMARIZER_ID) for job in test_jobs: service_id = 0 if str(job) != "NO_JOB": service_id = ontology.DOCUMENT_SUMMARIZER_ID job_parameters = { 'input_type': 'file', 'input_url': 'http://test.com/inputs/test_input.txt', 'output_type': 'file_url_put', 'output_url': 'test_output.txt' } job_parameters_2 = { 'input_type': 'file', 'input_url': 'http://test.com/inputs/test_input.txt', 'output_type': 'file_url_put', 'output_url': 'test_output.txt' } service_id = ontology.DOCUMENT_SUMMARIZER_ID # Create a new job descriptor with four sets of parameters. job_list = [ job_parameters, job_parameters, job_parameters, job_parameters ] new_job = JobDescriptor(ServiceDescriptor(service_id), job_list) file_count = 0 for job_item in new_job: if job_item['input_type'] == 'file': file_count += 1 else: file_count = 0 assert (file_count == 4) # Cover and test iteration and list item retrieval and length. new_job[0] = job_parameters_2 assert (new_job[0] == job_parameters_2) job_count = len(new_job) del new_job[1] assert (len(new_job) == job_count - 1) # Test equality and string conversion functions. last_job = new_job assert (last_job == new_job) assert (str(last_job) == str(new_job)) test_jobs.append(new_job) total_jobs = len(test_jobs) test_jobs[0] = new_job del test_jobs[total_jobs - 1] # Check the string conversion with no ServiceDescriptor... new_job = JobDescriptor(None, [job_parameters]) assert (str(new_job) != "")
def test_perform_services(app): print() setup_logging() init_test_jobs() setup_service_manager(app) # The test jobs specify output URLs for files in an "output" directory inside the "tests" directory. print("current directory is ", os.getcwd()) print("test directory is ", TEST_DIR) output_directory = os.path.join(TEST_DIR, "output") print("output directory is ", output_directory) if not os.path.exists(output_directory): os.mkdir(output_directory) # Excercise the service manager methods. assert (not app['service_manager'] is None) service_manager = app['service_manager'] perform_one_service(app, service_manager, ontology.DOCUMENT_SUMMARIZER_ID) perform_one_service(app, service_manager, ontology.ENTITY_EXTRACTER_ID) perform_one_service(app, service_manager, ontology.FACE_RECOGNIZER_ID) perform_one_service(app, service_manager, ontology.TEXT_SUMMARIZER_ID) perform_one_service(app, service_manager, ontology.VIDEO_SUMMARIZER_ID) perform_one_service(app, service_manager, ontology.WORD_SENSE_DISAMBIGUATER_ID) start_stop_start_one_service(app, service_manager, ontology.DOCUMENT_SUMMARIZER_ID) start_stop_start_one_service(app, service_manager, ontology.ENTITY_EXTRACTER_ID) start_stop_start_one_service(app, service_manager, ontology.FACE_RECOGNIZER_ID) start_stop_start_one_service(app, service_manager, ontology.TEXT_SUMMARIZER_ID) start_stop_start_one_service(app, service_manager, ontology.VIDEO_SUMMARIZER_ID) start_stop_start_one_service(app, service_manager, ontology.WORD_SENSE_DISAMBIGUATER_ID)
def test_perform_services(app): # The test jobs specify output URLs for files in an "output" directory inside the "tests" directory. print("current directory is ", os.getcwd()) print("test directory is ", TEST_DIRECTORY) output_directory = os.path.join(TEST_DIRECTORY, "output") print("output directory is ", output_directory) if not os.path.exists(output_directory): os.mkdir(output_directory) def remap_file_url(output_url: str): file_name = output_url.split("/")[-1] file_url = os.path.join(output_directory, file_name) return file_url def perform_one_service(app, service_manager, service_id): log.debug(" test_one_service") service_adapter = service_manager.get_service_adapter_for_id( service_id) test_jobs = JobDescriptor.get_test_jobs(service_id) # Remap the job item output URLs to the output directory. for job in test_jobs: for job_item in job: output_type = job_item['output_type'] if output_type == 'file_url_put': job_item['output_url'] = remap_file_url( job_item['output_url']) else: raise RuntimeError("Bad output type %s for job %s" % (output_type, self)) log.debug(" Testing jobs") job = None try: exception_caught = False for job in test_jobs: log.debug(" testing job %s", job) service_adapter.perform(job) except RuntimeError as exception: exception_caught = True log.error(" Exception caught %s", exception) log.debug(" Error performing %s %s", job, service_adapter) assert not exception_caught def start_stop_start_one_service(app, service_manager, service_id): log.debug(" start_stop_start_one_service") service_adapter = service_manager.get_service_adapter_for_id( service_id) try: exception_caught = False service_adapter.start() service_adapter.stop() service_adapter.start() except RuntimeError as exception: exception_caught = True log.error(" Exception caught %s", exception) log.debug(" Error starting or stopping %s", service_adapter) assert not exception_caught print() setup_logging() init_test_jobs() setup_service_manager(app) # Excercise the service manager methods. assert (not app['service_manager'] is None) service_manager = app['service_manager'] perform_one_service(app, service_manager, onto.DOCUMENT_SUMMARIZER_ID) perform_one_service(app, service_manager, onto.ENTITY_EXTRACTER_ID) perform_one_service(app, service_manager, onto.FACE_RECOGNIZER_ID) perform_one_service(app, service_manager, onto.TEXT_SUMMARIZER_ID) perform_one_service(app, service_manager, onto.VIDEO_SUMMARIZER_ID) perform_one_service(app, service_manager, onto.WORD_SENSE_DISAMBIGUATER_ID) start_stop_start_one_service(app, service_manager, onto.DOCUMENT_SUMMARIZER_ID) start_stop_start_one_service(app, service_manager, onto.ENTITY_EXTRACTER_ID) start_stop_start_one_service(app, service_manager, onto.FACE_RECOGNIZER_ID) start_stop_start_one_service(app, service_manager, onto.TEXT_SUMMARIZER_ID) start_stop_start_one_service(app, service_manager, onto.VIDEO_SUMMARIZER_ID) start_stop_start_one_service(app, service_manager, onto.WORD_SENSE_DISAMBIGUATER_ID)