Ejemplo n.º 1
0
    def test_loading_images(self):
        observer = Mock()
        events.subscribe(events.IMG_LOADED, observer.on_img_loaded)
        loaded_reading1 = Mock()
        image1 = Mock()
        loaded_reading2 = Mock()
        image2 = Mock()

        assert_that(self.download_manager.start_downloading_workunit.call_count,
                    equal_to(1))
        assert_that(self.model.get_loaded_image_count(), equal_to(0))

        # Simulate receiving callback
        self.model._on_image_loaded(loaded_reading1, image1)
        assert_that(self.model.get_loaded_image_count(), equal_to(1))
        assert_that(observer.on_img_loaded.call_count, equal_to(1))

        # Simulate receiving callback
        self.model._on_image_loaded(loaded_reading2, image2)
        assert_that(self.model.get_loaded_image_count(), equal_to(2))
        assert_that(observer.on_img_loaded.call_count, equal_to(2))

        # Check event args
        call_args_list = observer.on_img_loaded.call_args_list
        assert_that(call_args_list, has_length(2))

        msg0 = call_args_list[0][0][0]
        assert_that(msg0.topic, equal_to(events.IMG_LOADED))
        assert_that(msg0.data, equal_to(loaded_reading1))

        msg1 = call_args_list[1][0][0]
        assert_that(msg1.topic, equal_to(events.IMG_LOADED))
        assert_that(msg1.data, equal_to(loaded_reading2))
Ejemplo n.º 2
0
    def test_loading_images(self):
        observer = Mock()
        events.subscribe(events.IMG_LOADED, observer.on_img_loaded)
        image1 = Mock()
        loaded_reading1 = image1.reading
        image2 = Mock()
        loaded_reading2 = image2.reading

        assert_that(
            self.image_manager._singlet_download_manager.submit_request.
            call_count, equal_to(9))

        # Simulate receiving callback
        self.image_manager.on_singlet_image_loaded(image1)
        assert_that(observer.on_img_loaded.call_count, equal_to(1))

        # Simulate receiving callback
        self.image_manager.on_singlet_image_loaded(image2)
        assert_that(observer.on_img_loaded.call_count, equal_to(2))

        # Check event args
        call_args_list = observer.on_img_loaded.call_args_list
        assert_that(call_args_list, has_length(2))

        msg0 = call_args_list[0][0][0]
        assert_that(msg0.topic, equal_to(events.IMG_LOADED))
        assert_that(msg0.data, equal_to(loaded_reading1))

        msg1 = call_args_list[1][0][0]
        assert_that(msg1.topic, equal_to(events.IMG_LOADED))
        assert_that(msg1.data, equal_to(loaded_reading2))
Ejemplo n.º 3
0
    def test_loading_images(self):
        observer = Mock()
        events.subscribe(events.IMG_LOADED, observer.on_img_loaded)
        image1 = Mock()
        loaded_reading1 = image1.reading
        image2 = Mock()
        loaded_reading2 = image2.reading

        assert_that(
            self.image_manager._singlet_download_manager.submit_request.call_count,
            equal_to(9))

        # Simulate receiving callback
        self.image_manager.on_singlet_image_loaded(image1)
        assert_that(observer.on_img_loaded.call_count, equal_to(1))

        # Simulate receiving callback
        self.image_manager.on_singlet_image_loaded(image2)
        assert_that(observer.on_img_loaded.call_count, equal_to(2))

        # Check event args
        call_args_list = observer.on_img_loaded.call_args_list
        assert_that(call_args_list, has_length(2))

        msg0 = call_args_list[0][0][0]
        assert_that(msg0.topic, equal_to(events.IMG_LOADED))
        assert_that(msg0.data, equal_to(loaded_reading1))

        msg1 = call_args_list[1][0][0]
        assert_that(msg1.topic, equal_to(events.IMG_LOADED))
        assert_that(msg1.data, equal_to(loaded_reading2))
