def setUp(self): events.unsub_all() parser = AstromParser() directory_manager = LocalDirectoryWorkingContext( self._get_working_dir()) self.context = directory_manager progress_manager = LocalProgressManager(directory_manager) workunit_provider = WorkUnitProvider( tasks.get_suffix(self._get_task()), directory_manager, progress_manager, self._get_workunit_builder(parser, progress_manager)) self.workunit_provider = workunit_provider self.progress_manager = progress_manager self.singlet_download_manager = Mock(spec=AsynchronousDownloadManager) self.triplet_download_manager = Mock(spec=AsynchronousDownloadManager) self.image_manager = ImageManager(self.singlet_download_manager, self.triplet_download_manager) self.model = ValidationModel(self.workunit_provider, self.image_manager, None) self.custom_setup() self.model.start_work()
def setUp(self): self.taskid = "id" self.file1 = "file1" self.file2 = "file2" self.file3 = "file3" self.file4 = "file4" self.test_files = [self.file1, self.file2] directory_manager = TestDirectoryManager() progress_manager = InMemoryProgressManager(directory_manager) builder = TestWorkUnitBuilder() self.undertest = WorkUnitProvider(self.taskid, directory_manager, progress_manager, builder) self.directory_manager = directory_manager self.progress_manager = progress_manager self.directory_manager.set_listing(self.taskid, self.test_files)
def setUp(self): working_directory = self.get_directory_to_clean() context = LocalDirectoryWorkingContext(working_directory) progress_manager = InMemoryProgressManager(context) parser = AstromParser() builder = RealsWorkUnitBuilder(parser, context, context, progress_manager) undertest = WorkUnitProvider(tasks.get_suffix(tasks.REALS_TASK), context, progress_manager, builder) self.progress_manager = progress_manager self.undertest = undertest
def setUp(self): WxWidgetTestCase.setUp(self) parser = AstromParser() context = LocalDirectoryWorkingContext( self.get_abs_path("data/controller_testdir")) progress_manager = LocalProgressManager(context) workunit_provider = WorkUnitProvider(tasks.get_suffix(tasks.REALS_TASK), context, progress_manager, RealsWorkUnitBuilder( parser, context, context, progress_manager)) image_manager = Mock(spec=ImageManager) self.model = ValidationModel(workunit_provider, image_manager, None) self.model.start_work() self.model.get_writer = Mock(return_value=Mock(spec=mpc.MPCWriter)) # We don't actually have any images loaded, so mock this out source_cutout = Mock(spec=SourceCutout) source_cutout.pixel_x = 11 source_cutout.pixel_y = 50 self.model.get_current_cutout = Mock(return_value=source_cutout) x_cen = 10 y_cen = 50 mag = 24.0 self.model.get_current_source_observed_magnitude = Mock(return_value=(x_cen, y_cen, mag)) self.model.is_current_source_adjusted = Mock(return_value=False) self.model.get_current_fits_header = Mock() self.name_generator = Mock(spec=ProvisionalNameGenerator) self.name_generator.generate_name.return_value = TEST_PROVISIONAL_NAME class TestFactory(object): def __init__(self, model, name_generator): self.model = model self.name_generator = name_generator def create_controller(self, view): return ProcessRealsController(self.model, view, self.name_generator) self.view = ApplicationView( TestFactory(self.model, self.name_generator)) self.controller = self.view.controller self.controller.display_current_image = Mock()
class WorkUnitProviderTest(unittest.TestCase): def setUp(self): self.taskid = "id" self.file1 = "file1" self.file2 = "file2" self.file3 = "file3" self.file4 = "file4" self.test_files = [self.file1, self.file2] directory_manager = TestDirectoryManager() progress_manager = InMemoryProgressManager(directory_manager) builder = TestWorkUnitBuilder() self.undertest = WorkUnitProvider(self.taskid, directory_manager, progress_manager, builder) self.directory_manager = directory_manager self.progress_manager = progress_manager self.directory_manager.set_listing(self.taskid, self.test_files) def test_create_workload_acquires_lock(self): self.directory_manager.set_listing(self.taskid, self.test_files) workunit1 = self.undertest.get_workunit() assert_that(self.progress_manager.owns_lock(workunit1.get_filename()), equal_to(True)) def test_create_workload_fresh_directory(self): workunit1 = self.undertest.get_workunit() assert_that(workunit1.get_filename(), is_in(self.test_files)) self.progress_manager.record_done(workunit1.get_filename()) workunit2 = self.undertest.get_workunit() assert_that(workunit2.get_filename(), is_in(self.test_files)) assert_that(workunit2.get_filename(), is_not(equal_to(workunit1.get_filename()))) self.progress_manager.record_done(workunit2.get_filename()) self.assertRaises(NoAvailableWorkException, self.undertest.get_workunit) def test_create_workload_one_file_already_done(self): self.progress_manager.done.add(self.file1) workunit = self.undertest.get_workunit() assert_that(workunit.get_filename(), equal_to(self.file2)) self.progress_manager.record_done(self.file2) self.assertRaises(NoAvailableWorkException, self.undertest.get_workunit) def test_create_workload_locked_files(self): self.progress_manager.add_external_lock(self.file2) workunit = self.undertest.get_workunit() assert_that(workunit.get_filename(), equal_to(self.file1)) self.progress_manager.record_done(self.file1) self.assertRaises(NoAvailableWorkException, self.undertest.get_workunit) def test_items_in_ignore_list_ignored(self): workunit = self.undertest.get_workunit(ignore_list=[self.file1]) assert_that(workunit.get_filename(), equal_to(self.file2)) self.progress_manager.record_done(self.file2) self.assertRaises(NoAvailableWorkException, self.undertest.get_workunit, ignore_list=[self.file1]) def test_file_found_to_be_done_not_checked_again(self): test_files = [self.file1, self.file2, self.file3, self.file4] self.directory_manager.set_listing(self.taskid, test_files) self.progress_manager.lock(self.file2) self.progress_manager.record_done(self.file2) self.progress_manager.unlock(self.file2) # We don't yet know file1 is done. assert_that( self.undertest.get_potential_files([]), contains_inanyorder(self.file1, self.file2, self.file3, self.file4)) assert_that(self.undertest.get_workunit().get_filename(), equal_to(self.file1)) # We have not yet discovered file2 is done because we found file 1 # right away. However, we should remember we already returned file1. assert_that(self.undertest.get_potential_files([]), contains_inanyorder(self.file2, self.file3, self.file4)) # Here we should discover file2 is done and skip over it assert_that(self.undertest.get_workunit().get_filename(), equal_to(self.file3)) # So the next time we know not to check file2 again assert_that(self.undertest.get_potential_files([]), contains_inanyorder(self.file4))
def __init__(self, working_directory, output_directory, dry_run=False, debug=False, name_filter=None, user_id=None): self.dry_run = dry_run self.user_id = user_id logger.info("Input directory set to: %s" % working_directory) logger.info("Output directory set to: %s" % output_directory) working_context = context.get_context(working_directory, userid=self.user_id) output_context = context.get_context(output_directory, userid=self.user_id) if dry_run and working_context.is_remote(): sys.stdout.write("A dry run can only be done on local files.\n") sys.exit(0) if output_context.is_remote(): sys.stdout.write("The output directory must be local.\n") sys.exit(0) image_manager = self._create_image_manager() progress_manager = working_context.get_progress_manager() builder = self._create_workunit_builder(working_context, output_context, progress_manager) workunit_provider = WorkUnitProvider( self.input_suffix, working_context, progress_manager, builder, randomize=self.should_randomize_workunits, name_filter=name_filter) prefetching_workunit_provider = PreFetchingWorkUnitProvider( workunit_provider, config.read("PREFETCH.NUMBER"), image_manager) if working_context.is_remote(): synchronization_manager = SynchronizationManager(working_context, sync_enabled=True) else: synchronization_manager = None model = TransAckValidationModel(prefetching_workunit_provider, image_manager, synchronization_manager) logger.debug("Created model.") view = self._create_view(model, debug=debug) logger.debug("Created view.") model.start_work() self.model = model self.view = view self.controller = view.controller self.controller.display_current_image() if not synchronization_manager: self.view.disable_sync_menu() self.view.show()
class WorkUnitProviderTest(unittest.TestCase): def setUp(self): self.taskid = "id" self.file1 = "file1" self.file2 = "file2" self.file3 = "file3" self.file4 = "file4" self.test_files = [self.file1, self.file2] directory_manager = TestDirectoryManager() progress_manager = InMemoryProgressManager(directory_manager) builder = TestWorkUnitBuilder() self.undertest = WorkUnitProvider(self.taskid, directory_manager, progress_manager, builder) self.directory_manager = directory_manager self.progress_manager = progress_manager self.directory_manager.set_listing(self.taskid, self.test_files) def test_create_workload_acquires_lock(self): self.directory_manager.set_listing(self.taskid, self.test_files) workunit1 = self.undertest.get_workunit() assert_that(self.progress_manager.owns_lock(workunit1.get_filename()), equal_to(True)) def test_create_workload_fresh_directory(self): workunit1 = self.undertest.get_workunit() assert_that(workunit1.get_filename(), is_in(self.test_files)) self.progress_manager.record_done(workunit1.get_filename()) workunit2 = self.undertest.get_workunit() assert_that(workunit2.get_filename(), is_in(self.test_files)) assert_that(workunit2.get_filename(), is_not(equal_to(workunit1.get_filename()))) self.progress_manager.record_done(workunit2.get_filename()) self.assertRaises(NoAvailableWorkException, self.undertest.get_workunit) def test_create_workload_one_file_already_done(self): self.progress_manager.done.add(self.file1) workunit = self.undertest.get_workunit() assert_that(workunit.get_filename(), equal_to(self.file2)) self.progress_manager.record_done(self.file2) self.assertRaises(NoAvailableWorkException, self.undertest.get_workunit) def test_create_workload_locked_files(self): self.progress_manager.add_external_lock(self.file2) workunit = self.undertest.get_workunit() assert_that(workunit.get_filename(), equal_to(self.file1)) self.progress_manager.record_done(self.file1) self.assertRaises(NoAvailableWorkException, self.undertest.get_workunit) def test_items_in_ignore_list_ignored(self): workunit = self.undertest.get_workunit(ignore_list=[self.file1]) assert_that(workunit.get_filename(), equal_to(self.file2)) self.progress_manager.record_done(self.file2) self.assertRaises(NoAvailableWorkException, self.undertest.get_workunit, ignore_list=[self.file1]) def test_file_found_to_be_done_not_checked_again(self): test_files = [self.file1, self.file2, self.file3, self.file4] self.directory_manager.set_listing(self.taskid, test_files) self.progress_manager.lock(self.file2) self.progress_manager.record_done(self.file2) self.progress_manager.unlock(self.file2) # We don't yet know file1 is done. assert_that(self.undertest.get_potential_files([]), contains_inanyorder(self.file1, self.file2, self.file3, self.file4)) assert_that(self.undertest.get_workunit().get_filename(), equal_to(self.file1)) # We have not yet discovered file2 is done because we found file 1 # right away. However, we should remember we already returned file1. assert_that(self.undertest.get_potential_files([]), contains_inanyorder(self.file2, self.file3, self.file4)) # Here we should discover file2 is done and skip over it assert_that(self.undertest.get_workunit().get_filename(), equal_to(self.file3)) # So the next time we know not to check file2 again assert_that(self.undertest.get_potential_files([]), contains_inanyorder(self.file4))