Exemple #1
0
    def test_closing_filedialog_does_nothing(self):
        '''
        Test that closing the FileDialog without choosing a file causes the presenter to return without attempting
        to open/interpret a file.
        '''

        mock_view = mock.create_autospec(FileLoaderViewInterface)

        '''
        Tell the mock FileLoaderView to behave as if the FileDialog was closed without a file being chosen by returning
        an empty "filename"
        '''
        mock_view.get_selected_file_path = mock.MagicMock(side_effect = lambda: ('',''))

        fl_presenter = FileLoaderPresenter(mock_view)
        fl_presenter.register_master(self.mock_main_presenter)

        # Mock the `_load_data` method to check its calls
        fl_presenter._load_data = mock.MagicMock()

        fl_presenter.notify(Command.FILEOPENREQUEST)

        # Check that the `_load_data` and `set_dict` methods were not called due to a file not being selected
        fl_presenter._load_data.assert_not_called()
        self.mock_main_presenter.set_dict.assert_not_called()
Exemple #2
0
    def test_bad_file_shows_message_on_view(self):
        '''
        Test that the request to open a bad file causes the view to display a message.
        '''

        fl_presenter = FileLoaderPresenter(self.mock_view)
        fl_presenter.register_master(self.mock_main_presenter)

        # Mock the `open_dataset` function in the FileLoaderTool so that it returns a bad dataset
        with mock.patch("datasetviewer.fileloader.FileLoaderTool.open_dataset",
                        side_effect=lambda path: self.empty_data):

            fl_presenter.notify(Command.FILEOPENREQUEST)

            '''
            Check that loading a bad dataset caused a message to be displayed on the view indicating that the file
            was rejected.
            '''
            self.mock_view.show_reject_file_message.assert_called_once()

            '''
            Check that the `set_dict` method in the MainViewPresenter was not called as a result of the file being
            rejected.
            '''
            self.mock_main_presenter.set_dict.assert_not_called()
Exemple #3
0
    def test_file_selection_calls_get_path_on_view(self):
        '''
        Test that a FILEOPENREQUEST in the FileLoaderPresenter's `notify` function causes the `get_selected_file_path`
        method on the FileLoaderView to be called.
        '''
        fl_presenter = FileLoaderPresenter(self.mock_view)
        fl_presenter.register_master(self.mock_main_presenter)

        # Mock the `_load_data` method so that no actual file-reading occurs
        fl_presenter._load_data = mock.MagicMock()

        # Notify the FileLoaderPresenter of a FILE
        fl_presenter.notify(Command.FILEOPENREQUEST)
        self.mock_view.get_selected_file_path.assert_called_once()
Exemple #4
0
    def test_file_open_success_informs_main_presenter(self):
        '''
        Test that successfully opening a file in the FileLoaderPresenter causes the resulting DataSet to be sent to the
        MainViewPresenter.
        '''

        fl_presenter = FileLoaderPresenter(self.mock_view)
        fl_presenter.register_master(self.mock_main_presenter)

        # Mock the `file_to_dict` function from the FileLoaderTool and make it return a fake dictionary
        with mock.patch("datasetviewer.fileloader.FileLoaderTool.file_to_dict",
                        side_effect = lambda path: self.empty_dict):

            fl_presenter.notify(Command.FILEOPENREQUEST)

            # Check that the `set_dict` function in the MainViewPresenter was called with the same dictionary
            self.mock_main_presenter.set_dict.assert_called_once_with(self.empty_dict)
Exemple #5
0
    def test_load_file(self):
        '''
        Test that a FILEOPENREQUEST in `notify` causes the `_load_data` method to be called with the expected argument.
        '''
        fl_presenter = FileLoaderPresenter(self.mock_view)
        fl_presenter.register_master(self.mock_main_presenter)

        # Mock the `_load_data` method
        fl_presenter._load_data = mock.MagicMock()

        fl_presenter.notify(Command.FILEOPENREQUEST)

        '''
        Check that the `_load_data` method was called with the first element from the filename-extension tuple that gets
        returned by the FileLoaderView.
        '''
        fl_presenter._load_data.assert_called_once_with(self.fake_file_path[0])