Ejemplo n.º 4
0
    def test_loading_images(self):
        observer = Mock()
        events.subscribe(events.IMG_LOADED, observer.on_img_loaded)
        loaded_reading1 = Mock()
        image1 = Mock()
        loaded_reading2 = Mock()
        image2 = Mock()

        assert_that(
            self.download_manager.start_downloading_workunit.call_count,
            equal_to(1))
        assert_that(self.model.get_loaded_image_count(), equal_to(0))

        # Simulate receiving callback
        self.model._on_image_loaded(loaded_reading1, image1)
        assert_that(self.model.get_loaded_image_count(), equal_to(1))
        assert_that(observer.on_img_loaded.call_count, equal_to(1))

        # Simulate receiving callback
        self.model._on_image_loaded(loaded_reading2, image2)
        assert_that(self.model.get_loaded_image_count(), equal_to(2))
        assert_that(observer.on_img_loaded.call_count, equal_to(2))

        # Check event args
        call_args_list = observer.on_img_loaded.call_args_list
        assert_that(call_args_list, has_length(2))

        msg0 = call_args_list[0][0][0]
        assert_that(msg0.topic, equal_to(events.IMG_LOADED))
        assert_that(msg0.data, equal_to(loaded_reading1))

        msg1 = call_args_list[1][0][0]
        assert_that(msg1.topic, equal_to(events.IMG_LOADED))
        assert_that(msg1.data, equal_to(loaded_reading2))
Ejemplo n.º 5
0
    def test_receive_next_obs_event(self):
        # Subscribe a mock
        observer = Mock()
        events.subscribe(events.CHANGE_IMAGE, observer.on_change_img)

        # Perform action
        self.model.next_obs()

        # Make sure event triggered
        observer.on_change_img.assert_called_once()
Ejemplo n.º 6
0
    def test_receive_next_obs_event(self):
        # Subscribe a mock
        observer = Mock()
        events.subscribe(events.CHANGE_IMAGE, observer.on_change_img)

        # Perform action
        self.model.next_obs()

        # Make sure event triggered
        observer.on_change_img.assert_called_once()
Ejemplo n.º 7
0
    def test_receive_nav_event_next_and_prev_source(self):
        # Subscribe a mock
        observer = Mock()
        events.subscribe(events.CHANGE_IMAGE, observer.on_nav)

        # Perform actions
        self.model.next_obs()
        self.model.previous_obs()

        # Make sure event triggered
        assert_that(observer.on_nav.call_count, equal_to(2))
Ejemplo n.º 8
0
    def test_receive_nav_event_next_and_prev_source(self):
        # Subscribe a mock
        observer = Mock()
        events.subscribe(events.CHANGE_IMAGE, observer.on_nav)

        # Perform actions
        self.model.next_obs()
        self.model.previous_obs()

        # Make sure event triggered
        assert_that(observer.on_nav.call_count, equal_to(2))
Ejemplo n.º 9
0
    def _create_data_notebook(self):
        notebook = wx.Notebook(self.control_panel)

        reading_data_panel = KeyValueListPanel(notebook, self.model.get_reading_data)
        events.subscribe(events.CHANGE_IMAGE, reading_data_panel.on_change_data)

        obs_header_panel = KeyValueListPanel(notebook, self.model.get_header_data_list)
        events.subscribe(events.CHANGE_IMAGE, obs_header_panel.on_change_data)

        notebook.AddPage(reading_data_panel, "Readings")
        notebook.AddPage(obs_header_panel, "Observation Header")

        return notebook
Ejemplo n.º 10
0
    def test_kvlist_display_data_on_change_reading(self):
        events.subscribe(events.CHANGE_IMAGE, self.view.on_change_data)

        # XXX have to manually update model return value here
        self.model.get_reading_data.return_value = self.dataset2

        self.model.next_source()

        assert_that(self.view.list.GetColumnCount(), equal_to(2))
        assert_that(self.view.list.GetItemCount(), equal_to(2))

        # TODO create custom matcher?
        for item_ind in range(self.view.list.GetItemCount()):
            for col_ind in range(self.view.list.GetColumnCount()):
                assert_that(self.view.list.GetItem(item_ind, col_ind).GetText(),
                            equal_to(self.dataset2[item_ind][col_ind]))
Ejemplo n.º 11
0
    def test_receive_all_sources_processed_event_on_final_reject(self):
        observer = Mock()
        events.subscribe(events.NO_AVAILABLE_WORK, observer.on_all_processed)

        total_items = 3
        item = 0
        while item < total_items - 1:
            self.model.accept_current_item()
            assert_that(observer.on_all_processed.call_count, equal_to(0))
            self.model.next_item()
            item += 1

        self.model.reject_current_item()

        # we try to get the next work unit, and find there is none
        self.model.next_item()
        assert_that(observer.on_all_processed.call_count, equal_to(1))
