def test_03_02_pipeline_preferences(self): # # Walk the worker up through pipelines and preferences. # self.awthread = self.AWThread(self.announce_addr) self.awthread.start() self.set_work_socket() self.awthread.ex(self.awthread.aw.do_job, cpanalysis.WorkReply( image_set_numbers = [1], worker_runs_post_group = False, wants_dictionary = True)) # # The worker should ask for the pipeline and preferences next. # req = self.awthread.recv(self.work_socket) self.assertIsInstance(req, cpanalysis.PipelinePreferencesRequest) self.assertEqual(req.analysis_id, self.analysis_id) maybe_download_example_image(["ExampleSBSImages"], "Channel1-01-A-01.tif") maybe_download_example_image(["ExampleHT29"], "AS_09125_050116030001_D03f00d0.tif") input_dir = os.path.normcase( os.path.join(example_images_directory(), "ExampleSBSImages")) output_dir = os.path.normcase( os.path.join(example_images_directory(), "ExampleHT29")) cpprefs.set_default_image_directory(input_dir) input_dir = cpprefs.get_default_image_directory() cpprefs.set_default_output_directory(output_dir) output_dir = cpprefs.get_default_output_directory() preferences = {cpprefs.DEFAULT_IMAGE_DIRECTORY: cpprefs.config_read(cpprefs.DEFAULT_IMAGE_DIRECTORY), cpprefs.DEFAULT_OUTPUT_DIRECTORY: cpprefs.config_read(cpprefs.DEFAULT_OUTPUT_DIRECTORY)} cpprefs.set_default_image_directory(example_images_directory()) cpprefs.set_default_output_directory(example_images_directory()) rep = cpanalysis.Reply( pipeline_blob = np.array(GOOD_PIPELINE), preferences = preferences) req.reply(rep) # # Get the next request so that we know the worker has # processed the preferences. # req = self.awthread.recv(self.work_socket) self.assertEqual(cpprefs.get_default_image_directory(), input_dir) self.assertEqual(cpprefs.get_default_output_directory(), output_dir) self.assertIn(self.analysis_id, self.awthread.aw.pipelines_and_preferences) pipe, prefs = self.awthread.aw.pipelines_and_preferences[ self.analysis_id] self.assertEqual(len(pipe.modules()), 7) # # Cancel and check for exit # req.reply(cpanalysis.ServerExited()) self.assertRaises(cpp.CancelledException, self.awthread.ecute)
def test_03_03_initial_measurements(self): # # Walk to the initial measurements # self.awthread = self.AWThread(self.announce_addr) self.awthread.start() self.set_work_socket() self.awthread.ex( self.awthread.aw.do_job, cpanalysis.WorkReply(image_set_numbers=[1], worker_runs_post_group=False, wants_dictionary=True)) # # The worker should ask for the pipeline and preferences next. # req = self.awthread.recv(self.work_socket) self.assertIsInstance(req, cpanalysis.PipelinePreferencesRequest) self.assertEqual(req.analysis_id, self.analysis_id) input_dir = os.path.join(example_images_directory(), "ExampleSBSImages") cpprefs.set_default_image_directory(input_dir) preferences = { cpprefs.DEFAULT_IMAGE_DIRECTORY: cpprefs.config_read(cpprefs.DEFAULT_IMAGE_DIRECTORY) } rep = cpanalysis.Reply(pipeline_blob=np.array(GOOD_PIPELINE), preferences=preferences) req.reply(rep) # # The worker asks for the initial measurements. # req = self.awthread.recv(self.work_socket) self.assertIsInstance(req, cpanalysis.InitialMeasurementsRequest) self.assertEqual(req.analysis_id, self.analysis_id) m = get_measurements_for_good_pipeline() try: req.reply(cpanalysis.Reply(buf=m.file_contents())) req = self.awthread.recv(self.work_socket) # # Check that they were installed # self.assertIn(self.analysis_id, self.awthread.aw.initial_measurements) cm = self.awthread.aw.initial_measurements[self.analysis_id] for object_name in m.get_object_names(): for feature_name in m.get_feature_names(object_name): self.assertTrue(cm.has_feature(object_name, feature_name)) self.assertEqual(cm[object_name, feature_name, 1], m[object_name, feature_name, 1]) # # Cancel and check for exit # req.reply(cpanalysis.ServerExited()) self.assertRaises(cpaw.CancelledException, self.awthread.ecute) finally: m.close()
def test_02_03_send_upstream_exit(self): self.awthread = self.AWThread(self.announce_addr) self.awthread.start() self.set_work_socket() def send_something(): reply = self.awthread.aw.send(cpanalysis.WorkRequest("foo")) return reply self.awthread.ex(send_something) req = self.awthread.recv(self.work_socket) req.reply(cpanalysis.ServerExited()) self.assertRaises(cpp.CancelledException, self.awthread.ecute)