Ejemplo n.º 12
0
    def test_receive_all_sources_processed_event_on_final_reject(self):
        observer = Mock()
        events.subscribe(events.NO_AVAILABLE_WORK, observer.on_all_processed)

        total_items = 3
        item = 0
        while item < total_items - 1:
            self.model.accept_current_item()
            assert_that(observer.on_all_processed.call_count, equal_to(0))
            self.model.next_item()
            item += 1

        self.model.reject_current_item()

        # we try to get the next work unit, and find there is none
        self.model.next_item()
        assert_that(observer.on_all_processed.call_count, equal_to(1))
Ejemplo n.º 13
0
    def test_kvlist_display_data_on_change_reading(self):
        events.subscribe(events.CHANGE_IMAGE, self.view.on_change_data)

        # XXX have to manually update model return value here
        self.model.get_reading_data.return_value = self.dataset2

        self.model.next_source()

        assert_that(self.view.list.GetColumnCount(), equal_to(2))
        assert_that(self.view.list.GetItemCount(), equal_to(2))

        # TODO create custom matcher?
        for item_ind in range(self.view.list.GetItemCount()):
            for col_ind in range(self.view.list.GetColumnCount()):
                assert_that(
                    self.view.list.GetItem(item_ind, col_ind).GetText(),
                    equal_to(self.dataset2[item_ind][col_ind]))
Ejemplo n.º 14
0
    def test_load_partially_processed(self):
        self.create_part_file_with_indices([0, 2])
        super(CandidatesModelPersistenceLoadingTest, self).setUp()

        observer = Mock()
        events.subscribe(events.FINISHED_WORKUNIT, observer)

        workunit = self.model.get_current_workunit()
        assert_that(workunit.get_unprocessed_sources(), has_length(1))

        assert_that(self.model.get_current_source_number(), equal_to(1))
        assert_that(self.model.get_current_obs_number(), equal_to(0))

        self.model.accept_current_item()
        assert_that(observer.call_count, equal_to(1))

        msg = observer.call_args_list[0][0][0]
        assert_that(msg.data, equal_to(workunit.get_results_file_paths()))
Ejemplo n.º 15
0
    def test_load_partially_processed(self):
        self.create_part_file_with_indices([0, 2])
        super(CandidatesModelPersistenceLoadingTest, self).setUp()

        observer = Mock()
        events.subscribe(events.FINISHED_WORKUNIT, observer)

        assert_that(self.model.get_current_workunit().get_unprocessed_sources(),
                    has_length(1))

        assert_that(self.model.get_current_source_number(), equal_to(1))
        assert_that(self.model.get_current_obs_number(), equal_to(0))

        self.model.accept_current_item()
        assert_that(observer.call_count, equal_to(1))

        msg = observer.call_args_list[0][0][0]
        assert_that(msg.data, equal_to("xxx1.cands.astrom"))
Ejemplo n.º 16
0
    def test_next_item(self):
        observer = Mock()
        events.subscribe(events.CHANGE_IMAGE, observer.on_change_img)

        assert_that(self.model.get_current_source_number(), equal_to(0))
        assert_that(self.model.get_current_obs_number(), equal_to(0))

        self.model.next_item()
        assert_that(self.model.get_current_source_number(), equal_to(1))
        assert_that(self.model.get_current_obs_number(), equal_to(0))
        assert_that(observer.on_change_img.call_count, equal_to(1))

        self.model.next_item()
        assert_that(self.model.get_current_source_number(), equal_to(2))
        assert_that(self.model.get_current_obs_number(), equal_to(0))
        assert_that(observer.on_change_img.call_count, equal_to(2))

        self.model.next_item()
        assert_that(self.model.get_current_source_number(), equal_to(0))
        assert_that(self.model.get_current_obs_number(), equal_to(0))
        assert_that(observer.on_change_img.call_count, equal_to(3))
Ejemplo n.º 17
0
    def test_next_item(self):
        observer = Mock()
        events.subscribe(events.CHANGE_IMAGE, observer.on_change_img)

        assert_that(self.model.get_current_source_number(), equal_to(0))
        assert_that(self.model.get_current_obs_number(), equal_to(0))

        self.model.next_item()
        assert_that(self.model.get_current_source_number(), equal_to(1))
        assert_that(self.model.get_current_obs_number(), equal_to(0))
        assert_that(observer.on_change_img.call_count, equal_to(1))

        self.model.next_item()
        assert_that(self.model.get_current_source_number(), equal_to(2))
        assert_that(self.model.get_current_obs_number(), equal_to(0))
        assert_that(observer.on_change_img.call_count, equal_to(2))

        self.model.next_item()
        assert_that(self.model.get_current_source_number(), equal_to(0))
        assert_that(self.model.get_current_obs_number(), equal_to(0))
        assert_that(observer.on_change_img.call_count, equal_to(3))
Ejemplo n.º 18
0
    def test_load_partially_processed(self):
        observer = Mock()
        events.subscribe(events.FINISHED_WORKUNIT, observer)

        assert_that(self.model.get_current_workunit().get_unprocessed_sources(),
                    has_length(1))

        assert_that(self.model.get_current_source_number(), equal_to(2))
        assert_that(self.model.get_current_obs_number(), equal_to(0))
        self.model.reject_current_item()

        self.model.next_item()
        self.model.accept_current_item()

        self.model.next_item()
        self.model.accept_current_item()

        assert_that(observer.call_count, equal_to(1))

        msg = observer.call_args_list[0][0][0]
        assert_that(msg.data, equal_to("xxx3.reals.astrom"))
Ejemplo n.º 19
0
    def test_load_partially_processed(self):
        observer = Mock()
        events.subscribe(events.FINISHED_WORKUNIT, observer)

        assert_that(
            self.model.get_current_workunit().get_unprocessed_sources(),
            has_length(1))

        assert_that(self.model.get_current_source_number(), equal_to(2))
        assert_that(self.model.get_current_obs_number(), equal_to(0))
        self.model.reject_current_item()

        self.model.next_item()
        self.model.accept_current_item()

        self.model.next_item()
        self.model.accept_current_item()

        assert_that(observer.call_count, equal_to(1))

        msg = observer.call_args_list[0][0][0]
        assert_that(msg.data, equal_to("xxx3.reals.astrom"))
Ejemplo n.º 20
0
    def __init__(self, model):
        self.model = model

        events.subscribe(events.CHANGE_IMAGE, self.on_change_image)
        events.subscribe(events.IMG_LOADED, self.on_image_loaded)
        events.subscribe(events.NO_AVAILABLE_WORK, self.on_no_available_work)

        self.view = ApplicationView(self.model, self)
Ejemplo n.º 21
0
    def test_file_processed_event(self):
        observer = Mock()
        events.subscribe(events.FINISHED_WORKUNIT, observer.on_file_processed)

        filename = self.model.get_current_filename()
        accepts_before_next_file = 9

        while accepts_before_next_file > 1:
            self.model.accept_current_item()
            self.model.next_item()
            assert_that(observer.on_file_processed.call_count, equal_to(0))
            accepts_before_next_file -= 1

        self.model.accept_current_item()
        assert_that(observer.on_file_processed.call_count, equal_to(1))

        # Make sure it was triggered with the right data
        args = observer.on_file_processed.call_args[0]
        assert_that(args, has_length(1))

        msg = args[0]
        assert_that(msg.topic, equal_to(events.FINISHED_WORKUNIT))
        assert_that(msg.data, equal_to(filename))
Ejemplo n.º 22
0
    def test_file_processed_event(self):
        observer = Mock()
        events.subscribe(events.FINISHED_WORKUNIT, observer.on_file_processed)

        filename = self.model.get_current_filename()
        accepts_before_next_file = 9

        while accepts_before_next_file > 1:
            self.model.accept_current_item()
            self.model.next_item()
            assert_that(observer.on_file_processed.call_count, equal_to(0))
            accepts_before_next_file -= 1

        self.model.accept_current_item()
        assert_that(observer.on_file_processed.call_count, equal_to(1))

        # Make sure it was triggered with the right data
        args = observer.on_file_processed.call_args[0]
        assert_that(args, has_length(1))

        msg = args[0]
        assert_that(msg.topic, equal_to(events.FINISHED_WORKUNIT))
        assert_that(msg.data, equal_to(filename))
Ejemplo n.º 23
0
    def test_next_item_no_validation(self):
        observer = Mock()
        events.subscribe(events.CHANGE_IMAGE, observer.on_change_img)

        assert_that(self.model.get_current_source_number(), equal_to(0))
        assert_that(self.model.get_current_obs_number(), equal_to(0))

        self.model.next_item()
        assert_that(self.model.get_current_source_number(), equal_to(0))
        assert_that(self.model.get_current_obs_number(), equal_to(1))
        assert_that(observer.on_change_img.call_count, equal_to(1))

        self.model.next_item()
        assert_that(self.model.get_current_source_number(), equal_to(0))
        assert_that(self.model.get_current_obs_number(), equal_to(2))
        assert_that(observer.on_change_img.call_count, equal_to(2))

        self.model.next_item()
        # Should have looped back to first observation of the same source
        # because we haven't finished processing it.
        assert_that(self.model.get_current_source_number(), equal_to(0))
        assert_that(self.model.get_current_obs_number(), equal_to(0))
        assert_that(observer.on_change_img.call_count, equal_to(3))
Ejemplo n.º 24
0
    def test_load_partially_processed(self):
        self.model.set_current_source_name(TEST_OBJECT_NAME)

        observer = Mock()
        events.subscribe(events.FINISHED_WORKUNIT, observer)

        workunit = self.model.get_current_workunit()
        assert_that(workunit.get_unprocessed_sources(), has_length(1))

        assert_that(self.model.get_current_source_number(), equal_to(2))
        assert_that(self.model.get_current_obs_number(), equal_to(0))
        self.model.reject_current_item()

        self.model.next_item()
        self.model.accept_current_item()

        self.model.next_item()
        self.model.accept_current_item()

        assert_that(observer.call_count, equal_to(1))

        msg = observer.call_args_list[0][0][0]
        assert_that(msg.data, equal_to(workunit.get_results_file_paths()))
Ejemplo n.º 25
0
    def test_load_partially_processed(self):
        self.model.set_current_source_name(TEST_OBJECT_NAME)

        observer = Mock()
        events.subscribe(events.FINISHED_WORKUNIT, observer)

        workunit = self.model.get_current_workunit()
        assert_that(workunit.get_unprocessed_sources(), has_length(1))

        assert_that(self.model.get_current_source_number(), equal_to(2))
        assert_that(self.model.get_current_obs_number(), equal_to(0))
        self.model.reject_current_item()

        self.model.next_item()
        self.model.accept_current_item()

        self.model.next_item()
        self.model.accept_current_item()

        assert_that(observer.call_count, equal_to(1))

        msg = observer.call_args_list[0][0][0]
        assert_that(msg.data, equal_to(workunit.get_results_file_paths()))
Ejemplo n.º 26
0
    def test_next_item_no_validation(self):
        observer = Mock()
        events.subscribe(events.CHANGE_IMAGE, observer.on_change_img)

        assert_that(self.model.get_current_source_number(), equal_to(0))
        assert_that(self.model.get_current_obs_number(), equal_to(0))

        self.model.next_item()
        assert_that(self.model.get_current_source_number(), equal_to(0))
        assert_that(self.model.get_current_obs_number(), equal_to(1))
        assert_that(observer.on_change_img.call_count, equal_to(1))

        self.model.next_item()
        assert_that(self.model.get_current_source_number(), equal_to(0))
        assert_that(self.model.get_current_obs_number(), equal_to(2))
        assert_that(observer.on_change_img.call_count, equal_to(2))

        self.model.next_item()
        # Should have looped back to first observation of the same source
        # because we haven't finished processing it.
        assert_that(self.model.get_current_source_number(), equal_to(0))
        assert_that(self.model.get_current_obs_number(), equal_to(0))
        assert_that(observer.on_change_img.call_count, equal_to(3))
Ejemplo n.º 27
0
    def __init__(self, model, view):
        self.model = model
        self.view = view

        events.subscribe(events.CHANGE_IMAGE, self.on_change_image)
        events.subscribe(events.IMG_LOADED, self.on_image_loaded)
        events.subscribe(events.NO_AVAILABLE_WORK, self.on_no_available_work)

        self.autoplay_manager = AutoplayManager(model)
        self.image_loading_dialog_manager = ImageLoadingDialogManager(view)
Ejemplo n.º 28
0
    def __init__(self, model, view):
        self.model = model
        self.view = view

        assert isinstance(self.model, ValidationModel)
        events.subscribe(events.CHANGE_IMAGE, self.on_change_image)
        events.subscribe(events.IMG_LOADED, self.on_image_loaded)
        events.subscribe(events.NO_AVAILABLE_WORK, self.on_no_available_work)

        self.autoplay_manager = AutoplayManager(model)
        self.downloader = Downloader()
        self.image_loading_dialog_manager = ImageLoadingDialogManager(view)